From 65b1cca3077457fda738b88e3c1595bdcc065d63 Mon Sep 17 00:00:00 2001 From: schmolli <martin.schmollinger@reutlingen-university.de> Date: Mon, 4 May 2020 18:11:10 +0200 Subject: [PATCH] Extension of test class for lecture --- src/main/java/io/fp/campus/Faculty.java | 6 +++++- src/test/java/io/fp/campus/FacultyTest.java | 23 +++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/fp/campus/Faculty.java b/src/main/java/io/fp/campus/Faculty.java index feb969c..a7436b0 100644 --- a/src/main/java/io/fp/campus/Faculty.java +++ b/src/main/java/io/fp/campus/Faculty.java @@ -21,8 +21,12 @@ public class Faculty { } public void addProfessor(Professor professor) { - if (!profs.contains(professor)) + if (!profs.contains(professor)) { profs.add(professor); + } + else { + throw new RuntimeException(); + } } public void addAssistent(Assistent assistent) { diff --git a/src/test/java/io/fp/campus/FacultyTest.java b/src/test/java/io/fp/campus/FacultyTest.java index c0c6649..1abc659 100644 --- a/src/test/java/io/fp/campus/FacultyTest.java +++ b/src/test/java/io/fp/campus/FacultyTest.java @@ -1,10 +1,11 @@ package io.fp.campus; import java.util.ArrayList; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class FacultyTest { @@ -13,21 +14,16 @@ public class FacultyTest { @BeforeEach void setUp() { hogwarts = new Faculty("Hogwarts"); - Professor dumbledore = new Professor("Dumbledore", 77, "BPM", hogwarts); - dumbledore.setTalking(false); - + Professor dumbledore = new Professor("Dumbledore", 77, "Dragons", hogwarts); + Assistent hagrid = new Assistent("Hagrid", 26, hogwarts); hagrid.setBoss(dumbledore); - Assistent dobby = new Assistent("Dobby", 130, hogwarts); dobby.setBoss(dumbledore); - - Assistent pince = new Assistent("Madam Pince", 40, hogwarts); - + hogwarts.addProfessor(dumbledore); hogwarts.addAssistent(hagrid); hogwarts.addAssistent(dobby); - hogwarts.addAssistent(pince); } @Test void testGetProfsWithAssis() { @@ -35,4 +31,13 @@ public class FacultyTest { ArrayList<Professor> profsWithAssis = hogwarts.getProfsWithAssis(); assertEquals(profs, profsWithAssis); } + + @Test + void testAddProfessor() { + ArrayList<Professor> profs = hogwarts.getProfs(); + Professor prof1 = profs.get(0); + assertThrows(RuntimeException.class, + ()->{hogwarts.addProfessor(prof1);} + ); + } } \ No newline at end of file -- GitLab