From f5bb8ab648a19a0214e88858e00b2bef27943f75 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Sun, 31 Jan 2021 16:40:50 +0100 Subject: [PATCH] improvement --- .../check/abstractclass/InterfaceExample.java | 4 +++ .../AbstractExampleUnitTest.java | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java new file mode 100644 index 0000000000..d226611084 --- /dev/null +++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java @@ -0,0 +1,4 @@ +package com.baeldung.reflection.check.abstractclass; + +public interface InterfaceExample { +} diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java index cb5d927c23..d9a955ca6d 100644 --- a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java +++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java @@ -1,16 +1,36 @@ package com.baeldung.reflection.check.abstractclass; -import java.lang.reflect.Modifier; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.lang.reflect.Modifier; +import java.util.Date; + class AbstractExampleUnitTest { @Test - void givenAbstractClass_whenCheckModifierIsAbstract_thenTrue() throws Exception { + void givenAbstractClass_whenCheckModifierIsAbstract_thenTrue() { Class clazz = AbstractExample.class; Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers())); } + @Test + void givenInterface_whenCheckModifierIsAbstract_thenTrue() { + Class clazz = InterfaceExample.class; + Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers())); + } + + @Test + void givenAbstractClass_whenCheckIsAbstractClass_thenTrue() { + Class clazz = AbstractExample.class; + int mod = clazz.getModifiers(); + Assertions.assertTrue(Modifier.isAbstract(mod) && !Modifier.isInterface(mod)); + } + + @Test + void givenConcreteClass_whenCheckIsAbstractClass_thenFalse() { + Class clazz = Date.class; + int mod = clazz.getModifiers(); + Assertions.assertFalse(Modifier.isAbstract(mod) && !Modifier.isInterface(mod)); + } }