ZooSimulationsTest
parent
8858366161
commit
fb3c07cf89
|
@ -0,0 +1,31 @@
|
|||
package pr2.vererbung.polymorphie;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ZooSimulationTest {
|
||||
|
||||
/* Erster Test Tiere erzeugen und die richtigen Instanzen abfragen
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
void tiereErzeugenUndInstanzenAbfragen() {
|
||||
assertTrue(new Affe(" ") instanceof ZooTier,
|
||||
"Der Affe hat nicht von" + "ZooTier geerbt.");
|
||||
assertEquals("Charlie", new Affe("Charlie").getName());
|
||||
assertEquals("Hauer", new Gorilla("Hauer").getName());
|
||||
|
||||
assertTrue(new Gorilla("Hauer") instanceof Gorilla);
|
||||
assertTrue(new Gorilla("Hauer") instanceof ZooTier);
|
||||
|
||||
ZooTier albert = new Gorilla("Albert");
|
||||
assertTrue(albert.hunger(), "Hat noch Hunger.");
|
||||
albert.fuettern();
|
||||
assertTrue(!albert.hunger(), "Hat keinen Hunger mehr.");
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -25,14 +25,18 @@ public class ZooTier {
|
|||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* Gibt dem Tier futter.
|
||||
*/
|
||||
public void fuettern() {
|
||||
hungrig = false;
|
||||
}
|
||||
|
||||
public boolean hunger() {
|
||||
return hungrig;
|
||||
}
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue