diff --git a/README.md b/README.md index 93b8aea..39d3214 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ General: > libraries are automatically downloaded during build process + JUnit 5.+ ++ AssertJ 3.+ ----- diff --git a/ivy.xml b/ivy.xml index 5f669f0..6bfa95a 100644 --- a/ivy.xml +++ b/ivy.xml @@ -6,5 +6,6 @@ + diff --git a/test/dicontainer/DIContainerTest.java b/test/dicontainer/DIContainerTest.java index 6136be5..5706c43 100644 --- a/test/dicontainer/DIContainerTest.java +++ b/test/dicontainer/DIContainerTest.java @@ -1,7 +1,7 @@ package dicontainer; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,63 +39,73 @@ public void tearDown() @Test public void register_WhenSingleClass_ThenDifferentInstances() { + // given testObject.registerType(ClassConstructorDefault.class); - + // when ClassConstructorDefault result1 = testObject.resolve(ClassConstructorDefault.class); ClassConstructorDefault result2 = testObject.resolve(ClassConstructorDefault.class); - - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertNotSame(result1, result2); + // then + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test public void register_WhenSingleClassAsSingleton_ThenSameInstance() { + // given testObject.registerType(ClassConstructorDefault.class, ConstructionPolicy.SINGLETON); - + // when ClassConstructorDefault result1 = testObject.resolve(ClassConstructorDefault.class); ClassConstructorDefault result2 = testObject.resolve(ClassConstructorDefault.class); - - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertSame(result1, result2); + // then + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isSameAs(result1); } @Test public void register_WhenSingleClassChangesSingleton_ThenChangesInstances() { + // given 1 testObject.registerType(ClassConstructorDefault.class, ConstructionPolicy.SINGLETON); - + // when 1 ClassConstructorDefault result11 = testObject.resolve(ClassConstructorDefault.class); ClassConstructorDefault result12 = testObject.resolve(ClassConstructorDefault.class); + // then 1 + Assertions.assertThat(result11).isNotNull(); + Assertions.assertThat(result12).isNotNull(); + Assertions.assertThat(result12).isSameAs(result11); - Assertions.assertNotNull(result11); - Assertions.assertNotNull(result12); - Assertions.assertSame(result11, result12); - + // given 2 testObject.registerType(ClassConstructorDefault.class, ConstructionPolicy.CONSTRUCT); - + // when 2 ClassConstructorDefault result21 = testObject.resolve(ClassConstructorDefault.class); ClassConstructorDefault result22 = testObject.resolve(ClassConstructorDefault.class); - - Assertions.assertNotNull(result21); - Assertions.assertNotNull(result22); - Assertions.assertNotSame(result21, result22); + // then 2 + Assertions.assertThat(result21).isNotNull(); + Assertions.assertThat(result22).isNotNull(); + Assertions.assertThat(result22).isNotSameAs(result21); } @Test public void register_WhenSingleClassIsInterface_ThenAbstractTypeException() { - Assertions.assertThrows(AbstractTypeException.class, - () -> testObject.registerType(InterfaceBasic.class)); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.registerType(InterfaceBasic.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void register_WhenSingleClassIsAbstractClass_ThenAbstractTypeException() { - Assertions.assertThrows(AbstractTypeException.class, - () -> testObject.registerType(ClassBasicAbstract.class)); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.registerType(ClassBasicAbstract.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } // endregion @@ -104,115 +114,124 @@ public void register_WhenSingleClassIsAbstractClass_ThenAbstractTypeException() @Test public void register_WhenInheritanceFromInterface_ThenDifferentInstances() { + // given testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class); - + // when InterfaceBasic result1 = testObject.resolve(InterfaceBasic.class); InterfaceBasic result2 = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertNotSame(result1, result2); - Assertions.assertTrue(result1 instanceof ClassConstructorDefault); - Assertions.assertTrue(result2 instanceof ClassConstructorDefault); + // then + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isNotSameAs(result1); + Assertions.assertThat(result1).isInstanceOf(ClassConstructorDefault.class); + Assertions.assertThat(result2).isInstanceOf(ClassConstructorDefault.class); } @Test public void register_WhenInheritanceFromInterfaceAsSingleton_ThenSameInstances() { + // given testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class, ConstructionPolicy.SINGLETON); - + // when InterfaceBasic result1 = testObject.resolve(InterfaceBasic.class); InterfaceBasic result2 = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertSame(result1, result2); - Assertions.assertTrue(result1 instanceof ClassConstructorDefault); - Assertions.assertTrue(result2 instanceof ClassConstructorDefault); + // then + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isSameAs(result1); + Assertions.assertThat(result1).isInstanceOf(ClassConstructorDefault.class); + Assertions.assertThat(result2).isInstanceOf(ClassConstructorDefault.class); } @Test public void register_WhenInheritanceFromInterfaceChangesSingleton_ThenChangeInstances() { + // given 1 testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class, ConstructionPolicy.SINGLETON); - + // when 1 InterfaceBasic result11 = testObject.resolve(InterfaceBasic.class); InterfaceBasic result12 = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result11); - Assertions.assertNotNull(result12); - Assertions.assertSame(result11, result12); - Assertions.assertTrue(result11 instanceof ClassConstructorDefault); - Assertions.assertTrue(result12 instanceof ClassConstructorDefault); - + // then 1 + Assertions.assertThat(result11).isNotNull(); + Assertions.assertThat(result12).isNotNull(); + Assertions.assertThat(result12).isSameAs(result11); + Assertions.assertThat(result11).isInstanceOf(ClassConstructorDefault.class); + Assertions.assertThat(result12).isInstanceOf(ClassConstructorDefault.class); + + // given 2 testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class, ConstructionPolicy.CONSTRUCT); - + // when 2 InterfaceBasic result21 = testObject.resolve(InterfaceBasic.class); InterfaceBasic result22 = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result21); - Assertions.assertNotNull(result22); - Assertions.assertNotSame(result21, result22); - Assertions.assertTrue(result21 instanceof ClassConstructorDefault); - Assertions.assertTrue(result22 instanceof ClassConstructorDefault); + // then 2 + Assertions.assertThat(result21).isNotNull(); + Assertions.assertThat(result22).isNotNull(); + Assertions.assertThat(result22).isNotSameAs(result21); + Assertions.assertThat(result21).isInstanceOf(ClassConstructorDefault.class); + Assertions.assertThat(result22).isInstanceOf(ClassConstructorDefault.class); } @Test public void register_WhenInheritanceFromInterfaceChangesClass_ThenInstanceIsDerived() { + // given 1 testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class); - + // when 1 InterfaceBasic result1 = testObject.resolve(InterfaceBasic.class); + // then 1 + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result1).isInstanceOf(ClassConstructorDefault.class); - Assertions.assertNotNull(result1); - Assertions.assertTrue(result1 instanceof ClassConstructorDefault); - + // given 2 testObject.registerType(InterfaceBasic.class, ClassConstructorDefaultAndParameterized.class); - + // when 2 InterfaceBasic result3 = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result3); - Assertions.assertTrue(result3 instanceof ClassConstructorDefaultAndParameterized); + // then 2 + Assertions.assertThat(result3).isNotNull(); + Assertions.assertThat(result3).isInstanceOf(ClassConstructorDefaultAndParameterized.class); } @Test public void register_WhenInheritanceFromAbstractClass_ThenInstanceIsDerived() { + // given testObject.registerType(ClassBasicAbstract.class, ClassBasicInheritsFromAbstract.class); - + // when ClassBasicAbstract result = testObject.resolve(ClassBasicAbstract.class); - - Assertions.assertNotNull(result); - Assertions.assertTrue(result instanceof ClassBasicInheritsFromAbstract); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassBasicInheritsFromAbstract.class); } @Test public void register_WhenInheritanceFromConcreteClass_ThenInstanceIsDerived() { + // given testObject.registerType(ClassConstructorParameterized.class, ClassConstructorSuperParameterized.class); - + // when ClassConstructorParameterized result = testObject.resolve(ClassConstructorParameterized.class); - - Assertions.assertNotNull(result); - Assertions.assertTrue(result instanceof ClassConstructorSuperParameterized); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassConstructorSuperParameterized.class); } @Test public void register_WhenTwoStepsOfHierarchy_ThenInstanceIsDerived() { + // given testObject.registerType(InterfaceBasic.class, ClassBasicAbstract.class) .registerType(ClassBasicAbstract.class, ClassBasicInheritsFromAbstract.class); - + // when InterfaceBasic result = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result); - Assertions.assertTrue(result instanceof ClassBasicInheritsFromAbstract); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassBasicInheritsFromAbstract.class); } // endregion @@ -221,67 +240,76 @@ public void register_WhenTwoStepsOfHierarchy_ThenInstanceIsDerived() @Test public void registerInstance_WhenInterface_ThenRegisteredInstance() { - ClassConstructorDefault obj = new ClassConstructorDefault(); - - testObject.registerInstance(InterfaceBasic.class, obj); + // given + ClassConstructorDefault instance = new ClassConstructorDefault(); + testObject.registerInstance(InterfaceBasic.class, instance); + // when InterfaceBasic result = testObject.resolve(InterfaceBasic.class); - - Assertions.assertNotNull(result); - Assertions.assertTrue(result instanceof ClassConstructorDefault); - Assertions.assertSame(obj, result); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassConstructorDefault.class); + Assertions.assertThat(result).isSameAs(instance); } @Test public void registerInstance_WhenAbstractClass_ThenRegisteredInstance() { - ClassBasicInheritsFromAbstract obj = new ClassBasicInheritsFromAbstract(); - - testObject.registerInstance(ClassBasicAbstract.class, obj); + // given + ClassBasicInheritsFromAbstract instance = new ClassBasicInheritsFromAbstract(); + testObject.registerInstance(ClassBasicAbstract.class, instance); + // when ClassBasicAbstract result = testObject.resolve(ClassBasicAbstract.class); - - Assertions.assertNotNull(result); - Assertions.assertTrue(result instanceof ClassBasicInheritsFromAbstract); - Assertions.assertSame(obj, result); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassBasicInheritsFromAbstract.class); + Assertions.assertThat(result).isSameAs(instance); } @Test public void registerInstance_WhenSameConcreteClass_ThenRegisteredInstance() { - ClassConstructorDefaultAndParameterized obj = new ClassConstructorDefaultAndParameterized(); - - testObject.registerInstance(ClassConstructorDefaultAndParameterized.class, obj); + // given + ClassConstructorDefaultAndParameterized instance = + new ClassConstructorDefaultAndParameterized(); + testObject.registerInstance(ClassConstructorDefaultAndParameterized.class, instance); + // when ClassConstructorDefaultAndParameterized result = testObject.resolve(ClassConstructorDefaultAndParameterized.class); - - Assertions.assertNotNull(result); - Assertions.assertSame(obj, result); - Assertions.assertEquals(obj.getText(), result.getText()); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isSameAs(instance); + Assertions.assertThat(result.getText()).isEqualTo(instance.getText()); } @Test public void registerInstance_WhenDerivedConcreteClass_ThenRegisteredInstance() { - ClassConstructorSuperParameterized obj = new ClassConstructorSuperParameterized(); - - testObject.registerInstance(ClassConstructorParameterized.class, obj); + // given + ClassConstructorSuperParameterized instance = new ClassConstructorSuperParameterized(); + testObject.registerInstance(ClassConstructorParameterized.class, instance); + // when ClassConstructorParameterized result = testObject.resolve(ClassConstructorParameterized.class); - - Assertions.assertNotNull(result); - Assertions.assertSame(obj, result); - Assertions.assertTrue(result instanceof ClassConstructorSuperParameterized); - Assertions.assertEquals(obj.getNumber(), result.getNumber()); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result).isSameAs(instance); + Assertions.assertThat(result).isInstanceOf(ClassConstructorSuperParameterized.class); + Assertions.assertThat(result.getNumber()).isEqualTo(instance.getNumber()); } @Test public void registerInstance_WhenInstanceIsNull_ThenNullInstanceException() { - Assertions.assertThrows(NullInstanceException.class, () -> testObject.registerInstance( - ClassConstructorDefaultAndParameterized.class, null)); + // when + Throwable throwable = Assertions.catchThrowable( + () -> testObject.registerInstance(ClassConstructorDefaultAndParameterized.class, + null)); + // then + Assertions.assertThat(throwable).isInstanceOf(NullInstanceException.class); } // endregion @@ -290,93 +318,113 @@ public void registerInstance_WhenInstanceIsNull_ThenNullInstanceException() @Test public void resolve_WhenMultipleAnnotatedConstructors_ThenMultipleAnnotatedConstructorsException() { - Assertions.assertThrows(MultipleAnnotatedConstructorsException.class, - () -> testObject.resolve(ClassConstructorMultipleAnnotated.class)); + // when + Throwable throwable = Assertions.catchThrowable( + () -> testObject.resolve(ClassConstructorMultipleAnnotated.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(MultipleAnnotatedConstructorsException.class); } @Test public void resolve_WhenNoPublicConstructors_ThenNoSuitableConstructorException() { - Assertions.assertThrows(NoSuitableConstructorException.class, - () -> testObject.resolve(ClassConstructorPrivate.class)); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.resolve(ClassConstructorPrivate.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(NoSuitableConstructorException.class); } @Test public void resolve_WhenDependencySetterHasReturnType_ThenIncorrectDependencySetterException() { - Assertions.assertThrows(IncorrectDependencySetterException.class, - () -> testObject.resolve(ClassSetterIncorrectReturnType.class)); + // when + Throwable throwable = Assertions.catchThrowable( + () -> testObject.resolve(ClassSetterIncorrectReturnType.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void resolve_WhenDependencySetterHasNoParameters_ThenIncorrectDependencySetterException() { - Assertions.assertThrows(IncorrectDependencySetterException.class, - () -> testObject.resolve(ClassSetterWithoutParameters.class)); + // when + Throwable throwable = Assertions.catchThrowable( + () -> testObject.resolve(ClassSetterWithoutParameters.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void resolve_WhenDependencySetterNameDoesNotStartWithSet_ThenIncorrectDependencySetterException() { - Assertions.assertThrows(IncorrectDependencySetterException.class, - () -> testObject.resolve(ClassSetterIncorrectName.class)); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.resolve(ClassSetterIncorrectName.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void resolve_WhenDependencySetterOnly_ThenInstanceIsResolved() { + // given testObject.registerType(InterfaceSetter.class, ClassSetterSingle.class) .registerType(InterfaceBasic.class, ClassConstructorDefault.class); - + // when InterfaceSetter result = testObject.resolve(InterfaceSetter.class); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertTrue(result instanceof ClassSetterSingle); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassSetterSingle.class); } @Test public void resolve_WhenDependencySetterAndConstructor_ThenInstanceIsResolved() { + // given testObject.registerType(InterfaceSetter.class, ClassSetterConstructor.class) .registerType(InterfaceBasic.class, ClassConstructorDefault.class); - + // when InterfaceSetter result = testObject.resolve(InterfaceSetter.class); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertTrue(result instanceof ClassSetterConstructor); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result).isInstanceOf(ClassSetterConstructor.class); } @Test public void resolve_WhenDoubleDependencySetter_ThenIncorrectDependencySetterException() { + // given testObject.registerType(InterfaceSetterMultipleParameters.class, ClassSetterMultipleParameters.class); - - Assertions.assertThrows(IncorrectDependencySetterException.class, - () -> testObject.resolve(InterfaceSetterMultipleParameters.class)); + // when + Throwable throwable = Assertions.catchThrowable( + () -> testObject.resolve(InterfaceSetterMultipleParameters.class)); + // then + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void resolve_WhenMultipleDependencySetters_ThenInstanceIsResolved() { + // given String string = "string"; - testObject.registerType(InterfaceSetterMultiple.class, ClassSetterMultiple.class) + testObject.registerInstance(String.class, string) + .registerType(InterfaceSetterMultiple.class, ClassSetterMultiple.class) .registerType(InterfaceBasic.class, ClassConstructorDefault.class) .registerType(InterfaceBasicStringGetter.class, ClassBasicStringGetter.class); - - testObject.registerInstance(String.class, string); - + // when InterfaceSetterMultiple result = testObject.resolve(InterfaceSetterMultiple.class); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(result.getStringObject()); - Assertions.assertNotNull(result.getStringObject().getString()); - Assertions.assertEquals(string, result.getStringObject().getString()); - Assertions.assertTrue(result instanceof ClassSetterMultiple); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getStringObject()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isEqualTo(string); + Assertions.assertThat(result).isInstanceOf(ClassSetterMultiple.class); } // endregion @@ -385,56 +433,61 @@ public void resolve_WhenMultipleDependencySetters_ThenInstanceIsResolved() @Test public void buildUp_WhenDependencySetterOnly_ThenInstanceIsBuiltUp() { + // given testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class); InterfaceSetter instance = new ClassSetterSingle(); - + // when InterfaceSetter result = testObject.buildUp(instance); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(instance); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(instance.getBasicObject()); - Assertions.assertSame(instance, result); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(instance).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(instance.getBasicObject()).isNotNull(); + Assertions.assertThat(result).isSameAs(instance); } @Test - public void buildUp_WhenDoubleDependencySetter_ThenIncorrectDependencySetterException() + public void buildUp_WhenDependencySetterHasMultipleParameters_ThenIncorrectDependencySetterException() { + // given InterfaceSetterMultipleParameters instance = new ClassSetterMultipleParameters(); - - Assertions.assertThrows(IncorrectDependencySetterException.class, - () -> testObject.buildUp(instance)); + // when + Throwable throwable = Assertions.catchThrowable(() -> testObject.buildUp(instance)); + // then + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void buildUp_WhenMultipleDependencySetters_ThenInstanceIsBuiltUp() { + // given String string = "string"; + InterfaceSetterMultiple instance = new ClassSetterMultiple(); testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class) .registerType(InterfaceBasicStringGetter.class, ClassBasicStringGetter.class) .registerInstance(String.class, string); - - InterfaceSetterMultiple instance = new ClassSetterMultiple(); + // when InterfaceSetterMultiple result = testObject.buildUp(instance); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(instance); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(instance.getBasicObject()); - Assertions.assertNotNull(result.getStringObject()); - Assertions.assertNotNull(instance.getStringObject()); - Assertions.assertNotNull(result.getStringObject().getString()); - Assertions.assertNotNull(instance.getStringObject().getString()); - Assertions.assertEquals(string, result.getStringObject().getString()); - Assertions.assertEquals(string, instance.getStringObject().getString()); - Assertions.assertSame(instance, result); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(instance).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(instance.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getStringObject()).isNotNull(); + Assertions.assertThat(instance.getStringObject()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isNotNull(); + Assertions.assertThat(instance.getStringObject().getString()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isEqualTo(string); + Assertions.assertThat(instance.getStringObject().getString()).isEqualTo(string); + Assertions.assertThat(result).isSameAs(instance); } @Test public void buildUp_WhenComplexDependency_ThenInstanceIsBuiltUp() { + // given String string = "string"; testObject.registerType(InterfaceBasic.class, ClassConstructorDefault.class) @@ -446,26 +499,26 @@ public void buildUp_WhenComplexDependency_ThenInstanceIsBuiltUp() InterfaceDiamondLeft diamond1 = testObject.resolve(InterfaceDiamondLeft.class); InterfaceBasicStringGetter withString = testObject.resolve(InterfaceBasicStringGetter.class); - InterfaceBasicComplexDependency instance = new ClassBasicComplexDependency(diamond1, withString); + // when InterfaceBasicComplexDependency result = testObject.buildUp(instance); - - Assertions.assertNotNull(result); - Assertions.assertNotNull(instance); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(instance.getBasicObject()); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNotNull(instance.getFirstObject()); - Assertions.assertNotNull(result.getSecondObject()); - Assertions.assertNotNull(instance.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertNotNull(instance.getFirstObject().getObject()); - Assertions.assertNotNull(result.getSecondObject().getString()); - Assertions.assertNotNull(instance.getSecondObject().getString()); - Assertions.assertEquals(string, result.getSecondObject().getString()); - Assertions.assertEquals(string, instance.getSecondObject().getString()); - Assertions.assertSame(instance, result); + // then + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(instance).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(instance.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(instance.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNotNull(); + Assertions.assertThat(instance.getSecondObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(instance.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(instance.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isEqualTo(string); + Assertions.assertThat(instance.getSecondObject().getString()).isEqualTo(string); + Assertions.assertThat(result).isSameAs(instance); } // endregion diff --git a/test/dicontainer/dictionary/DIDictionaryTest.java b/test/dicontainer/dictionary/DIDictionaryTest.java index 9c82456..23cc7fb 100644 --- a/test/dicontainer/dictionary/DIDictionaryTest.java +++ b/test/dicontainer/dictionary/DIDictionaryTest.java @@ -1,10 +1,9 @@ package dicontainer.dictionary; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import dicontainer.ConstructionPolicy; import dicontainer.auxiliary.basic.ClassBasicAbstract; @@ -49,8 +48,8 @@ public void addType_findType_WhenSpecifyTypeWithSubtypeAndPolicy_ThenSubtypeInse SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(subtype, result.subtype); - Assertions.assertEquals(ConstructionPolicy.SINGLETON, result.policy); + Assertions.assertThat(result.subtype).isEqualTo(subtype); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.SINGLETON); } @Test @@ -63,8 +62,8 @@ public void addType_findType_WhenSpecifyTypeAndPolicy_ThenThisTypeInserted() SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(type, result.subtype); - Assertions.assertEquals(ConstructionPolicy.SINGLETON, result.policy); + Assertions.assertThat(result.subtype).isEqualTo(type); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.SINGLETON); } @Test @@ -77,8 +76,8 @@ public void addType_findType_WhenTypeHasSelfRegisterAnnotation_ThenThisTypeInser SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(type, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(type); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -91,8 +90,8 @@ public void addType_findType_WhenTypeHasRegisterAnnotation_ThenSubtypeInserted() SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(ClassRegisterDerivedFromRegister.class, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(ClassRegisterDerivedFromRegister.class); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } // endregion @@ -102,70 +101,77 @@ public void addType_findType_WhenTypeHasRegisterAnnotation_ThenSubtypeInserted() public void addType_WhenSingleInterface_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.addType(InterfaceBasic.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.addType(InterfaceBasic.class)); // then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void addType_WhenSingleAbstractClass_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.addType(ClassBasicAbstract.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.addType(ClassBasicAbstract.class)); // then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void addType_WhenRegisterAnnotatedTypeAndSubtype_ThenAnnotatedTypeRegistrationException() { // when - Executable executable = () -> testObject.addType(ClassRegisterConcrete.class, - ClassRegisterDerivedFromRegister.class, - ConstructionPolicy.getDefault()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addType(ClassRegisterConcrete.class, + ClassRegisterDerivedFromRegister.class, + ConstructionPolicy.getDefault())); // then - Assertions.assertThrows(AnnotatedTypeRegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AnnotatedTypeRegistrationException.class); } @Test public void addType_WhenSelfRegisterAnnotatedTypeAndSubtype_ThenAnnotatedTypeRegistrationException() { // when - Executable executable = () -> testObject.addType(ClassRegisterSelf.class, - ClassRegisterDerivedFromSelfRegister.class, - ConstructionPolicy.getDefault()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addType(ClassRegisterSelf.class, + ClassRegisterDerivedFromSelfRegister.class, + ConstructionPolicy.getDefault())); // then - Assertions.assertThrows(AnnotatedTypeRegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AnnotatedTypeRegistrationException.class); } @Test public void addType_WhenRegisterTypeAndNotSubtype_ThenNotDerivedTypeException() { // when - Executable executable = () -> testObject.addType(ClassRegisterIncorrectOtherClass.class, - ConstructionPolicy.getDefault()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addType(ClassRegisterIncorrectOtherClass.class, + ConstructionPolicy.getDefault())); // then - Assertions.assertThrows(NotDerivedTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NotDerivedTypeException.class); } @Test public void addType_WhenRegisterTypeAndAbstract_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.addType(ClassRegisterAbstractIncorrect.class, - ConstructionPolicy.getDefault()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addType(ClassRegisterAbstractIncorrect.class, + ConstructionPolicy.getDefault())); // then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void addType_WhenSelfRegisterAbstract_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.addType(ClassRegisterSelfAbstractIncorrect.class, - ConstructionPolicy.getDefault()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addType(ClassRegisterSelfAbstractIncorrect.class, + ConstructionPolicy.getDefault())); // then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test @@ -178,18 +184,18 @@ public void addType_WhenRegisteredInstance_ThenRegistrationException() testObject.addInstance(type, instance); // when - Executable executable = () -> testObject.addType(type); + Throwable throwable = Assertions.catchThrowable(() -> testObject.addType(type)); // then - Assertions.assertThrows(RegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(RegistrationException.class); } @Test public void addType_WhenPrimitiveType_ThenRegistrationException() { // when - Executable executable = () -> testObject.addType(boolean.class); + Throwable throwable = Assertions.catchThrowable(() -> testObject.addType(boolean.class)); // then - Assertions.assertThrows(RegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(RegistrationException.class); } // endregion @@ -207,9 +213,9 @@ public void addInstance_findInstance_WhenInstancePresent_ThenInstance() Instance result = testObject.findInstance(ClassBasicStringGetter.class); // then - Assertions.assertTrue(result.exists()); - Assertions.assertSame(instance, result.extract()); - Assertions.assertEquals(string, result.extract().getString()); + Assertions.assertThat(result.exists()).isTrue(); + Assertions.assertThat(result.extract()).isSameAs(instance); + Assertions.assertThat(result.extract().getString()).isEqualTo(string); } // endregion @@ -225,28 +231,31 @@ public void addInstance_WhenRegisteredType_ThenRegistrationException() testObject.addType(type); // when - Executable executable = () -> testObject.addInstance(type, instance); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.addInstance(type, instance)); // then - Assertions.assertThrows(RegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(RegistrationException.class); } @Test public void addInstance_WhenAnnotatedType_ThenRegistrationException() { // when - Executable executable = () -> testObject.addInstance(ClassRegisterConcrete.class, - new ClassRegisterConcrete()); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addInstance(ClassRegisterConcrete.class, + new ClassRegisterConcrete())); // then - Assertions.assertThrows(RegistrationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(RegistrationException.class); } @Test public void addInstance_WhenNullInstance_ThenNullInstanceException() { // when - Executable executable = () -> testObject.addInstance(ClassBasicAbstract.class, null); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.addInstance(ClassBasicAbstract.class, null)); // then - Assertions.assertThrows(NullInstanceException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NullInstanceException.class); } // endregion @@ -258,8 +267,8 @@ public void findType_WhenPrimitive_ThenFoundMapping() // when SubtypeMapping result = testObject.findType(double.class); // then - Assertions.assertEquals(double.class, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(double.class); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -273,8 +282,8 @@ public void findType_WhenAbstractClass_ThenFoundMapping() // when SubtypeMapping result = testObject.findType(InterfaceBasic.class); // then - Assertions.assertEquals(ClassBasicInheritsFromAbstract.class, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(ClassBasicInheritsFromAbstract.class); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -285,8 +294,8 @@ public void findType_WhenConcreteClassNotRegistered_ThenFoundNewMapping() // when SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(type, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(type); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -296,8 +305,8 @@ public void findType_WhenAnnotatedClass_ThenMappingFromAnnotation() SubtypeMapping result = testObject.findType(ClassRegisterAbstract.class); // then - Assertions.assertEquals(ClassRegisterDerivedFromRegister.class, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(ClassRegisterDerivedFromRegister.class); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -309,9 +318,10 @@ public void findType_WhenDifferentPolicy_ThenMixingPoliciesException() testObject.addType(ClassBasicAbstract.class, ClassBasicInheritsFromAbstract.class, ConstructionPolicy.SINGLETON); // when - Executable executable = () -> testObject.findType(InterfaceBasic.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.findType(InterfaceBasic.class)); // then - Assertions.assertThrows(MixingPoliciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MixingPoliciesException.class); } @Test @@ -321,8 +331,8 @@ public void findType_WhenSelfRegisterClass_ThenMapping() SubtypeMapping result = testObject.findType(ClassRegisterSelf.class); // then - Assertions.assertEquals(ClassRegisterSelf.class, result.subtype); - Assertions.assertEquals(ConstructionPolicy.getDefault(), result.policy); + Assertions.assertThat(result.subtype).isEqualTo(ClassRegisterSelf.class); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.getDefault()); } @Test @@ -335,8 +345,8 @@ public void findType_whenRegisteredInstance_ThenMappingToThisType() // when SubtypeMapping result = testObject.findType(type); // then - Assertions.assertEquals(type, result.subtype); - Assertions.assertEquals(ConstructionPolicy.SINGLETON, result.policy); + Assertions.assertThat(result.subtype).isEqualTo(type); + Assertions.assertThat(result.policy).isEqualTo(ConstructionPolicy.SINGLETON); } // endregion @@ -349,7 +359,7 @@ public void findInstance_WhenInstanceAbsent_ThenMappingNone() Instance result = testObject.findInstance(ClassBasicStringGetter.class); // then - Assertions.assertFalse(result.exists()); + Assertions.assertThat(result.exists()).isFalse(); } // endregion @@ -363,7 +373,7 @@ public void contains_WhenAddedInstance_ThenTrue() // when boolean result = testObject.contains(ClassBasicStringGetter.class); // then - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } @Test @@ -372,7 +382,7 @@ public void contains_WhenAbstractTypeIsAbsent_ThenFalse() // when boolean result = testObject.contains(InterfaceBasic.class); // then - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } @Test @@ -381,7 +391,7 @@ public void contains_WhenConcreteTypeIsAbsent_ThenFalse() // when boolean result = testObject.contains(ClassBasicInheritsFromAbstract.class); // then - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } @Test @@ -390,7 +400,7 @@ public void contains_WhenAnnotatedTypeIsAbsent_ThenTrue() // when boolean result = testObject.contains(ClassRegisterConcrete.class); // then - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } @Test @@ -403,7 +413,7 @@ public void contains_WhenAnnotatedTypeIsPresent_ThenTrue() // when boolean result = testObject.contains(type); // then - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } @Test @@ -416,7 +426,7 @@ public void contains_WhenInsertedTypeIsPresent_ThenTrue() // when boolean result = testObject.contains(type); // then - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } @Test @@ -425,7 +435,7 @@ public void contains_WhenAnnotatedTypeIncorrect_ThenFalse() // when boolean result = testObject.contains(ClassRegisterSelfAbstractIncorrect.class); // then - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } // endregion @@ -444,8 +454,8 @@ public void addSingleton_findInstance_WhenRegisteredTypeAsSingleton_ThenSingleto Instance result = testObject.findInstance(ClassBasicAbstract.class); // then - Assertions.assertTrue(result.exists()); - Assertions.assertSame(singleton, result.extract()); + Assertions.assertThat(result.exists()).isTrue(); + Assertions.assertThat(result.extract()).isSameAs(singleton); } @Test @@ -461,7 +471,7 @@ public void addSingleton_findInstance_WhenRegisteredTypeAsNotSingleton_ThenNoIns Instance result = testObject.findInstance(ClassBasicAbstract.class); // then - Assertions.assertFalse(result.exists()); + Assertions.assertThat(result.exists()).isFalse(); } @Test @@ -474,7 +484,7 @@ public void addSingleton_findInstance_WhenNotRegisteredType_ThenNoInstance() Instance result = testObject.findInstance(ClassBasicAbstract.class); // then - Assertions.assertFalse(result.exists()); + Assertions.assertThat(result.exists()).isFalse(); } // endregion diff --git a/test/dicontainer/resolver/ConstructorComparatorTest.java b/test/dicontainer/resolver/ConstructorComparatorTest.java index 310b2ed..38b719b 100644 --- a/test/dicontainer/resolver/ConstructorComparatorTest.java +++ b/test/dicontainer/resolver/ConstructorComparatorTest.java @@ -2,8 +2,9 @@ import java.lang.reflect.Constructor; import java.util.Arrays; +import java.util.stream.Collectors; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,13 +35,11 @@ public void compare_WhenSorting_ThenFirstDependencyAndNextByParametersDescending // when Arrays.sort(constructors, testObject); // then - Assertions.assertTrue(constructors[0].isAnnotationPresent(Dependency.class)); - Assertions.assertEquals(3, constructors[0].getParameterCount()); - Assertions.assertEquals(5, constructors[1].getParameterCount()); - Assertions.assertEquals(4, constructors[2].getParameterCount()); - Assertions.assertEquals(2, constructors[3].getParameterCount()); - Assertions.assertEquals(1, constructors[4].getParameterCount()); - Assertions.assertEquals(0, constructors[5].getParameterCount()); + Assertions.assertThat(constructors[0].isAnnotationPresent(Dependency.class)).isTrue(); + Assertions.assertThat(Arrays.stream(constructors) + .map(Constructor::getParameterCount) + .collect(Collectors.toList())) + .containsExactly(3, 5, 4, 2, 1, 0); } @Test @@ -53,7 +52,7 @@ public void compare_WhenDependencyAnnotated_ThenLess() // when int result = testObject.compare(constructors[3], constructors[4]); // then - Assertions.assertEquals(-1, result); + Assertions.assertThat(result).isEqualTo(-1); } @Test @@ -66,6 +65,6 @@ public void compare_WhenNotDependencyAnnotated_ThenByParametersCountDescending() // when int result = testObject.compare(constructors[2], constructors[5]); // then - Assertions.assertEquals(1, result); + Assertions.assertThat(result).isEqualTo(1); } } diff --git a/test/dicontainer/resolver/DIResolverTest.java b/test/dicontainer/resolver/DIResolverTest.java index f694ace..cd06b44 100644 --- a/test/dicontainer/resolver/DIResolverTest.java +++ b/test/dicontainer/resolver/DIResolverTest.java @@ -1,10 +1,9 @@ package dicontainer.resolver; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import dicontainer.ConstructionPolicy; import dicontainer.auxiliary.basic.*; @@ -44,7 +43,7 @@ public void construct_WhenClassHasDefaultConstructorOnly_ThenInstanceIsResolved( // when ClassConstructorDefault result = testObject.construct(ClassConstructorDefault.class); // then - Assertions.assertNotNull(result); + Assertions.assertThat(result).isNotNull(); } @Test @@ -54,7 +53,7 @@ public void construct_WhenClassInheritsFromConcreteClass_ThenInstanceIsResolved( ClassConstructorSuperParameterized result = testObject.construct(ClassConstructorSuperParameterized.class); // then - Assertions.assertNotNull(result); + Assertions.assertThat(result).isNotNull(); } @Test @@ -64,16 +63,17 @@ public void construct_WhenClassInheritsFromAbstractClass_ThenInstanceIsResolved( ClassBasicInheritsFromAbstract result = testObject.construct(ClassBasicInheritsFromAbstract.class); // then - Assertions.assertNotNull(result); + Assertions.assertThat(result).isNotNull(); } @Test public void construct_WhenClassHasParameterConstructorWithoutRegisteredParameter_ThenMissingDependenciesException() { // when - Executable executable = () -> testObject.construct(ClassConstructorParameterized.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassConstructorParameterized.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test @@ -87,8 +87,8 @@ public void construct_WhenClassHasParameterConstructorWithRegisteredPrimitivePar ClassConstructorParameterized result = testObject.construct(ClassConstructorParameterized.class); // then - Assertions.assertNotNull(result); - Assertions.assertEquals(number, result.getNumber()); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getNumber()).isEqualTo(number); } @Test @@ -99,9 +99,10 @@ public void construct_WhenClassHasPrimitiveParameterConstructorButRegisteredRefe dictionary.addInstance(Integer.class, number); // when - Executable executable = () -> testObject.construct(ClassConstructorParameterized.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassConstructorParameterized.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test @@ -111,61 +112,66 @@ public void construct_WhenClassHasDefaultAndParameterConstructorWithoutRegistere ClassConstructorDefaultAndParameterized result = testObject.construct(ClassConstructorDefaultAndParameterized.class); // then - Assertions.assertNotNull(result); + Assertions.assertThat(result).isNotNull(); } @Test public void construct_WhenInterface_ThenMissingDependenciesException() { // when - Executable executable = () -> testObject.construct(InterfaceBasic.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(InterfaceBasic.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test public void construct_WhenAbstractClass_ThenMissingDependenciesException() { // when - Executable executable = () -> testObject.construct(ClassBasicAbstract.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(ClassBasicAbstract.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test public void construct_WhenClassConstructorThrowsException_ThenNoInstanceCreatedException() { // when - Executable executable = () -> testObject.construct(ClassConstructorExceptionThrown.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassConstructorExceptionThrown.class)); // then - Assertions.assertThrows(NoInstanceCreatedException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NoInstanceCreatedException.class); } @Test public void construct_WhenPrimitiveType_ThenNoSuitableConstructorException() { // when - Executable executable = () -> testObject.construct(double.class); + Throwable throwable = Assertions.catchThrowable(() -> testObject.construct(double.class)); // then - Assertions.assertThrows(NoSuitableConstructorException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NoSuitableConstructorException.class); } @Test public void construct_WhenMultipleAnnotatedConstructors_ThenMultipleAnnotatedConstructorsException() { // when - Executable executable = () -> testObject.construct(ClassConstructorMultipleAnnotated.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassConstructorMultipleAnnotated.class)); // then - Assertions.assertThrows(MultipleAnnotatedConstructorsException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MultipleAnnotatedConstructorsException.class); } @Test public void construct_WhenNoPublicConstructors_ThenNoSuitableConstructorException() { // when - Executable executable = () -> testObject.construct(ClassConstructorPrivate.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassConstructorPrivate.class)); // then - Assertions.assertThrows(NoSuitableConstructorException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NoSuitableConstructorException.class); } // endregion @@ -175,45 +181,50 @@ public void construct_WhenNoPublicConstructors_ThenNoSuitableConstructorExceptio public void construct_WhenDependencySetterHasReturnType_ThenIncorrectDependencySetterException() { // when - Executable executable = () -> testObject.construct(ClassSetterIncorrectReturnType.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassSetterIncorrectReturnType.class)); // then - Assertions.assertThrows(IncorrectDependencySetterException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void construct_WhenDependencySetterHasNoParameters_ThenIncorrectDependencySetterException() { // when - Executable executable = () -> testObject.construct(ClassSetterWithoutParameters.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassSetterWithoutParameters.class)); // then - Assertions.assertThrows(IncorrectDependencySetterException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void construct_WhenDependencySetterHasIncorrectName_ThenIncorrectDependencySetterException() { // when - Executable executable = () -> testObject.construct(ClassSetterIncorrectName.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassSetterIncorrectName.class)); // then - Assertions.assertThrows(IncorrectDependencySetterException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void construct_WhenDependencySetterHasMultipleParameters_ThenIncorrectDependencySetterException() { // when - Executable executable = () -> testObject.construct(ClassSetterMultipleParameters.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassSetterMultipleParameters.class)); // then - Assertions.assertThrows(IncorrectDependencySetterException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(IncorrectDependencySetterException.class); } @Test public void construct_WhenMissingDependency_ThenMissingDependenciesException() { // when - Executable executable = () -> testObject.construct(ClassSetterSingle.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(ClassSetterSingle.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test @@ -222,9 +233,10 @@ public void construct_WhenSetterThrowsException_ThenSetterInvocationException() // given dictionary.addInstance(String.class, "string"); // when - Executable executable = () -> testObject.construct(ClassSetterThrows.class); + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(ClassSetterThrows.class)); // then - Assertions.assertThrows(SetterInvocationException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(SetterInvocationException.class); } @Test @@ -235,8 +247,8 @@ public void construct_WhenDependencySetterOnly_ThenInstanceIsResolved() // when InterfaceSetter result = testObject.construct(ClassSetterSingle.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); } @Test @@ -252,11 +264,11 @@ public void construct_WhenMultipleDependencySetters_ThenInstanceIsResolved() // when InterfaceSetterMultiple result = testObject.construct(InterfaceSetterMultiple.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(result.getStringObject()); - Assertions.assertNotNull(result.getStringObject().getString()); - Assertions.assertEquals(string, result.getStringObject().getString()); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getStringObject()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isEqualTo(string); } // endregion @@ -284,13 +296,14 @@ public void construct_WhenDependenciesWithRegisteredInstance_ThenInstanceIsResol InterfaceBasicSimpleDependency result = testObject.construct(InterfaceBasicSimpleDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNotNull(result.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertNotNull(result.getSecondObject().getString()); - Assertions.assertEquals(string, result.getSecondObject().getString()); - Assertions.assertTrue(result instanceof ClassConstructorNotAnnotatedWithDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isEqualTo(string); + Assertions.assertThat(result) + .isInstanceOf(ClassConstructorNotAnnotatedWithDependency.class); } @Test @@ -312,13 +325,14 @@ public void construct_WhenDependenciesWithoutAnnotatedConstructorsWithAllDepende InterfaceBasicSimpleDependency result = testObject.construct(InterfaceBasicSimpleDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNotNull(result.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertNotNull(result.getSecondObject().getString()); - Assertions.assertEquals("", result.getSecondObject().getString()); - Assertions.assertTrue(result instanceof ClassConstructorNotAnnotatedWithDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isEqualTo(""); + Assertions.assertThat(result) + .isInstanceOf(ClassConstructorNotAnnotatedWithDependency.class); } @Test @@ -338,11 +352,12 @@ public void construct_WhenDependenciesWithoutAnnotatedConstructorsWithoutSomeDep InterfaceBasicSimpleDependency result = testObject.construct(InterfaceBasicSimpleDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNull(result.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertTrue(result instanceof ClassConstructorNotAnnotatedWithDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result) + .isInstanceOf(ClassConstructorNotAnnotatedWithDependency.class); } @Test @@ -364,13 +379,13 @@ public void construct_WhenDependenciesWithAnnotatedConstructor_ThenInstanceIsRes InterfaceBasicSimpleDependency result = testObject.construct(InterfaceBasicSimpleDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNotNull(result.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertNotNull(result.getSecondObject().getString()); - Assertions.assertEquals("", result.getSecondObject().getString()); - Assertions.assertTrue(result instanceof ClassConstructorAnnotatedWithDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isEqualTo(""); + Assertions.assertThat(result).isInstanceOf(ClassConstructorAnnotatedWithDependency.class); } @Test @@ -383,9 +398,11 @@ public void construct_WhenDependenciesWithAnnotatedConstructorWithoutSomeDepende ConstructionPolicy.getDefault()); dictionary.addType(InterfaceDiamondBottom.class, ClassDiamondBottom.class, ConstructionPolicy.getDefault()); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(InterfaceDiamondBottom.class)); // then - Assertions.assertThrows(MissingDependenciesException.class, - () -> testObject.construct(InterfaceDiamondBottom.class)); + Assertions.assertThat(throwable).isInstanceOf(MissingDependenciesException.class); } @Test @@ -403,14 +420,14 @@ public void construct_WhenDiamondDependenciesWithoutSingleton_ThenInstanceIsReso // when InterfaceDiamondBottom result = testObject.construct(InterfaceDiamondBottom.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getDiamond1()); - Assertions.assertNotNull(result.getDiamond2()); - Assertions.assertNotNull(result.getDiamond1().getObject()); - Assertions.assertNotNull(result.getDiamond2().getObject()); - Assertions.assertNotSame(result.getDiamond1().getObject(), - result.getDiamond2().getObject()); - Assertions.assertTrue(result instanceof ClassDiamondBottom); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getDiamond1()).isNotNull(); + Assertions.assertThat(result.getDiamond2()).isNotNull(); + Assertions.assertThat(result.getDiamond1().getObject()).isNotNull(); + Assertions.assertThat(result.getDiamond2().getObject()).isNotNull(); + Assertions.assertThat(result.getDiamond1().getObject()) + .isNotSameAs(result.getDiamond2().getObject()); + Assertions.assertThat(result).isInstanceOf(ClassDiamondBottom.class); } @Test @@ -428,13 +445,14 @@ public void construct_WhenDiamondDependenciesWithSingleton_ThenInstanceIsResolve // when InterfaceDiamondBottom result = testObject.construct(InterfaceDiamondBottom.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getDiamond1()); - Assertions.assertNotNull(result.getDiamond2()); - Assertions.assertNotNull(result.getDiamond1().getObject()); - Assertions.assertNotNull(result.getDiamond2().getObject()); - Assertions.assertSame(result.getDiamond1().getObject(), result.getDiamond2().getObject()); - Assertions.assertTrue(result instanceof ClassDiamondBottom); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getDiamond1()).isNotNull(); + Assertions.assertThat(result.getDiamond2()).isNotNull(); + Assertions.assertThat(result.getDiamond1().getObject()).isNotNull(); + Assertions.assertThat(result.getDiamond2().getObject()).isNotNull(); + Assertions.assertThat(result.getDiamond2().getObject()) + .isSameAs(result.getDiamond1().getObject()); + Assertions.assertThat(result).isInstanceOf(ClassDiamondBottom.class); } @Test @@ -445,9 +463,11 @@ public void construct_WhenCircularDependencies_ThenCircularDependenciesException ConstructionPolicy.getDefault()); dictionary.addType(InterfaceCircularRight.class, ClassCircularRight.class, ConstructionPolicy.getDefault()); + // when + Throwable throwable = + Assertions.catchThrowable(() -> testObject.construct(InterfaceCircularRight.class)); // then - Assertions.assertThrows(CircularDependenciesException.class, - () -> testObject.construct(InterfaceCircularRight.class)); + Assertions.assertThat(throwable).isInstanceOf(CircularDependenciesException.class); } @Test @@ -469,12 +489,12 @@ public void construct_WhenCanOmitCircularDependencies_ThenInstanceIsResolved() InterfaceCircularDependency result = testObject.construct(InterfaceCircularDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getNonCircularObject()); - Assertions.assertNull(result.getCircularObject()); - Assertions.assertNotNull(result.getNonCircularObject().getString()); - Assertions.assertEquals(string, result.getNonCircularObject().getString()); - Assertions.assertTrue(result instanceof ClassCircularDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getNonCircularObject()).isNotNull(); + Assertions.assertThat(result.getCircularObject()).isNull(); + Assertions.assertThat(result.getNonCircularObject().getString()).isNotNull(); + Assertions.assertThat(result.getNonCircularObject().getString()).isEqualTo(string); + Assertions.assertThat(result).isInstanceOf(ClassCircularDependency.class); } @Test @@ -498,14 +518,14 @@ public void construct_WhenComplexDependency_ThenInstanceIsResolved() InterfaceBasicComplexDependency result = testObject.construct(InterfaceBasicComplexDependency.class); // then - Assertions.assertNotNull(result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(result.getFirstObject()); - Assertions.assertNotNull(result.getSecondObject()); - Assertions.assertNotNull(result.getFirstObject().getObject()); - Assertions.assertNotNull(result.getSecondObject().getString()); - Assertions.assertEquals(string, result.getSecondObject().getString()); - Assertions.assertTrue(result instanceof ClassBasicComplexDependency); + Assertions.assertThat(result).isNotNull(); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject()).isNotNull(); + Assertions.assertThat(result.getFirstObject().getObject()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isNotNull(); + Assertions.assertThat(result.getSecondObject().getString()).isEqualTo(string); + Assertions.assertThat(result).isInstanceOf(ClassBasicComplexDependency.class); } // endregion @@ -518,11 +538,11 @@ public void construct_WhenAnnotatedInterface_ThenInstanceIsResolved() InterfaceRegister result1 = testObject.construct(InterfaceRegister.class); InterfaceRegister result2 = testObject.construct(InterfaceRegister.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertTrue(result1 instanceof ClassRegisterInterface); - Assertions.assertTrue(result2 instanceof ClassRegisterInterface); - Assertions.assertNotSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result1).isInstanceOf(ClassRegisterInterface.class); + Assertions.assertThat(result2).isInstanceOf(ClassRegisterInterface.class); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test @@ -532,11 +552,11 @@ public void construct_WhenAnnotatedAbstractClass_ThenInstanceIsResolved() ClassRegisterAbstract result1 = testObject.construct(ClassRegisterAbstract.class); ClassRegisterAbstract result2 = testObject.construct(ClassRegisterAbstract.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertTrue(result2 instanceof ClassRegisterConcrete); - Assertions.assertTrue(result1 instanceof ClassRegisterConcrete); - Assertions.assertNotSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isInstanceOf(ClassRegisterConcrete.class); + Assertions.assertThat(result1).isInstanceOf(ClassRegisterConcrete.class); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test @@ -546,11 +566,11 @@ public void construct_WhenAnnotatedConcreteClass_ThenInstanceIsResolved() ClassRegisterConcrete result1 = testObject.construct(ClassRegisterConcrete.class); ClassRegisterConcrete result2 = testObject.construct(ClassRegisterConcrete.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertTrue(result1 instanceof ClassRegisterDerivedFromRegister); - Assertions.assertTrue(result2 instanceof ClassRegisterDerivedFromRegister); - Assertions.assertNotSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result1).isInstanceOf(ClassRegisterDerivedFromRegister.class); + Assertions.assertThat(result2).isInstanceOf(ClassRegisterDerivedFromRegister.class); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test @@ -560,9 +580,9 @@ public void construct_WhenSelfAnnotatedConcreteClass_ThenInstanceIsResolved() ClassRegisterSelf result1 = testObject.construct(ClassRegisterSelf.class); ClassRegisterSelf result2 = testObject.construct(ClassRegisterSelf.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertNotSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test @@ -572,73 +592,79 @@ public void construct_WhenAnnotatedConcreteClassAsItself_ThenInstanceIsResolved( ClassRegisterSelfAsSubtype result1 = testObject.construct(ClassRegisterSelfAsSubtype.class); ClassRegisterSelfAsSubtype result2 = testObject.construct(ClassRegisterSelfAsSubtype.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertNotSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isNotSameAs(result1); } @Test public void construct_WhenSelfAnnotatedInterface_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.construct(InterfaceRegisterSelfIncorrect.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(InterfaceRegisterSelfIncorrect.class)); //then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void construct_WhenSelfAnnotatedAbstractClass_ThenAbstractTypeException() { // when - Executable executable = - () -> testObject.construct(ClassRegisterSelfAbstractIncorrect.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassRegisterSelfAbstractIncorrect.class)); //then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void construct_WhenAnnotatedAbstractClassAsItself_ThenAbstractTypeException() { // when - Executable executable = () -> testObject.construct(ClassRegisterAbstractIncorrect.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassRegisterAbstractIncorrect.class)); //then - Assertions.assertThrows(AbstractTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(AbstractTypeException.class); } @Test public void construct_WhenInterfaceAnnotatedClassNotImplementing_ThenNotDerivedTypeException() { // when - Executable executable = () -> testObject.construct(InterfaceRegisterIncorrect.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(InterfaceRegisterIncorrect.class)); //then - Assertions.assertThrows(NotDerivedTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NotDerivedTypeException.class); } @Test public void construct_WhenAnnotatedClassRegistersInterface_ThenNotDerivedTypeException() { // when - Executable executable = () -> testObject.construct(ClassRegisterInterfaceIncorrect.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassRegisterInterfaceIncorrect.class)); //then - Assertions.assertThrows(NotDerivedTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NotDerivedTypeException.class); } @Test public void construct_WhenAnnotatedClassRegistersNotDerivedClass_ThenNotDerivedTypeException() { // when - Executable executable = () -> testObject.construct(ClassRegisterIncorrectOtherClass.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassRegisterIncorrectOtherClass.class)); // then - Assertions.assertThrows(NotDerivedTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NotDerivedTypeException.class); } @Test public void construct_WhenAnnotatedClassRegistersAbstractConcreteSuperclass_ThenNotDerivedTypeException() { // when - Executable executable = () -> testObject.construct(ClassRegisterIncorrectSuperClass.class); + Throwable throwable = Assertions.catchThrowable( + () -> testObject.construct(ClassRegisterIncorrectSuperClass.class)); // then - Assertions.assertThrows(NotDerivedTypeException.class, executable); + Assertions.assertThat(throwable).isInstanceOf(NotDerivedTypeException.class); } @Test @@ -648,11 +674,11 @@ public void construct_WhenAnnotatedInterfaceSingleton_ThenSameInstances() InterfaceRegisterSingleton result1 = testObject.construct(InterfaceRegisterSingleton.class); InterfaceRegisterSingleton result2 = testObject.construct(InterfaceRegisterSingleton.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertTrue(result1 instanceof ClassRegisterSingletonBase); - Assertions.assertTrue(result2 instanceof ClassRegisterSingletonBase); - Assertions.assertSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result1).isInstanceOf(ClassRegisterSingletonBase.class); + Assertions.assertThat(result2).isInstanceOf(ClassRegisterSingletonBase.class); + Assertions.assertThat(result2).isSameAs(result1); } @Test @@ -662,11 +688,11 @@ public void construct_WhenAnnotatedConcreteClassSingleton_ThenSameInstances() ClassRegisterSingletonBase result1 = testObject.construct(ClassRegisterSingletonBase.class); ClassRegisterSingletonBase result2 = testObject.construct(ClassRegisterSingletonBase.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertTrue(result1 instanceof ClassRegisterSingletonDerived); - Assertions.assertTrue(result2 instanceof ClassRegisterSingletonDerived); - Assertions.assertSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result1).isInstanceOf(ClassRegisterSingletonDerived.class); + Assertions.assertThat(result2).isInstanceOf(ClassRegisterSingletonDerived.class); + Assertions.assertThat(result2).isSameAs(result1); } @Test @@ -676,9 +702,9 @@ public void construct_WhenSelfAnnotatedConcreteClassSingleton_ThenSameInstances( ClassRegisterSelfSingleton result1 = testObject.construct(ClassRegisterSelfSingleton.class); ClassRegisterSelfSingleton result2 = testObject.construct(ClassRegisterSelfSingleton.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isSameAs(result1); } @Test @@ -690,9 +716,9 @@ public void construct_WhenAnnotatedConcreteClassAsItselfSingleton_ThenSameInstan ClassRegisterSelfAsSubtypeSingleton result2 = testObject.construct(ClassRegisterSelfAsSubtypeSingleton.class); // then - Assertions.assertNotNull(result1); - Assertions.assertNotNull(result2); - Assertions.assertSame(result1, result2); + Assertions.assertThat(result1).isNotNull(); + Assertions.assertThat(result2).isNotNull(); + Assertions.assertThat(result2).isSameAs(result1); } // endregion @@ -711,11 +737,11 @@ public void inject_WhenMultipleDependencySetters_ThenInstanceIsResolved() // when InterfaceSetterMultiple result = testObject.inject(instance); // then - Assertions.assertSame(instance, result); - Assertions.assertNotNull(result.getBasicObject()); - Assertions.assertNotNull(result.getStringObject()); - Assertions.assertNotNull(result.getStringObject().getString()); - Assertions.assertEquals(string, result.getStringObject().getString()); + Assertions.assertThat(result).isSameAs(instance); + Assertions.assertThat(result.getBasicObject()).isNotNull(); + Assertions.assertThat(result.getStringObject()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isNotNull(); + Assertions.assertThat(result.getStringObject().getString()).isEqualTo(string); } // endregion }