public View2 createView2( FooModel model ) { TransientBuilder<View2> builder = transientBuilderFactory.newTransientBuilder( View2.class ); builder.use( model ); return builder.newInstance(); } }
@Test( expected = ConstraintViolationException.class ) public void testNotEmpty() { TransientBuilder<Sample> cb = transientBuilderFactory.newTransientBuilder( Sample.class ); cb.prototypeFor( Sample.class ).stuff().set( null ); } }
@Test public void testURIOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().uri().set( "http://polygene.apache.org/path?query=string#fragment" ); }
@Test( expected = ConstraintViolationException.class ) public void testGreaterThanFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().greaterThan().set( 10 ); }
@Test( expected = ConstraintViolationException.class ) public void testMatchesFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().matches().set( "cba" ); }
@Test public void testMaxLengthOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().maxLength().set( "xxx" ); }
@Test( expected = ConstraintViolationException.class ) public void testContainsFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().containsString().set( "bar" ); }
@Test public void testEmailOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().email().set( "rickard@gmail.com" ); }
@Test( expected = ConstraintViolationException.class ) public void testMaxLengthFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().maxLength().set( "xxxxx" ); }
private Location createLocation( String locationName ) { TransientBuilder<Location> locationBuilder = transientBuilderFactory.newTransientBuilder( Location.class ); Location locState = locationBuilder.prototypeFor( Location.class ); locState.name().set( locationName ); return locationBuilder.newInstance(); }
public CostPerUnit toCostPer( Unit<?> unit ) { TransientBuilder<CostPerUnitComposite> builder = builderFactory.newTransientBuilder( CostPerUnitComposite.class ); builder.prototype().unit().set( unit ); return builder.newInstance(); } }
@Test( expected = ConstraintViolationException.class ) public void testURLFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().url().set( "this is no url" ); }
@Test public void givenInterfaceWithDefaultMethodAndMixinImplementationWhenCallingExpectMixinValueReturned() { TransientBuilder<Hello> builder = transientBuilderFactory.newTransientBuilder( Hello.class ); Hello prototype = builder.prototype(); Property<String> phrase = prototype.phrase(); phrase.set( "Hello" ); Hello hello = builder.newInstance(); assertThat( hello.speak(), equalTo( "Hello, Mixin!" ) ); assertThat( Hello.noise(), equalTo( "Good Bye" ) ); }
@Test public void givenOptionalPropertyWhenOptionalMissingThenNoException() { TransientBuilder<TestComposite2> builder = transientBuilderFactory.newTransientBuilder( TestComposite2.class ); builder.prototype().mandatoryProperty().set( "Hello World" ); TestComposite2 testComposite2 = builder.newInstance(); }
@Test public void testNotEmptyOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().notEmptyString().set( "X" ); cb.prototype().notEmptyCollection().set( Collections.singletonList( "X" ) ); cb.prototype().notEmptyList().set( Collections.singletonList( "X" ) ); }
@Test public final void testCreationWithStateOfComposite() { TransientBuilder<Location> locationBuilder = transientBuilderFactory.newTransientBuilder( Location.class ); Location locState = locationBuilder.prototype(); locState.name().set( KUALA_LUMPUR ); Location location = locationBuilder.newInstance(); testNamePropertyGet( location, KUALA_LUMPUR ); }
private TestComposite newInstance( String a, int b ) { TransientBuilder<TestComposite> builder = transientBuilderFactory.newTransientBuilder( TestComposite.class ); TestComposite instance = builder.prototype(); instance.a().set( a ); instance.b().set( b ); return builder.newInstance(); }
@Test public void testRangeOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().range().set( 0 ); cb.prototype().range().set( 50 ); cb.prototype().range().set( 100 ); }
@Test public void givenCompositeWithPropertyConstraintsWhenInstantiatedThenPropertiesWork() throws Exception { TransientBuilder<PersonComposite> builder = transientBuilderFactory.newTransientBuilder( PersonComposite.class ); PersonComposite personComposite = builder.prototype(); personComposite.givenName().set( "Rickard" ); personComposite.familyName().set( "Öberg" ); personComposite = builder.newInstance(); personComposite.givenName().set( "Niclas" ); personComposite.familyName().set( "Hedhman" ); }
@Test public void genericPropertiesAndParameters() throws SecurityException, NoSuchMethodException { TransientBuilder<CostPerUnitComposite> builder = transientBuilderFactory.newTransientBuilder( CostPerUnitComposite.class ); builder.prototype().unit().set( new Unit<Integer>( 10 ) ); CostPerUnitComposite test = builder.newInstance(); assertEquals( 10, test.unit().get().value ); assertEquals( 50, test.toCostPer( new Unit<Integer>( 50 ) ).unit().get().value ); }