BooleanValueFactory extends AbstractValueFactory<Boolean> { @Override public Boolean create( String value ) { if (value == null) return null; return Boolean.valueOf(value.trim()); } BooleanValueFactory( TextDecoder decoder,
                                ValueFactories factories ); @Override BooleanValueFactory with( ValueFactories valueFactories ); @Override Boolean create( String value ); @Override Boolean create( String value,
                           TextDecoder decoder ); @Override Boolean create( int value ); @Override Boolean create( long value ); @Override Boolean create( boolean value ); @Override Boolean create( float value ); @Override Boolean create( double value ); @Override Boolean create( BigDecimal value ); @Override Boolean create( Calendar value ); @Override Boolean create( Date value ); @Override Boolean create( DateTime value ); @Override Boolean create( Name value ); @Override Boolean create( Path value ); @Override Boolean create( Path.Segment value ); @Override Boolean create( Reference value ); @Override Boolean create( URI value ); @Override Boolean create( UUID value ); @Override Boolean create( NodeKey value ); @Override Boolean create( byte[] value ); @Override Boolean create( BinaryValue value ); @Override Boolean create( InputStream stream ); @Override Boolean[] createEmptyArray( int length );  }
@Test public void shouldCreateBooleanFromBoolean() { assertThat(factory.create(true), is(true)); assertThat(factory.create(false), is(false)); }
@Test public void shouldCreateBooleanFromTrueAndFalseStringRegardlessOfCase() { assertThat(factory.create("true"), is(true)); assertThat(factory.create("false"), is(false)); assertThat(factory.create("TRUE"), is(true)); assertThat(factory.create("FALSE"), is(false)); }
@Test public void shouldCreateBooleanFromTrueAndFalseStringRegardlessOfLeadingAndTrailingWhitespace() { assertThat(factory.create(" true "), is(true)); assertThat(factory.create(" false "), is(false)); assertThat(factory.create(" TRUE "), is(true)); assertThat(factory.create(" FALSE "), is(false)); }
@Test public void shouldCreateFalseFromStringContainingOneOrZero() { assertThat(factory.create("1"), is(false)); assertThat(factory.create("0"), is(false)); assertThat(factory.create(" 0 "), is(false)); assertThat(factory.create(" 1 "), is(false)); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromIntegerValue() { factory.create(1); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromLongValue() { factory.create(1l); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromFloatValue() { factory.create(1.0f); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromDoubleValue() { factory.create(1.0d); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromBigDecimal() { factory.create(1.0d); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromDate() { factory.create(new Date()); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromCalendar() { factory.create(Calendar.getInstance()); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromName() { factory.create(mock(Name.class)); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromPath() { factory.create(mock(Path.class)); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromReference() { factory.create(mock(Reference.class)); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateBooleanFromUri() throws Exception { factory.create(new URI("http: }
@Test public void shouldCreateBooleanFromByteArrayContainingUtf8EncodingOfTrueOrFalseStringRegardlessOfCase() throws Exception { assertThat(factory.create("true".getBytes("UTF-8")), is(true)); assertThat(factory.create("false".getBytes("UTF-8")), is(false)); assertThat(factory.create("TRUE".getBytes("UTF-8")), is(true)); assertThat(factory.create("FALSE".getBytes("UTF-8")), is(false)); assertThat(factory.create("something else".getBytes("UTF-8")), is(false)); }
@Test public void shouldCreateBooleanFromInputStreamContainingUtf8EncodingOfTrueOrFalseStringRegardlessOfCase() throws Exception { assertThat(factory.create(new ByteArrayInputStream("true".getBytes("UTF-8"))), is(true)); assertThat(factory.create(new ByteArrayInputStream("false".getBytes("UTF-8"))), is(false)); assertThat(factory.create(new ByteArrayInputStream("TRUE".getBytes("UTF-8"))), is(true)); assertThat(factory.create(new ByteArrayInputStream("FALSE".getBytes("UTF-8"))), is(false)); assertThat(factory.create(new ByteArrayInputStream("something else".getBytes("UTF-8"))), is(false)); }
@Test public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() { List<String> values = new ArrayList<String>(); for (int i = 0; i != 10; ++i) values.add((i % 2 == 0 ? "true" : "false")); Iterator<Boolean> iter = factory.create(values.iterator()); Iterator<String> valueIter = values.iterator(); while (iter.hasNext()) { assertThat(iter.next(), is(factory.create(valueIter.next()))); } }