From 3a856779f3e33daaaaa75b72c9287a001d937a6d Mon Sep 17 00:00:00 2001 From: Philipp3107 Date: Thu, 8 Dec 2022 23:34:47 +0100 Subject: [PATCH] Updated domain. Further explanation in README --- domain/R2D2.java | 20 +++++++++++++++++++- domain/R2D2Test.java | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 domain/R2D2Test.java diff --git a/domain/R2D2.java b/domain/R2D2.java index 410667c..322f217 100644 --- a/domain/R2D2.java +++ b/domain/R2D2.java @@ -5,30 +5,48 @@ public class R2D2 implements Robot{ private String name; private boolean power; + /** + * Constructor + * @param id> int + * @param name> String + */ public R2D2(int id, String name){ this.id = id; this.name = name; power = false; } + + /** + * @see domain.RobotControl + */ @Override public int getId() { return id; } + /** + * @see domain.RobotControl + */ @Override public String getName() { return name; } + /** + * @see domain.RobotControl + */ @Override public void triggerPowerSwitch() { - if(power = false){ + if(power == false){ power = true; }else{ power = false; } } + /** + * @see domain.RobotControl + */ @Override public boolean isPowerOn() { return power; diff --git a/domain/R2D2Test.java b/domain/R2D2Test.java new file mode 100644 index 0000000..d544f21 --- /dev/null +++ b/domain/R2D2Test.java @@ -0,0 +1,45 @@ +package domain; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + + +class R2D2Test { + + R2D2 Herbert; + int id = 0; + String name = "Herbert"; + @BeforeEach + void setup(){ + Herbert = new R2D2(id, name); + } + + + //Tests for basic functions + @Test + void getId() { + assertEquals(0, Herbert.getId()); + } + + @Test + void getName() { + assertEquals(name, Herbert.getName()); + } + + @Test + void triggerPowerSwitch() { + Herbert.triggerPowerSwitch(); + assertTrue(Herbert.isPowerOn()); + } + + @Test + void isPowerOn() { + assertFalse(Herbert.isPowerOn()); + Herbert.triggerPowerSwitch(); + assertTrue(Herbert.isPowerOn()); + } + + +} \ No newline at end of file