Added some tests for Regular Light and for Switch
This commit is contained in:
parent
313e6ed88e
commit
5e7bd298de
2 changed files with 143 additions and 0 deletions
|
@ -0,0 +1,47 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RegularLight;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("A RegularLight")
|
||||||
|
public class RegularLightTests {
|
||||||
|
|
||||||
|
RegularLight regularLight;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void createRegularLight() {
|
||||||
|
this.regularLight = new RegularLight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("State when just created")
|
||||||
|
public void beginningState() {
|
||||||
|
assertFalse(regularLight.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Changing state to on after creating the light")
|
||||||
|
public void createAndSetOn() {
|
||||||
|
regularLight.setOn(true);
|
||||||
|
assertTrue(regularLight.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Change state of the light to off after creating it")
|
||||||
|
public void createAndSetOff() {
|
||||||
|
regularLight.setOn(false);
|
||||||
|
assertFalse(regularLight.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks whether a turned on light getting turned on is still in the on State")
|
||||||
|
public void setOn() {
|
||||||
|
regularLight.setOn(true);
|
||||||
|
regularLight.setOn(true);
|
||||||
|
assertTrue(regularLight.isOn());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@DisplayName("A switch")
|
||||||
|
public class SwitchTests {
|
||||||
|
|
||||||
|
Switch aSwitch;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void createNewSwitch() {
|
||||||
|
|
||||||
|
this.aSwitch = new Switch();
|
||||||
|
RegularLight regularLight = new RegularLight();
|
||||||
|
DimmableLight dimmableLight = new DimmableLight();
|
||||||
|
SmartPlug smartPlug = new SmartPlug();
|
||||||
|
this.aSwitch.getOutputs().add(regularLight);
|
||||||
|
this.aSwitch.getOutputs().add(dimmableLight);
|
||||||
|
this.aSwitch.getOutputs().add(smartPlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("check state when switch created")
|
||||||
|
public void createdSwitch() {
|
||||||
|
assertFalse(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Check toggle on a switch in its off state")
|
||||||
|
public void offToggle() {
|
||||||
|
aSwitch.toggle();
|
||||||
|
assertTrue(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks whether setting on a off switch works as intended")
|
||||||
|
public void offSetOn() {
|
||||||
|
aSwitch.setOn(true);
|
||||||
|
assertTrue(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks whether setting off a on switch works as intended")
|
||||||
|
public void onSetOff() {
|
||||||
|
aSwitch.toggle();
|
||||||
|
aSwitch.setOn(false);
|
||||||
|
assertFalse(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks that setting off an off switch results in a off state")
|
||||||
|
public void offSetOff() {
|
||||||
|
aSwitch.setOn(false);
|
||||||
|
assertFalse(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks that setting on an on switch results in a on state")
|
||||||
|
public void onSetOn() {
|
||||||
|
aSwitch.toggle();
|
||||||
|
aSwitch.setOn(true);
|
||||||
|
assertTrue(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks wheter toggling a on switch set its state to off")
|
||||||
|
public void onToggle() {
|
||||||
|
aSwitch.setOn(true);
|
||||||
|
aSwitch.toggle();
|
||||||
|
assertFalse(aSwitch.isOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks that toggling on sets all elements of the Set on as well")
|
||||||
|
public void toggleEffctOnSet() {
|
||||||
|
aSwitch.toggle();
|
||||||
|
for (final Switchable s : aSwitch.getOutputs()) {
|
||||||
|
assertTrue(s.isOn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Checks that toggling the switch off also sets all elements of its set off")
|
||||||
|
public void toggleOffEffectOnElementes() {
|
||||||
|
aSwitch.setOn(true);
|
||||||
|
aSwitch.toggle();
|
||||||
|
for (final Switchable s : aSwitch.getOutputs()) {
|
||||||
|
assertFalse(s.isOn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue