Merge pull request #10458 from sk1418/BAEL-4709_isAbstract

improvement
This commit is contained in:
Eric Martin 2021-02-05 16:53:11 -06:00 committed by GitHub
commit 30e84898fd
2 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,4 @@
package com.baeldung.reflection.check.abstractclass;
public interface InterfaceExample {
}

View File

@ -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<AbstractExample> clazz = AbstractExample.class;
Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
}
@Test
void givenInterface_whenCheckModifierIsAbstract_thenTrue() {
Class<InterfaceExample> clazz = InterfaceExample.class;
Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
}
@Test
void givenAbstractClass_whenCheckIsAbstractClass_thenTrue() {
Class<AbstractExample> clazz = AbstractExample.class;
int mod = clazz.getModifiers();
Assertions.assertTrue(Modifier.isAbstract(mod) && !Modifier.isInterface(mod));
}
@Test
void givenConcreteClass_whenCheckIsAbstractClass_thenFalse() {
Class<Date> clazz = Date.class;
int mod = clazz.getModifiers();
Assertions.assertFalse(Modifier.isAbstract(mod) && !Modifier.isInterface(mod));
}
}