I have an abstract class called Animal ànd inside it I have an abstract method called multiply. How do I check if this method is abstract or not using JUnit 5?
public abstract class Animal {
private final int age;
private final int speed;
public Animal (int age,int speed) {
if(age > 0) {
this.age = age;
}
else {
throw new IllegalArgumentException("Age can't be less than 0");
}
if(speed > 0) {
this.speed = speed;
}
else {
throw new IllegalArgumentException("Speed can't be less than 0");
}
}
public static void main(String[] args) {
}
@Override
public boolean equals(Object anotherObject) {
if (this == anotherObject) {
return true;
}else {
return false;
}
}
public abstract Animal[] multiply(int n);
private boolean isFaster(Animal a) {
if(this.getSpeed() >a.getSpeed()) {
return true;
}else {
return false;
}
}
private boolean isOlder(Animal a) {
if(this.getAge() >a.getAge()) {
return true;
}
return false;
}
@Override
public String toString() {
return this.getClass()+ "is " + this.getAge() + " years old, is " +this.getSpeed() +" units fast.";
}
public final int getAge() {
return age;
}
public final int getSpeed() {
return speed;
}
}
I know how to get if the class is abstract by entering this
Class<Animal> clazz = Animal.class;
Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
how do I do the equivalent for an abstract method?
Aucun commentaire:
Enregistrer un commentaire