From 90e29a27345f55dfd7014b29c07791b0c8645f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?HARDEMAN=20S=C3=A9bastien?= Date: Wed, 18 Jan 2023 10:39:54 +0100 Subject: [PATCH] case correction --- .../CheckInterfaceUnitTest.java | 258 +++++++++--------- 1 file changed, 127 insertions(+), 131 deletions(-) diff --git a/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/checkinterface/CheckInterfaceUnitTest.java b/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/checkinterface/CheckInterfaceUnitTest.java index 3accef0869..ab607322d1 100644 --- a/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/checkinterface/CheckInterfaceUnitTest.java +++ b/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/checkinterface/CheckInterfaceUnitTest.java @@ -1,131 +1,127 @@ -package com.baeldung.checkinterface; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import org.apache.commons.lang3.ClassUtils; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.reflections.ReflectionUtils; -import org.reflections.Reflections; - -import com.baeldung.checkinterface.ChildClass2; -import com.baeldung.checkinterface.ChildInterface2; -import com.baeldung.checkinterface.MasterInterface; - -public class CheckInterfaceUnitTest { - - protected static Reflections reflections; - - @BeforeAll - public static void initializeReflectionsLibrary() { - - reflections = new Reflections("com.baeldung.checkInterface"); - } - - @Test - public void whenUsingReflectionGetInterfaces_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - List> interfaces = Arrays.asList(childClass2.getClass().getInterfaces()); - - assertTrue(interfaces.contains(ChildInterface2.class)); - } - - @Test - public void whenUsingReflectionGetInterfaces_thenParentInterfaceIsNotFound() { - - ChildClass2 childClass2 = new ChildClass2(); - List> interfaces = Arrays.asList(childClass2.getClass().getInterfaces()); - - assertFalse(interfaces.contains(MasterInterface.class)); - } - - @Test - public void whenUsingReflectionIsAssignableFrom_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(ChildInterface2.class.isAssignableFrom(childClass2.getClass())); - } - - @Test - public void whenUsingReflectionIsAssignableFrom_thenParentInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(MasterInterface.class.isAssignableFrom(childClass2.getClass())); - } - - @Test - public void whenUsingReflectionIsInstance_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(ChildInterface2.class.isInstance(childClass2)); - } - - @Test - public void whenUsingReflectionIsInstance_thenParentInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(MasterInterface.class.isInstance(childClass2)); - } - - @Test - public void whenUsingReflectionInstanceOf_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(childClass2 instanceof ChildInterface2); - } - - @Test - public void whenUsingReflectionInstanceOf_thenParentInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - - assertTrue(childClass2 instanceof MasterInterface); - } - - @Test - public void whenUsingCommons_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - List> interfaces = ClassUtils.getAllInterfaces(childClass2.getClass()); - - assertTrue(interfaces.contains(ChildInterface2.class)); - } - - @Test - public void whenUsingCommons_thenParentInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - List> interfaces = ClassUtils.getAllInterfaces(childClass2.getClass()); - - assertTrue(interfaces.contains(MasterInterface.class)); - } - - @Test - public void whenUsingReflections_thenDirectlyImplementedInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - Set> interfaces = reflections.get(ReflectionUtils.Interfaces.of(childClass2.getClass())); - - assertTrue(interfaces.contains(ChildInterface2.class)); - } - - @Test - public void whenUsingReflections_thenParentInterfaceIsFound() { - - ChildClass2 childClass2 = new ChildClass2(); - Set> interfaces = reflections.get(ReflectionUtils.Interfaces.of(childClass2.getClass())); - - assertTrue(interfaces.contains(MasterInterface.class)); - } -} +package com.baeldung.checkinterface; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang3.ClassUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.reflections.ReflectionUtils; +import org.reflections.Reflections; + +public class CheckInterfaceUnitTest { + + protected static Reflections reflections; + + @BeforeAll + public static void initializeReflectionsLibrary() { + + reflections = new Reflections("com.baeldung.checkinterface"); + } + + @Test + public void whenUsingReflectionGetInterfaces_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + List> interfaces = Arrays.asList(childClass2.getClass().getInterfaces()); + + assertTrue(interfaces.contains(ChildInterface2.class)); + } + + @Test + public void whenUsingReflectionGetInterfaces_thenParentInterfaceIsNotFound() { + + ChildClass2 childClass2 = new ChildClass2(); + List> interfaces = Arrays.asList(childClass2.getClass().getInterfaces()); + + assertFalse(interfaces.contains(MasterInterface.class)); + } + + @Test + public void whenUsingReflectionIsAssignableFrom_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(ChildInterface2.class.isAssignableFrom(childClass2.getClass())); + } + + @Test + public void whenUsingReflectionIsAssignableFrom_thenParentInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(MasterInterface.class.isAssignableFrom(childClass2.getClass())); + } + + @Test + public void whenUsingReflectionIsInstance_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(ChildInterface2.class.isInstance(childClass2)); + } + + @Test + public void whenUsingReflectionIsInstance_thenParentInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(MasterInterface.class.isInstance(childClass2)); + } + + @Test + public void whenUsingReflectionInstanceOf_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(childClass2 instanceof ChildInterface2); + } + + @Test + public void whenUsingReflectionInstanceOf_thenParentInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + + assertTrue(childClass2 instanceof MasterInterface); + } + + @Test + public void whenUsingCommons_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + List> interfaces = ClassUtils.getAllInterfaces(childClass2.getClass()); + + assertTrue(interfaces.contains(ChildInterface2.class)); + } + + @Test + public void whenUsingCommons_thenParentInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + List> interfaces = ClassUtils.getAllInterfaces(childClass2.getClass()); + + assertTrue(interfaces.contains(MasterInterface.class)); + } + + @Test + public void whenUsingReflections_thenDirectlyImplementedInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + Set> interfaces = reflections.get(ReflectionUtils.Interfaces.of(childClass2.getClass())); + + assertTrue(interfaces.contains(ChildInterface2.class)); + } + + @Test + public void whenUsingReflections_thenParentInterfaceIsFound() { + + ChildClass2 childClass2 = new ChildClass2(); + Set> interfaces = reflections.get(ReflectionUtils.Interfaces.of(childClass2.getClass())); + + assertTrue(interfaces.contains(MasterInterface.class)); + } +}