Package net.emaze.dysfunctional.strings.lexcasts

Source Code of net.emaze.dysfunctional.strings.lexcasts.BooleanTryParserTest

package net.emaze.dysfunctional.strings.lexcasts;

import net.emaze.dysfunctional.dispatching.delegates.Delegate;
import net.emaze.dysfunctional.options.Maybe;
import org.junit.Assert;
import org.junit.Test;

public class BooleanTryParserTest {

    @Test
    public void parsingNullStringYieldsNothing() {
        final Maybe<Boolean> got = new BooleanTryParser().perform(null);
        Assert.assertFalse(got.hasValue());
    }

    @Test
    public void parsingInvalidStringYieldsNothing() {
        final Maybe<Boolean> got = new BooleanTryParser().perform("A");
        Assert.assertFalse(got.hasValue());
    }

    @Test(expected = ClassCastException.class)
    public void passingNonStringToErasureYieldsException() {
        Delegate d = new BooleanTryParser();
        d.perform(new Object());
    }       
   
    @Test
    public void parsingValidTrueStringYieldsTrue() {
        final Maybe<Boolean> got = new BooleanTryParser().perform("true");
        Assert.assertEquals(Maybe.just(true), got);
    }

    @Test
    public void parsingValidFalseStringYieldsFalse() {
        final Maybe<Boolean> got = new BooleanTryParser().perform("false");
        Assert.assertEquals(Maybe.just(false), got);
    }
}
TOP

Related Classes of net.emaze.dysfunctional.strings.lexcasts.BooleanTryParserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.