From fb3c07cf89cfe9fbf5e4bcdaa968c3d49f8ae20c Mon Sep 17 00:00:00 2001 From: Kai Sellmann <2210892@stud.hs-mannheim.de> Date: Mon, 29 May 2023 09:48:07 +0200 Subject: [PATCH] ZooSimulationsTest --- .../polymorphie/ZooSimulationTest.java | 31 +++++++++++++++++++ .../pr2/vererbung/polymorphie/ZooTier.java | 8 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 sources/src/main/java/pr2/vererbung/polymorphie/ZooSimulationTest.java diff --git a/sources/src/main/java/pr2/vererbung/polymorphie/ZooSimulationTest.java b/sources/src/main/java/pr2/vererbung/polymorphie/ZooSimulationTest.java new file mode 100644 index 0000000..787ac85 --- /dev/null +++ b/sources/src/main/java/pr2/vererbung/polymorphie/ZooSimulationTest.java @@ -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."); + + + } +} diff --git a/sources/src/main/java/pr2/vererbung/polymorphie/ZooTier.java b/sources/src/main/java/pr2/vererbung/polymorphie/ZooTier.java index 4ea6c41..327d166 100644 --- a/sources/src/main/java/pr2/vererbung/polymorphie/ZooTier.java +++ b/sources/src/main/java/pr2/vererbung/polymorphie/ZooTier.java @@ -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() */