@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( expected = ConstraintViolationException.class ) public void testEmailFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().email().set( "foo.com" ); }
@Test public void testGreaterThanOk() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().greaterThan().set( 11 ); }
@Test( expected = ConstraintViolationException.class ) public void testMinLengthFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().minLength().set( "xx" ); }
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( expected = ConstraintViolationException.class ) public void testURIFail() { TransientBuilder<TestCaseComposite> cb = transientBuilderFactory.newTransientBuilder( TestCaseComposite.class ); cb.prototype().uri().set( "" ); }
@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" ); }
@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 public void givenOptionalPropertyWhenOptionalMissingThenNoException() { TransientBuilder<TestComposite2> builder = transientBuilderFactory.newTransientBuilder( TestComposite2.class ); builder.prototype().mandatoryProperty().set( "Hello World" ); TestComposite2 testComposite2 = builder.newInstance(); }
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 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 ); }