http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java b/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java index f925623..4b61e91 100644 --- a/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java +++ b/core/api/src/test/java/org/apache/polygene/api/value/ValueCompositeTest.java @@ -21,8 +21,6 @@ package org.apache.polygene.api.value; import java.util.List; -import org.junit.Assert; -import org.junit.Test; import org.apache.polygene.api.association.Association; import org.apache.polygene.api.association.ManyAssociation; import org.apache.polygene.api.common.Optional; @@ -38,13 +36,15 @@ import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.library.constraints.annotation.MaxLength; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; -import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for ValueComposites @@ -62,14 +62,16 @@ public class ValueCompositeTest new EntityTestAssembler().assemble( module ); } - @Test( expected = IllegalStateException.class ) + @Test public void testImmutabilityOfValueComposite() { - ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); - SomeValue some = builder.prototype(); - some.other().set( "test" ); - some = builder.newInstance(); - some.other().set( "test2" ); + assertThrows( IllegalStateException.class, () -> { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue some = builder.prototype(); + some.other().set( "test" ); + some = builder.newInstance(); + some.other().set( "test2" ); + } ); } @Test @@ -81,7 +83,7 @@ public class ValueCompositeTest builder.newInstance(); // Check that @UseDefaults works for ValueComposites - assertEquals( "{\"val1\":\"\"}", some.another().get().toString() ); + assertThat( some.another().get().toString(), equalTo( "{\"val1\":\"\"}" ) ); } @Test @@ -92,8 +94,8 @@ public class ValueCompositeTest prototype.other().set( "test" ); SomeValue instance = builder.newInstance(); SomeValue other = builder.newInstance(); - Assert.assertFalse( "Instances should not be the same.", instance == other ); - Assert.assertEquals( "Equal values.", instance, other ); + assertThat( "Instances should not be the same.", instance == other, is( false ) ); + assertThat( "Equal values.", other, equalTo( instance ) ); } @Test @@ -104,8 +106,8 @@ public class ValueCompositeTest prototype.other().set( "test" ); SomeValue instance = builder.newInstance(); SomeValue other = builder.newInstance(); - Assert.assertFalse( "Instances should not be the same.", instance == other ); - Assert.assertEquals( "Equal values.", instance.hashCode(), other.hashCode() ); + assertThat( "Instances should not be the same.", instance == other, is( false ) ); + assertThat( "Equal values.", other.hashCode(), equalTo( instance.hashCode() ) ); } @Test @@ -143,16 +145,18 @@ public class ValueCompositeTest assertThat( "Some is set to bar", instance.some().get(), equalTo( "bar" ) ); } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenValueWhenModifyToIncorrectValueThenThrowConstraintException() { - ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); - SomeValue prototype = builder.prototype(); - prototype.some().set( "foo" ); - SomeValue instance = builder.newInstance(); - - builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); - builder.prototype().some().set( "123456" ); + assertThrows( ConstraintViolationException.class, () -> { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.some().set( "foo" ); + SomeValue instance = builder.newInstance(); + + builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); + builder.prototype().some().set( "123456" ); + } ); } @Test @@ -160,24 +164,15 @@ public class ValueCompositeTest { ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); - SomeValue some = builder.newInstance(); + SomeValue some1 = builder.newInstance(); - builder = valueBuilderFactory.newValueBuilderWithPrototype( some ); + builder = valueBuilderFactory.newValueBuilderWithPrototype( some1 ); builder.prototype().anotherList().get().get( 0 ).val1().set( "Foo" ); builder.prototype().anotherList().get().add( valueBuilderFactory.newValue( AnotherValue.class ) ); - some = builder.newInstance(); + SomeValue some2 = builder.newInstance(); - assertThat( "Val1 has been set", some.anotherList().get().get( 0 ).val1().get(), equalTo( "Foo" ) ); - - try - { - some.anotherList().get().get( 0 ).val1().set( "Bar" ); - Assert.fail( "Should not be allowed to modify value" ); - } - catch( IllegalStateException e ) - { - // Ok - } + assertThat( "Val1 has been set", some2.anotherList().get().get( 0 ).val1().get(), equalTo( "Foo" ) ); + assertThrows( IllegalStateException.class, () -> some2.anotherList().get().get( 0 ).val1().set( "Bar" ) ); } @Test @@ -243,7 +238,7 @@ public class ValueCompositeTest AssociationValue newAssociationValue = valueBuilderFactory.newValueFromSerializedState( AssociationValue.class, json ); - Assert.assertEquals( associationValue.some().get(), newAssociationValue.some().get() ); + assertThat( newAssociationValue.some().get(), equalTo( associationValue.some().get() ) ); } finally {
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/AssemblySpecificationTest.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/AssemblySpecificationTest.java b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/AssemblySpecificationTest.java index a107af2..d26bcee 100644 --- a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/AssemblySpecificationTest.java +++ b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/AssemblySpecificationTest.java @@ -25,10 +25,10 @@ import java.util.Arrays; import java.util.function.Predicate; import java.util.stream.Stream; import org.apache.polygene.api.type.HasTypes; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class AssemblySpecificationTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java index 49697ca..7f191eb 100644 --- a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java +++ b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java @@ -21,11 +21,12 @@ package org.apache.polygene.bootstrap; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.bootstrap.somepackage.Test2Value; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.polygene.bootstrap.ClassScanner.findClasses; import static org.apache.polygene.bootstrap.ClassScanner.matches; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; /** * Test and showcase of the ClassScanner assembly utility. @@ -40,7 +41,7 @@ public class ClassScannerTest module -> { // Find all classes starting from TestValue, but include only the ones that are named *Value findClasses( TestValue.class ).filter( matches( ".*Value" ) ) - .forEach( module::values ); + .forEach( module::values ); } ); @@ -51,6 +52,6 @@ public class ClassScannerTest @Test public void testClassScannerJar() { - Assert.assertEquals( 185, findClasses( Test.class ).count() ); + assertThat( findClasses( Test.class ).count(), equalTo( 185 ) ); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/assembly/LayeredApplicationAssemblerTest.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/assembly/LayeredApplicationAssemblerTest.java b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/assembly/LayeredApplicationAssemblerTest.java index 484d3e2..720bf13 100644 --- a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/assembly/LayeredApplicationAssemblerTest.java +++ b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/assembly/LayeredApplicationAssemblerTest.java @@ -19,13 +19,13 @@ */ package org.apache.polygene.bootstrap.assembly; -import org.junit.Test; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.api.structure.Application; import org.apache.polygene.bootstrap.AssemblyException; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class LayeredApplicationAssemblerTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/builder/ApplicationBuilderTest.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/builder/ApplicationBuilderTest.java b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/builder/ApplicationBuilderTest.java index c7c1e6c..7ff383c 100644 --- a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/builder/ApplicationBuilderTest.java +++ b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/builder/ApplicationBuilderTest.java @@ -29,13 +29,13 @@ import org.apache.polygene.api.structure.Module; import org.apache.polygene.bootstrap.Assembler; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.stream.Collectors.toList; import static org.apache.polygene.bootstrap.ClassScanner.findClasses; import static org.apache.polygene.bootstrap.ClassScanner.matches; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class ApplicationBuilderTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java index 6a43690..be120db 100644 --- a/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java @@ -20,8 +20,6 @@ package org.apache.polygene.api.common; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.association.Association; import org.apache.polygene.api.composite.TransientBuilder; import org.apache.polygene.api.composite.TransientComposite; @@ -33,10 +31,13 @@ import org.apache.polygene.api.property.Property; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests for @Optional @@ -60,11 +61,13 @@ public class OptionalTest instance.doStuff( "Hello WOrld", "Hello World" ); } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenOptionalMethodWhenMandatoryMissingThenException() { - TestComposite instance = transientBuilderFactory.newTransient( TestComposite.class ); - instance.doStuff( "Hello World", null ); + assertThrows( ConstraintViolationException.class, () -> { + TestComposite instance = transientBuilderFactory.newTransient( TestComposite.class ); + instance.doStuff( "Hello World", null ); + } ); } @Test @@ -91,10 +94,10 @@ public class OptionalTest TestComposite2 testComposite2 = builder.newInstance(); } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenMandatoryPropertyWhenMandatoryMissingThenException() { - TestComposite2 testComposite2 = transientBuilderFactory.newTransient( TestComposite2.class ); + assertThrows( ConstraintViolationException.class, () -> transientBuilderFactory.newTransient( TestComposite2.class ) ); } @Test @@ -140,25 +143,27 @@ public class OptionalTest } } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenMandatoryAssociationWhenMandatoryMissingThenException() throws Exception { - UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); - try - { - TestComposite4 ref = unitOfWork.newEntity( TestComposite4.class ); + assertThrows( ConstraintViolationException.class, () -> { + UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); + try + { + TestComposite4 ref = unitOfWork.newEntity( TestComposite4.class ); - EntityBuilder<TestComposite3> builder = unitOfWork.newEntityBuilder( TestComposite3.class ); - builder.instance().optionalAssociation().set( ref ); - TestComposite3 testComposite3 = builder.newInstance(); + EntityBuilder<TestComposite3> builder = unitOfWork.newEntityBuilder( TestComposite3.class ); + builder.instance().optionalAssociation().set( ref ); + TestComposite3 testComposite3 = builder.newInstance(); - unitOfWork.complete(); - } - finally - { - unitOfWork.discard(); - } + unitOfWork.complete(); + } + finally + { + unitOfWork.discard(); + } + } ); } @Mixins( TestComposite.TestMixin.class ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyErrorTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyErrorTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyErrorTest.java index 97aba67..3ccf070 100644 --- a/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyErrorTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyErrorTest.java @@ -20,15 +20,17 @@ package org.apache.polygene.api.common; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.constraint.ConstraintViolationException; import org.apache.polygene.api.entity.EntityComposite; import org.apache.polygene.api.property.Property; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Error messages for Properties @@ -43,21 +45,23 @@ public class PropertyErrorTest module.entities( PersonEntity.class ); } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenEntityWithNonOptionPropertyWhenInstantiatedThenException() throws Exception { - UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); - try - { - PersonEntity person = unitOfWork.newEntity( PersonEntity.class ); + assertThrows( ConstraintViolationException.class, () -> { + UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork(); + try + { + PersonEntity person = unitOfWork.newEntity( PersonEntity.class ); - unitOfWork.complete(); - } - finally - { - unitOfWork.discard(); - } + unitOfWork.complete(); + } + finally + { + unitOfWork.discard(); + } + } ); } interface PersonEntity http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyTypeTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyTypeTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyTypeTest.java index 79349ae..791563b 100644 --- a/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyTypeTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/api/common/PropertyTypeTest.java @@ -22,9 +22,6 @@ package org.apache.polygene.api.common; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.apache.polygene.api.injection.scope.Invocation; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.composite.TransientBuilder; import org.apache.polygene.api.composite.TransientComposite; import org.apache.polygene.api.constraint.Constraint; @@ -36,7 +33,9 @@ import org.apache.polygene.api.property.Property; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; /** * Test for ability to set constraints on Properties http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/api/common/RemovalTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/RemovalTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/RemovalTest.java index b58c6c9..3b9adc1 100644 --- a/core/runtime/src/test/java/org/apache/polygene/api/common/RemovalTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/api/common/RemovalTest.java @@ -30,7 +30,7 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RemovalTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/api/common/ValueCompositeTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/ValueCompositeTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/ValueCompositeTest.java index 0a6d1d3..cf01570 100644 --- a/core/runtime/src/test/java/org/apache/polygene/api/common/ValueCompositeTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/api/common/ValueCompositeTest.java @@ -21,9 +21,6 @@ package org.apache.polygene.api.common; import java.util.List; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Assert; -import org.junit.Test; import org.apache.polygene.api.constraint.ConstraintViolationException; import org.apache.polygene.api.entity.EntityBuilder; import org.apache.polygene.api.entity.EntityComposite; @@ -34,10 +31,15 @@ import org.apache.polygene.api.value.ValueBuilder; import org.apache.polygene.api.value.ValueComposite; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for ValueComposites @@ -54,14 +56,16 @@ public class ValueCompositeTest new EntityTestAssembler().assemble( module ); } - @Test( expected = IllegalStateException.class ) + @Test public void testImmutabilityOfValueComposite() { - ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); - SomeValue some = builder.prototype(); - some.other().set( "test" ); - some = builder.newInstance(); - some.other().set( "test2" ); + assertThrows( IllegalStateException.class, () -> { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue some = builder.prototype(); + some.other().set( "test" ); + some = builder.newInstance(); + some.other().set( "test2" ); + } ); } @Test @@ -85,8 +89,8 @@ public class ValueCompositeTest prototype = builder.prototype(); prototype.other().set( "test" ); SomeValue other = builder.newInstance(); - Assert.assertFalse( "Instances should not be the same.", instance == other ); - Assert.assertEquals( "Equal values.", instance, other ); + assertThat( "Instances should not be the same.", instance == other, is( false ) ); + assertThat( "Equal values.", other, equalTo( instance ) ); } @Test @@ -101,8 +105,8 @@ public class ValueCompositeTest prototype = builder.prototype(); prototype.other().set( "test" ); SomeValue other = builder.newInstance(); - Assert.assertFalse( "Instances should not be the same.", instance == other ); - Assert.assertEquals( "Equal values.", instance.hashCode(), other.hashCode() ); + assertThat( "Instances should not be the same.", instance == other, is( false ) ); + assertThat( "Equal values.", other.hashCode(), equalTo( instance.hashCode() ) ); } @Test @@ -140,16 +144,18 @@ public class ValueCompositeTest assertThat( "Some is set to bar", instance.some().get(), equalTo( "bar" ) ); } - @Test( expected = ConstraintViolationException.class ) + @Test public void givenValueWhenModifyToIncorrectValueThenThrowConstraintException() { - ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); - SomeValue prototype = builder.prototype(); - prototype.some().set( "foo" ); - SomeValue instance = builder.newInstance(); - - builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); - builder.prototype().some().set( null ); + assertThrows( ConstraintViolationException.class, () -> { + ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class ); + SomeValue prototype = builder.prototype(); + prototype.some().set( "foo" ); + SomeValue instance = builder.newInstance(); + + builder = valueBuilderFactory.newValueBuilderWithPrototype( instance ); + builder.prototype().some().set( null ); + } ); } @Test @@ -169,7 +175,7 @@ public class ValueCompositeTest try { some.anotherList().get().get( 0 ).val1().set( "Bar" ); - Assert.fail( "Should not be allowed to modify value" ); + fail( "Should not be allowed to modify value" ); } catch( IllegalStateException e ) { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/bootstrap/ApplicationAssemblerTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ApplicationAssemblerTest.java b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ApplicationAssemblerTest.java index 4646efa..e96bf2d 100644 --- a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ApplicationAssemblerTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ApplicationAssemblerTest.java @@ -29,8 +29,11 @@ import org.apache.polygene.api.service.ServiceDescriptor; import org.apache.polygene.api.structure.ApplicationDescriptor; import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; import org.apache.polygene.api.util.HierarchicalVisitorAdapter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; /** * TODO @@ -78,14 +81,14 @@ public class ApplicationAssemblerTest { return false; } - Assert.assertTrue( serviceDescriptor.isInstantiateOnStartup() ); - Assert.assertTrue( serviceDescriptor.visibility() == Visibility.layer ); + assertThat( serviceDescriptor.isInstantiateOnStartup(), is( true ) ); + assertThat( serviceDescriptor.visibility(), equalTo( Visibility.layer ) ); return false; } else if( visited instanceof EntityDescriptor ) { EntityDescriptor entityDescriptor = (EntityDescriptor) visited; - Assert.assertTrue( entityDescriptor.visibility() == Visibility.application ); + assertThat( entityDescriptor.visibility(), equalTo( Visibility.application ) ); return false; } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/bootstrap/ErrorReportingTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ErrorReportingTest.java b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ErrorReportingTest.java index 0ddb5e6..c9152af 100644 --- a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ErrorReportingTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ErrorReportingTest.java @@ -24,10 +24,10 @@ import org.apache.polygene.api.association.Association; import org.apache.polygene.api.association.ManyAssociation; import org.apache.polygene.api.property.Property; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; public class ErrorReportingTest extends AbstractPolygeneTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java b/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java index 1283272..3a0e58f 100644 --- a/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/bootstrap/RuntimeMixinsTest.java @@ -22,11 +22,11 @@ package org.apache.polygene.bootstrap; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.mixin.NoopMixin; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; public class RuntimeMixinsTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/bootstrap/ServiceAssemblyTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ServiceAssemblyTest.java b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ServiceAssemblyTest.java index 2f0492f..2da3a09 100644 --- a/core/runtime/src/test/java/org/apache/polygene/bootstrap/ServiceAssemblyTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/bootstrap/ServiceAssemblyTest.java @@ -24,10 +24,10 @@ import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.service.ServiceActivation; import org.apache.polygene.api.service.ServiceReference; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class ServiceAssemblyTest extends AbstractPolygeneTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/constraints/PropertyConstraintTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/constraints/PropertyConstraintTest.java b/core/runtime/src/test/java/org/apache/polygene/constraints/PropertyConstraintTest.java index 51b9e93..5efd213 100644 --- a/core/runtime/src/test/java/org/apache/polygene/constraints/PropertyConstraintTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/constraints/PropertyConstraintTest.java @@ -22,9 +22,9 @@ package org.apache.polygene.constraints; import java.util.Collection; import org.apache.polygene.api.composite.TransientBuilder; import org.apache.polygene.api.composite.TransientComposite; -import org.apache.polygene.api.constraint.ValueConstraintViolation; import org.apache.polygene.api.constraint.ConstraintViolationException; import org.apache.polygene.api.constraint.Constraints; +import org.apache.polygene.api.constraint.ValueConstraintViolation; import org.apache.polygene.api.property.Property; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; @@ -32,20 +32,22 @@ import org.apache.polygene.library.constraints.MinLengthConstraint; import org.apache.polygene.library.constraints.annotation.Matches; import org.apache.polygene.library.constraints.annotation.MinLength; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.jupiter.api.Assertions.fail; public class PropertyConstraintTest extends AbstractPolygeneTest { - @org.junit.Test + @Test public void givenConstraintOnPropertyWhenInvalidValueThenThrowException() throws Throwable { - TransientBuilder<Test> builder = transientBuilderFactory.newTransientBuilder( Test.class ); + TransientBuilder<TestType> builder = transientBuilderFactory.newTransientBuilder( TestType.class ); builder.prototype().test().set( "XXXXXX" ); - Test test = builder.newInstance(); + TestType test = builder.newInstance(); try { test.test().set( "YY" ); @@ -54,7 +56,7 @@ public class PropertyConstraintTest catch( ConstraintViolationException e ) { Collection<ValueConstraintViolation> violations = e.constraintViolations(); - assertEquals( 2, violations.size() ); + assertThat( violations.size(), equalTo( 2 ) ); } } @@ -66,11 +68,11 @@ public class PropertyConstraintTest @Constraints( { MinLengthConstraint.class } ) public interface TestComposite - extends Test, TransientComposite + extends TestType, TransientComposite { } - public interface Test + public interface TestType { @MinLength( 3 ) @Matches( "X*" ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java b/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java index 0d1c8ee..f584147 100644 --- a/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java @@ -25,14 +25,18 @@ import org.apache.polygene.api.value.ValueBuilder; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; public class ValueConstraintTest extends AbstractPolygeneTest { - @Test(expected = ConstraintViolationException.class) + @Test public void testProhibitNewInstanceWithViolation() { - ValueBuilder<Value1> builder = valueBuilderFactory.newValueBuilder(Value1.class); - builder.newInstance(); + assertThrows( ConstraintViolationException.class, () -> { + ValueBuilder<Value1> builder = valueBuilderFactory.newValueBuilder( Value1.class ); + builder.newInstance(); + } ); } public void assemble(ModuleAssembly module) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi230/Qi230IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi230/Qi230IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi230/Qi230IssueTest.java index 271147f..ff0a877 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi230/Qi230IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi230/Qi230IssueTest.java @@ -20,8 +20,6 @@ package org.apache.polygene.regression.qi230; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.PolygeneAPI; import org.apache.polygene.api.composite.Composite; import org.apache.polygene.api.concern.ConcernOf; @@ -34,8 +32,11 @@ import org.apache.polygene.api.mixin.NoopMixin; import org.apache.polygene.api.service.ServiceComposite; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; /** * JAVADOC @@ -57,9 +58,9 @@ public class Qi230IssueTest { Result result = serviceFinder.findService( Result.class ).get(); Some some = serviceFinder.findService( Some.class ).get(); - assertEquals( "method()", some.method() ); - assertEquals( some.identity(), result.some().identity() ); - assertEquals( some.identity().get(), result.some().identity().get() ); + assertThat( some.method(), equalTo( "method()" ) ); + assertThat( result.some().identity(), equalTo( some.identity() ) ); + assertThat( result.some().identity().get(), equalTo( some.identity().get() ) ); } @Mixins( ResultMixin.class ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java index f766590..e0b5a79 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java @@ -19,23 +19,23 @@ */ package org.apache.polygene.regression.qi377; -import org.apache.polygene.api.identity.HasIdentity; -import org.apache.polygene.api.identity.Identity; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.association.Association; import org.apache.polygene.api.association.ManyAssociation; import org.apache.polygene.api.common.Optional; +import org.apache.polygene.api.identity.HasIdentity; +import org.apache.polygene.api.identity.Identity; import org.apache.polygene.api.property.Property; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.api.unitofwork.UnitOfWorkCompletionException; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; public class InterfaceCollisionWithRelatedReturnTypesTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi377/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/IssueTest.java index 31a57b5..2702f06 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/IssueTest.java @@ -19,15 +19,15 @@ */ package org.apache.polygene.regression.qi377; -import org.junit.Test; import org.apache.polygene.api.common.UseDefaults; import org.apache.polygene.api.property.Property; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; public class IssueTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi377/SetAssociationInSideEffectTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/SetAssociationInSideEffectTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/SetAssociationInSideEffectTest.java index 1a73631..ad18f42 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/SetAssociationInSideEffectTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/SetAssociationInSideEffectTest.java @@ -37,12 +37,12 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.nullValue; import static org.hamcrest.core.IsSame.theInstance; -import static org.junit.Assert.assertThat; public class SetAssociationInSideEffectTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi377/ValueCollisionWithRelatedReturnTypesTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/ValueCollisionWithRelatedReturnTypesTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/ValueCollisionWithRelatedReturnTypesTest.java index 6b6bb0a..91cb688 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi377/ValueCollisionWithRelatedReturnTypesTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi377/ValueCollisionWithRelatedReturnTypesTest.java @@ -30,7 +30,7 @@ import org.apache.polygene.api.value.ValueBuilder; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ValueCollisionWithRelatedReturnTypesTest extends AbstractPolygeneTest http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi382/Qi382Test.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi382/Qi382Test.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi382/Qi382Test.java index d645308..a50b474 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi382/Qi382Test.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi382/Qi382Test.java @@ -35,11 +35,11 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; public class Qi382Test extends AbstractPolygeneTest { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi383/Qi383Test.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi383/Qi383Test.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi383/Qi383Test.java index efa6bc0..4188bca 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi383/Qi383Test.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi383/Qi383Test.java @@ -28,7 +28,9 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; public class Qi383Test extends AbstractPolygeneTest { @@ -41,17 +43,19 @@ public class Qi383Test extends AbstractPolygeneTest new EntityTestAssembler().assemble( module ); } - @Test( expected = EntityCompositeAlreadyExistsException.class ) + @Test public void givenUnitOfWorkInProgressWhenAddingSameEntityTwiceExpectException() throws UnitOfWorkCompletionException { - try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() ) - { - unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ferrari" ) ); - unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ford" ) ); - unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ferrari" ) ); - unitOfWork.complete(); - } + assertThrows( EntityCompositeAlreadyExistsException.class, () -> { + try (UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork()) + { + unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ferrari" ) ); + unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ford" ) ); + unitOfWork.newEntity( Car.class, StringIdentity.identityOf( "Ferrari" ) ); + unitOfWork.complete(); + } + } ); } public interface Car extends EntityComposite http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi53/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi53/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi53/IssueTest.java index bea4d6f..dc4e307 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi53/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi53/IssueTest.java @@ -19,7 +19,6 @@ */ package org.apache.polygene.regression.qi53; -import org.junit.Test; import org.apache.polygene.api.composite.TransientBuilder; import org.apache.polygene.api.composite.TransientBuilderFactory; import org.apache.polygene.api.composite.TransientComposite; @@ -31,8 +30,10 @@ import org.apache.polygene.api.property.Property; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class IssueTest extends AbstractPolygeneTest @@ -48,10 +49,10 @@ public class IssueTest throws SecurityException, NoSuchMethodException { TransientBuilder<CostPerUnitComposite> builder = transientBuilderFactory.newTransientBuilder( CostPerUnitComposite.class ); - builder.prototype().unit().set( new Unit<Integer>( 10 ) ); + builder.prototype().unit().set( new Unit<>( 10 ) ); CostPerUnitComposite test = builder.newInstance(); - assertEquals( 10, test.unit().get().value ); - assertEquals( 50, test.toCostPer( new Unit<Integer>( 50 ) ).unit().get().value ); + assertThat( test.unit().get().value, equalTo( 10 ) ); + assertThat( test.toCostPer( new Unit<>( 50 ) ).unit().get().value, equalTo( 50 ) ); } public interface CostPerUnit http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi55/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi55/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi55/IssueTest.java index f907013..0ba0a67 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi55/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi55/IssueTest.java @@ -19,13 +19,14 @@ */ package org.apache.polygene.regression.qi55; -import org.junit.Test; import org.apache.polygene.api.injection.scope.Uses; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class IssueTest extends AbstractPolygeneTest @@ -39,7 +40,7 @@ public class IssueTest @Test public void objectWithGenericUsage() { - assertEquals( "Using - Test string", objectFactory.newObject( AClass.class, "Test string" ).uses() ); + assertThat( objectFactory.newObject( AClass.class, "Test string" ).uses(), equalTo( "Using - Test string" ) ); } public static class AClass<T> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi59/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi59/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi59/IssueTest.java index 37f0dff..d92af75 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi59/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi59/IssueTest.java @@ -20,17 +20,17 @@ package org.apache.polygene.regression.qi59; -import org.apache.polygene.test.AbstractPolygeneTest; -import org.junit.Test; import org.apache.polygene.api.entity.EntityComposite; import org.apache.polygene.api.property.Property; import org.apache.polygene.api.unitofwork.UnitOfWork; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.library.constraints.annotation.NotEmpty; +import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Test for QI-59 http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi65/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi65/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi65/IssueTest.java index f4a3a97..81a756d 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi65/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi65/IssueTest.java @@ -19,12 +19,14 @@ */ package org.apache.polygene.regression.qi65; -import org.junit.Test; import org.apache.polygene.api.composite.TransientComposite; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; public class IssueTest extends AbstractPolygeneTest @@ -39,13 +41,15 @@ public class IssueTest module.transients( TestComposite.class ); } - @Test( expected = IllegalArgumentException.class ) + @Test public void constraintOnMethodParameter() throws SecurityException, NoSuchMethodException { - TestComposite test = transientBuilderFactory.newTransient( TestComposite.class ); + assertThrows( IllegalArgumentException.class, () -> { + TestComposite test = transientBuilderFactory.newTransient( TestComposite.class ); - test.someMethod( null ); + test.someMethod( null ); + } ); } @Mixins( TestMixin.class ) http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi74/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi74/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi74/IssueTest.java index e265cf8..22d5c00 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi74/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi74/IssueTest.java @@ -19,8 +19,6 @@ */ package org.apache.polygene.regression.qi74; -import org.junit.Assert; -import org.junit.Test; import org.apache.polygene.api.composite.TransientBuilder; import org.apache.polygene.api.composite.TransientComposite; import org.apache.polygene.api.constraint.ConstraintViolationException; @@ -28,6 +26,9 @@ import org.apache.polygene.api.property.Property; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; public class IssueTest extends AbstractPolygeneTest @@ -45,7 +46,7 @@ public class IssueTest { TransientBuilder<ValueHolder> builder = transientBuilderFactory.newTransientBuilder( ValueHolder.class ); builder.newInstance(); - Assert.fail( "NotNull constraint violated but no exception is raised" ); + fail( "NotNull constraint violated but no exception is raised" ); } catch( ConstraintViolationException e ) { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi78/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi78/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi78/IssueTest.java index 04dade8..f25e555 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi78/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi78/IssueTest.java @@ -27,8 +27,10 @@ import org.apache.polygene.bootstrap.ApplicationAssembly; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.Energy4Java; import org.apache.polygene.bootstrap.LayerAssembly; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNull.notNullValue; public class IssueTest { @@ -75,7 +77,7 @@ public class IssueTest if( visited instanceof LayerDescriptor ) { ( (LayerDescriptor) visited ).usedLayers().layers().forEach( usedLayerModel -> { - Assert.assertNotNull( "Used layer model is null", usedLayerModel ); + assertThat( "Used layer model is null", usedLayerModel, notNullValue() ); } ); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/regression/qi94/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/regression/qi94/IssueTest.java b/core/runtime/src/test/java/org/apache/polygene/regression/qi94/IssueTest.java index 6a60093..757be13 100644 --- a/core/runtime/src/test/java/org/apache/polygene/regression/qi94/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/regression/qi94/IssueTest.java @@ -19,7 +19,6 @@ */ package org.apache.polygene.regression.qi94; -import org.junit.Test; import org.apache.polygene.api.association.Association; import org.apache.polygene.api.entity.EntityBuilder; import org.apache.polygene.api.entity.EntityComposite; @@ -29,8 +28,10 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class IssueTest extends AbstractPolygeneTest @@ -50,11 +51,13 @@ public class IssueTest try { EntityBuilder<Item> builder = uow.newEntityBuilder( Item.class ); - assertEquals( ItemType.class, polygene.api() - .entityDescriptorFor( builder.instance() ) - .state() - .getAssociationByName( "typeOfItem" ) - .type() ); + assertThat( polygene.api() + .entityDescriptorFor( builder.instance() ) + .state() + .getAssociationByName( "typeOfItem" ) + .type(), + equalTo( ItemType.class ) + ); } finally { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneAPITest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneAPITest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneAPITest.java index 24419d6..adecae4 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneAPITest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneAPITest.java @@ -20,7 +20,6 @@ package org.apache.polygene.runtime; -import org.junit.Test; import org.apache.polygene.api.composite.TransientComposite; import org.apache.polygene.api.entity.EntityComposite; import org.apache.polygene.api.service.ServiceComposite; @@ -30,6 +29,7 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.junit.jupiter.api.Test; /** * JAVADOC http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneSPITest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneSPITest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneSPITest.java index 7c60d87..0829dfd 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneSPITest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/PolygeneSPITest.java @@ -20,8 +20,6 @@ package org.apache.polygene.runtime; -import org.hamcrest.CoreMatchers; -import org.junit.Test; import org.apache.polygene.api.association.AbstractAssociation; import org.apache.polygene.api.association.Association; import org.apache.polygene.api.association.AssociationStateDescriptor; @@ -37,8 +35,10 @@ import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; import org.apache.polygene.test.AbstractPolygeneTest; import org.apache.polygene.test.EntityTestAssembler; +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * JAVADOC http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ApplicationActivationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ApplicationActivationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ApplicationActivationTest.java index d8fb864..3001830 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ApplicationActivationTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ApplicationActivationTest.java @@ -22,8 +22,10 @@ package org.apache.polygene.runtime.activation; import org.apache.polygene.api.activation.Activator; import org.apache.polygene.api.structure.Application; import org.apache.polygene.bootstrap.SingletonAssembler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class ApplicationActivationTest { @@ -33,7 +35,7 @@ public class ApplicationActivationTest private static int passivationLevel = 0; public static class TestedActivator - implements Activator<Application> + implements Activator<Application> { public void beforeActivation( Application activating ) @@ -55,12 +57,11 @@ public class ApplicationActivationTest { passivationLevel++; } - } @Test public void testApplicationActivator() - throws Exception + throws Exception { SingletonAssembler assembly = new SingletonAssembler( module -> module.layer().application().withActivators( TestedActivator.class ) @@ -70,13 +71,12 @@ public class ApplicationActivationTest Application application = assembly.application(); // Assert activated - Assert.assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); // Passivate application.passivate(); // Assert passivated - Assert.assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } - } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ImportedServiceActivationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ImportedServiceActivationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ImportedServiceActivationTest.java index c13d019..1f69127 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ImportedServiceActivationTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ImportedServiceActivationTest.java @@ -30,13 +30,13 @@ import org.apache.polygene.api.service.ServiceReference; import org.apache.polygene.api.structure.Application; import org.apache.polygene.bootstrap.ImportedServiceDeclaration; import org.apache.polygene.bootstrap.SingletonAssembler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.jupiter.api.Assertions.fail; public class ImportedServiceActivationTest { @@ -46,76 +46,79 @@ public class ImportedServiceActivationTest private static int passivationLevel = 0; public static class TestedActivator - implements Activator<ServiceReference<TestedService>> + implements Activator<ServiceReference<TestedService>> { public void beforeActivation( ServiceReference<TestedService> activating ) { - assertFalse( "Service should not be active before activation", activating.isActive() ); - try { + assertThat( "Service should not be active before activation", activating.isActive(), is( false ) ); + try + { activating.get(); fail( "Service is not activated yet, the reference get method should throw IllegalStateException." ); - } catch ( IllegalStateException expected ) { + } + catch( IllegalStateException expected ) + { } activationLevel++; } public void afterActivation( ServiceReference<TestedService> activated ) { - assertTrue( "Service should be active after activation", activated.isActive() ); - assertEquals( "After activation", "bar", activated.get().foo() ); + assertThat( "Service should be active after activation", activated.isActive(), is( true ) ); + assertThat( "After activation", activated.get().foo(), equalTo( "bar" ) ); activationLevel++; } public void beforePassivation( ServiceReference<TestedService> passivating ) { - assertTrue( "Service should be active before passivation", passivating.isActive() ); - assertEquals( "Before passivation", "bar", passivating.get().foo() ); + assertThat( "Service should be active before passivation", passivating.isActive(), is( true ) ); + assertThat( "Before passivation", passivating.get().foo(), equalTo( "bar" ) ); passivationLevel++; } public void afterPassivation( ServiceReference<TestedService> passivated ) { - assertFalse( "Service should not be active after passivation", passivated.isActive() ); - try { + assertThat( "Service should not be active after passivation", passivated.isActive(), is( false ) ); + try + { passivated.get(); fail( "Service is passivated, the reference get method should throw IllegalStateException." ); - } catch ( IllegalStateException expected ) { + } + catch( IllegalStateException expected ) + { } passivationLevel++; } - } public interface TestedService { String foo(); - } public static class TestedServiceInstance - implements TestedService + implements TestedService { public String foo() { return "bar"; } - } @Mixins( TestedServiceImporterService.Mixin.class ) interface TestedServiceImporterService - extends ServiceComposite, ServiceImporter<TestedService> + extends ServiceComposite, ServiceImporter<TestedService> { class Mixin - implements ServiceImporter<TestedService> + implements ServiceImporter<TestedService> { public TestedService importService( ImportedServiceDescriptor serviceDescriptor ) - throws ServiceImporterException + throws ServiceImporterException { return new TestedServiceInstance(); } @@ -124,12 +127,10 @@ public class ImportedServiceActivationTest { return true; } - } - } - @Before + @BeforeEach public void beforeEachTest() { activationLevel = 0; @@ -138,57 +139,56 @@ public class ImportedServiceActivationTest @Test public void testNewInstanceImportedServiceActivators() - throws Exception + throws Exception { SingletonAssembler assembler = new SingletonAssembler( module -> module.importedServices( TestedService.class ) - .withActivators( TestedActivator.class ) - .setMetaInfo( new TestedServiceInstance() ) - .importOnStartup() + .withActivators( TestedActivator.class ) + .setMetaInfo( new TestedServiceInstance() ) + .importOnStartup() ); Application application = assembler.application(); - assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); application.passivate(); - assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } @Test public void testNewObjectImportedServiceActivators() - throws Exception + throws Exception { SingletonAssembler assembler = new SingletonAssembler( module -> { module.importedServices( TestedService.class ). importedBy( ImportedServiceDeclaration.NEW_OBJECT ). - withActivators( TestedActivator.class ). - importOnStartup(); + withActivators( TestedActivator.class ). + importOnStartup(); module.objects( TestedServiceInstance.class ); } ); Application application = assembler.application(); - assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); application.passivate(); - assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } @Test public void testServiceImporterImportedServiceActivators() - throws Exception + throws Exception { SingletonAssembler assembler = new SingletonAssembler( module -> { module.importedServices( TestedService.class ). importedBy( ImportedServiceDeclaration.SERVICE_IMPORTER ). - setMetaInfo( StringIdentity.identityOf( "testimporter" ) ). - withActivators( TestedActivator.class ). - importOnStartup(); + setMetaInfo( StringIdentity.identityOf( "testimporter" ) ). + withActivators( TestedActivator.class ). + importOnStartup(); module.services( TestedServiceImporterService.class ).identifiedBy( "testimporter" ); } ); Application application = assembler.application(); - assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); application.passivate(); - assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/IntraMixinActivationOrderTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/IntraMixinActivationOrderTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/IntraMixinActivationOrderTest.java index 2d6eb39..0fddd4e 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/IntraMixinActivationOrderTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/IntraMixinActivationOrderTest.java @@ -20,8 +20,6 @@ package org.apache.polygene.runtime.activation; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.api.activation.ActivatorAdapter; import org.apache.polygene.api.activation.Activators; @@ -35,8 +33,11 @@ import org.apache.polygene.bootstrap.SingletonAssembler; import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.ActivationStep; import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.ActivationStepsRecorder; import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.ActivationStepsRecorderInstance; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; /** * Assert that intra-mixin activation order is correct. @@ -47,7 +48,7 @@ public class IntraMixinActivationOrderTest public static final ActivationStepsRecorder RECORDER = new ActivationStepsRecorderInstance(); - @Before + @BeforeEach public void beforeEachTest() { RECORDER.reset(); @@ -207,7 +208,7 @@ public class IntraMixinActivationOrderTest "beta.tear-down", } ); String actual = Arrays.toString( RECORDER.steps().toArray() ); - assertEquals( expected, actual ); + assertThat( actual, equalTo( expected ) ); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/LayerActivationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/LayerActivationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/LayerActivationTest.java index f6d5e7c..6732405 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/LayerActivationTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/LayerActivationTest.java @@ -23,8 +23,10 @@ import org.apache.polygene.api.activation.Activator; import org.apache.polygene.api.structure.Application; import org.apache.polygene.api.structure.Layer; import org.apache.polygene.bootstrap.SingletonAssembler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class LayerActivationTest { @@ -34,7 +36,7 @@ public class LayerActivationTest private static int passivationLevel = 0; public static class TestedActivator - implements Activator<Layer> + implements Activator<Layer> { public void beforeActivation( Layer activating ) @@ -56,12 +58,11 @@ public class LayerActivationTest { passivationLevel++; } - } @Test public void testLayersActivators() - throws Exception + throws Exception { SingletonAssembler assembly = new SingletonAssembler( module -> module.layer().withActivators( TestedActivator.class ) @@ -70,13 +71,12 @@ public class LayerActivationTest Application application = assembly.application(); // Assert activated - Assert.assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); // Passivate application.passivate(); // Assert passivated - Assert.assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } - } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ModuleActivationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ModuleActivationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ModuleActivationTest.java index 74b9b89..714a248 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ModuleActivationTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ModuleActivationTest.java @@ -23,8 +23,10 @@ import org.apache.polygene.api.activation.Activator; import org.apache.polygene.api.structure.Application; import org.apache.polygene.api.structure.Module; import org.apache.polygene.bootstrap.SingletonAssembler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class ModuleActivationTest { @@ -70,13 +72,13 @@ public class ModuleActivationTest Application application = assembly.application(); // Assert activated - Assert.assertEquals( "Activation Level", 2, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 2 ) ); // Passivate application.passivate(); // Assert passivated - Assert.assertEquals( "Passivation Level", 2, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 2 ) ); } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivationTest.java index 90c7de4..fb454a5 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivationTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivationTest.java @@ -25,8 +25,12 @@ import org.apache.polygene.api.service.ServiceComposite; import org.apache.polygene.api.service.ServiceReference; import org.apache.polygene.api.structure.Application; import org.apache.polygene.bootstrap.SingletonAssembler; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.jupiter.api.Assertions.fail; public class ServiceActivationTest { @@ -36,56 +40,61 @@ public class ServiceActivationTest private static int passivationLevel = 0; public static class TestedActivator - implements Activator<ServiceReference<TestedService>> + implements Activator<ServiceReference<TestedService>> { public void beforeActivation( ServiceReference<TestedService> activating ) { - Assert.assertFalse( "Service should not be active before activation", activating.isActive() ); - try { + assertThat( "Service should not be active before activation", activating.isActive(), is( false ) ); + try + { activating.get(); - Assert.fail( "Service is not activated yet, the reference get method should throw IllegalStateException." ); - } catch ( IllegalStateException expected ) { + fail( "Service is not activated yet, the reference get method should throw IllegalStateException." ); + } + catch( IllegalStateException expected ) + { } activationLevel++; } public void afterActivation( ServiceReference<TestedService> activated ) { - Assert.assertTrue( "Service should be active after activation", activated.isActive() ); - Assert.assertEquals( "After activation", "bar", activated.get().foo() ); + assertThat( "Service should be active after activation", activated.isActive(), is( true ) ); + assertThat( "After activation", activated.get().foo(), equalTo( "bar" ) ); activationLevel++; } public void beforePassivation( ServiceReference<TestedService> passivating ) { - Assert.assertTrue( "Service should be active before passivation", passivating.isActive() ); - Assert.assertEquals( "Before passivation", "bar", passivating.get().foo() ); + assertThat( "Service should be active before passivation", passivating.isActive(), is( true ) ); + assertThat( "Before passivation", passivating.get().foo(), equalTo( "bar" ) ); passivationLevel++; } public void afterPassivation( ServiceReference<TestedService> passivated ) { - Assert.assertFalse( "Service should not be active after passivation", passivated.isActive() ); - try { + assertThat( "Service should not be active after passivation", passivated.isActive(), is( false ) ); + try + { passivated.get(); - Assert.fail( "Service is passivated, the reference get method should throw IllegalStateException." ); - } catch ( IllegalStateException expected ) { + fail( "Service is passivated, the reference get method should throw IllegalStateException." ); + } + catch( IllegalStateException expected ) + { } passivationLevel++; } - } @Mixins( TestedServiceMixin.class ) public interface TestedServiceComposite - extends TestedService, ServiceComposite + extends TestedService, ServiceComposite { } @Mixins( TestedServiceMixin.class ) public interface TestedServiceComposite2 - extends TestedService, ServiceComposite + extends TestedService, ServiceComposite { } @@ -93,45 +102,42 @@ public class ServiceActivationTest { String foo(); - } public static class TestedServiceMixin - implements TestedService + implements TestedService { public String foo() { return "bar"; } - } @Test public void testServicesActivators() - throws Exception + throws Exception { SingletonAssembler assembly = new SingletonAssembler( module -> { module.addServices( TestedServiceComposite.class ). withActivators( TestedActivator.class ). - instantiateOnStartup(); + instantiateOnStartup(); module.addServices( TestedServiceComposite2.class ). withActivators( TestedActivator.class ). - instantiateOnStartup(); + instantiateOnStartup(); } ); // Activate Application application = assembly.application(); // Assert activated - Assert.assertEquals( "Activation Level", 4, activationLevel ); + assertThat( "Activation Level", activationLevel, equalTo( 4 ) ); // Passivate application.passivate(); // Assert passivated - Assert.assertEquals( "Passivation Level", 4, passivationLevel ); + assertThat( "Passivation Level", passivationLevel, equalTo( 4 ) ); } - } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/6ae17138/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivatorOrderTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivatorOrderTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivatorOrderTest.java index 20a91de..6cf0018 100644 --- a/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivatorOrderTest.java +++ b/core/runtime/src/test/java/org/apache/polygene/runtime/activation/ServiceActivatorOrderTest.java @@ -20,8 +20,6 @@ package org.apache.polygene.runtime.activation; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; import org.apache.polygene.api.activation.Activators; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.service.ServiceComposite; @@ -33,8 +31,11 @@ import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.Activati import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.ActivationStepsRecorderInstance; import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.Expected; import org.apache.polygene.runtime.activation.ActivatorOrderTestSupport.OrderTestActivator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; public class ServiceActivatorOrderTest { @@ -44,7 +45,7 @@ public class ServiceActivatorOrderTest // public static final ActivationStepsRecorder RECORDER = new ActivationStepsRecorderInstance(); - @Before + @BeforeEach public void beforeEachTest() { RECORDER.reset(); @@ -233,7 +234,7 @@ public class ServiceActivatorOrderTest String actual = Arrays.toString( RECORDER.steps().toArray() ); // System.out.println( "\n" + Expected.ALPHA_BETA_SINGLE + "\n" + actual + "\n" ); - assertEquals( Expected.ALPHA_BETA_SINGLE, actual ); + assertThat( actual, equalTo( Expected.ALPHA_BETA_SINGLE ) ); } @Test @@ -269,7 +270,7 @@ public class ServiceActivatorOrderTest String actual = Arrays.toString( RECORDER.steps().toArray() ); // System.out.println( "\n" + expected + "\n" + actual + "\n" ); - assertEquals( expected, actual ); + assertThat( actual, equalTo( expected ) ); } @Test @@ -314,7 +315,7 @@ public class ServiceActivatorOrderTest String actual = Arrays.toString( RECORDER.steps().toArray() ); // System.out.println( "\n" + expected + "\n" + actual + "\n" ); - assertEquals( expected, actual ); + assertThat( actual, equalTo( expected ) ); } @Test @@ -362,7 +363,7 @@ public class ServiceActivatorOrderTest } ); String actual = Arrays.toString( RECORDER.steps().toArray() ); // System.out.println( "\n" + expected + "\n" + actual + "\n" ); - assertEquals( expected, actual ); + assertThat( actual, equalTo( expected ) ); } }