room and thermostat tests

This commit is contained in:
Jacob Salvi 2020-05-10 15:17:27 +02:00
parent 1d422ec420
commit 1b22534f40
2 changed files with 188 additions and 0 deletions

View file

@ -0,0 +1,81 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
import javax.swing.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Room test")
public class RoomTests {
private Room room;
@BeforeEach
private void createRoom() {
room = new Room();
}
@Test
@DisplayName("test id")
public void testId() {
room.setId(42l);
assertEquals(42l, room.getId());
}
@Test
@DisplayName("test userId")
public void testUserId() {
room.setUserId(42l);
assertEquals(42l, room.getUserId());
}
@Test
@DisplayName("test name")
public void testName() {
room.setName("alpaca");
assertEquals("alpaca", room.getName());
}
@Test
@DisplayName("test image")
public void testImage() {
room.setImage("realFakeImage.png");
assertEquals("realFakeImage.png", room.getImage());
}
@Test
@DisplayName("test toString()")
public void testToString() {
room.setId(1l);
room.setName("alpaca");
assertEquals("Room{id=1, name='alpaca'}", room.toString());
}
@Test
@DisplayName("test devices")
public void testDevices() {
room.getDevices().add(new DimmableLight());
assertEquals(1, room.getDevices().size());
}
@Test
@DisplayName("test user")
public void testUser() {
User user = new User();
user.setId(34l);
room.setUser(user);
assertEquals(34l, room.getUser().getId());
}
@Test
@DisplayName("test Icon")
public void testIcon() {
// ImageIcon image = new ImageIcon("file","description");
room.setIcon(null);
assertEquals(null, room.getIcon());
}
}

View file

@ -0,0 +1,107 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Thermostat tests")
public class ThermostatTests {
private Thermostat thermostat;
@BeforeEach
public void createThermostat() {
this.thermostat = new Thermostat();
}
@Test
@DisplayName("test isOn()")
public void inOnTest() {
assertFalse(thermostat.isOn());
}
@Test
@DisplayName("test setOn(true) ")
public void setOnTestTrue() {
thermostat.setOn(true);
assertTrue(thermostat.isOn());
}
@Test
@DisplayName("test setOn(false) ")
public void setOnTestFalse() {
thermostat.setOn(false);
assertFalse(thermostat.isOn());
}
@Test
@DisplayName("test compute measured is null")
public void computeMeasureNull() {
this.thermostat.setMeasuredTemperature(null);
thermostat.setOn(true);
assertEquals(Thermostat.Mode.IDLE, thermostat.getMode());
}
@Test
@DisplayName("test compute |measured-target|<0.25")
public void computeMeasureIdle() {
this.thermostat.setMeasuredTemperature(new BigDecimal(1));
this.thermostat.setTargetTemperature(new BigDecimal(0.9));
thermostat.setOn(true);
assertEquals(Thermostat.Mode.IDLE, thermostat.getMode());
}
@Test
@DisplayName("test compute heating")
public void computeMeasureHeating() {
this.thermostat.setMeasuredTemperature(new BigDecimal(1));
this.thermostat.setTargetTemperature(new BigDecimal(2));
thermostat.setOn(true);
assertEquals(Thermostat.Mode.HEATING, thermostat.getMode());
}
@Test
@DisplayName("test compute cooling")
public void computeMeasureCooling() {
this.thermostat.setMeasuredTemperature(new BigDecimal(10));
this.thermostat.setTargetTemperature(new BigDecimal(5));
thermostat.setOn(true);
assertEquals(Thermostat.Mode.COOLING, thermostat.getMode());
}
@Test
@DisplayName("test external sensor")
public void testExternalSensor() {
thermostat.setUseExternalSensors(true);
assertTrue(thermostat.isUseExternalSensors());
}
@Test
@DisplayName("test internal sensor temperature")
public void testInternalSensorTemperature() {
thermostat.setInternalSensorTemperature(new BigDecimal(42));
assertEquals(new BigDecimal(42), thermostat.getInternalSensorTemperature());
}
@Test
@DisplayName("test triggerState")
public void testTriggerState() {
assertFalse(thermostat.readTriggerState());
}
// for obvious reasons I am not gonna check all the possible combinations of toString()
@Test
@DisplayName("test to string")
public void testToString() {
thermostat.setMeasuredTemperature(new BigDecimal(1));
thermostat.setTargetTemperature(new BigDecimal(1));
assertEquals(
"Thermostat{targetTemperature=1, internalSensorTemperature=17.0, mode=OFF, measuredTemperature=1, useExternalSensors=false}",
thermostat.toString());
}
}