a couple of tests

This commit is contained in:
Jacob Salvi 2020-05-13 09:42:36 +02:00
parent c614f96b31
commit b4bf15583a
11 changed files with 516 additions and 2 deletions

View file

@ -3,6 +3,7 @@ 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.Icon;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Room;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
import javax.swing.*;
@ -75,7 +76,7 @@ public class RoomTests {
@DisplayName("test Icon")
public void testIcon() {
// ImageIcon image = new ImageIcon("file","description");
room.setIcon(null);
assertEquals(null, room.getIcon());
room.setIcon(Icon.FEMALE);
assertEquals("female", room.getIcon().toString());
}
}

View file

@ -0,0 +1,53 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.*;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SceneSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Icon;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("SceneSaveRequest tests")
public class SceneSaveRequestTests {
private SceneSaveRequest scene;
@BeforeEach
private void createSceneSaveRequest() {
scene = new SceneSaveRequest();
}
@Test
@DisplayName("guestAccessEnable")
public void testGuestAccess() {
assertFalse(scene.isGuestAccessEnabled());
}
@Test
@DisplayName("set guestAccess")
public void testSetGuestAccess() {
scene.setGuestAccessEnabled(true);
assertTrue(scene.isGuestAccessEnabled());
}
@Test
@DisplayName("test getId")
public void testGetId() {
assertEquals(0l, scene.getId());
}
@Test
@DisplayName("test getName")
public void testGetName() {
scene.setName("Roberto");
assertEquals("Roberto", scene.getName());
}
@Test
@DisplayName("test getIcon")
public void testGetIcon() {
scene.setIcon(Icon.FEMALE);
assertEquals("female", scene.getIcon().toString());
}
}

View file

@ -0,0 +1,71 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SensorSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor;
import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("SensorSaveRequest tests")
public class SensorSaveRequestTests {
private SensorSaveRequest sensor;
@BeforeEach
public void createSensorSaveRequest() {
this.sensor = new SensorSaveRequest();
}
@Test
@DisplayName("test setRoomId")
public void testSetRoomId() {
sensor.setRoomId(42l);
assertEquals(42l, sensor.getRoomId());
}
@Test
@DisplayName("test setName")
public void testSetName() {
sensor.setName("Giovanni");
assertEquals("Giovanni", sensor.getName());
}
@Test
@DisplayName("test setValue")
public void testSetValue() {
sensor.setValue(new BigDecimal(42));
assertEquals(new BigDecimal(42), sensor.getValue());
}
@Test
@DisplayName("test set to TEMPERATURE")
public void testSetToTemperature() {
sensor.setSensor(Sensor.SensorType.TEMPERATURE);
assertEquals(Sensor.SensorType.TEMPERATURE, sensor.getSensor());
}
@Test
@DisplayName("test set to HUMIDITY")
public void testSetToHumidity() {
sensor.setSensor(Sensor.SensorType.HUMIDITY);
assertEquals(Sensor.SensorType.HUMIDITY, sensor.getSensor());
}
@Test
@DisplayName("test set to LIGHT")
public void testSetToLight() {
sensor.setSensor(Sensor.SensorType.LIGHT);
assertEquals(Sensor.SensorType.LIGHT, sensor.getSensor());
}
@Test
@DisplayName("test SensorType")
public void testSetSensorType() {
assertEquals("TEMPERATURE", Sensor.SensorType.TEMPERATURE.name());
assertEquals("HUMIDITY", Sensor.SensorType.HUMIDITY.name());
assertEquals("LIGHT", Sensor.SensorType.LIGHT.name());
}
}

View file

@ -0,0 +1,46 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.SwitchOperationRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("switchOperationRequest tests")
public class SwitchOperationRequestTests {
private SwitchOperationRequest request;
@BeforeEach
private void createRequest() {
this.request = new SwitchOperationRequest();
}
@Test
@DisplayName("test setId")
public void testSetId() {
request.setId(42l);
assertEquals(42l, request.getId());
}
@Test
@DisplayName("test setType")
public void testSetTypeOFF() {
request.setType(SwitchOperationRequest.OperationType.OFF);
assertEquals(SwitchOperationRequest.OperationType.OFF, request.getType());
}
@Test
@DisplayName("test setType")
public void testSetTypeON() {
request.setType(SwitchOperationRequest.OperationType.ON);
assertEquals(SwitchOperationRequest.OperationType.ON, request.getType());
}
@Test
@DisplayName("test setType")
public void testSetTypeTOGGLE() {
request.setType(SwitchOperationRequest.OperationType.TOGGLE);
assertEquals(SwitchOperationRequest.OperationType.TOGGLE, request.getType());
}
}

View file

@ -0,0 +1,62 @@
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.dto.SwitchableSaveRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("SwitchableSaveRequest tests")
public class SwitchableSaveRequestTests {
private SwitchableSaveRequest saveRequest;
@BeforeEach
private void createSaveRequest() {
this.saveRequest = new SwitchableSaveRequest();
}
@Test
@DisplayName("test setRoomId")
public void testSetRoomId() {
saveRequest.setRoomId(42l);
assertEquals(42l, saveRequest.getRoomId());
}
@Test
@DisplayName("test setName")
public void testSetName() {
saveRequest.setName("Giovanni");
assertEquals("Giovanni", saveRequest.getName());
}
@Test
@DisplayName("test isOn()")
public void inOnTest() {
assertFalse(saveRequest.isOn());
}
@Test
@DisplayName("test setOn(true) ")
public void setOnTestTrue() {
saveRequest.setOn(true);
assertTrue(saveRequest.isOn());
}
@Test
@DisplayName("test setOn(false) ")
public void setOnTestFalse() {
saveRequest.setOn(false);
assertFalse(saveRequest.isOn());
}
@Test
@DisplayName("test setId")
public void testSetId() {
saveRequest.setId(300771l);
assertEquals(300771l, saveRequest.getId());
}
}

View file

@ -0,0 +1,46 @@
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.dto.SwitchableStateSaveRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("switchableStateSaveRequest tests")
public class SwitchableStateSaveRequestTests {
private SwitchableStateSaveRequest saveRequest;
@BeforeEach
public void createSwitchableStateSaveRequest() {
this.saveRequest = new SwitchableStateSaveRequest();
}
@Test
@DisplayName("test isOn()")
public void inOnTest() {
assertFalse(saveRequest.isOn());
}
@Test
@DisplayName("test setOn(true) ")
public void setOnTestTrue() {
saveRequest.setOn(true);
assertTrue(saveRequest.isOn());
}
@Test
@DisplayName("test setOn(false) ")
public void setOnTestFalse() {
saveRequest.setOn(false);
assertFalse(saveRequest.isOn());
}
@Test
@DisplayName("test setId")
public void testSetId() {
assertEquals(null, saveRequest.getId());
}
}

View file

@ -0,0 +1,62 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ThermostatConditionSaveRequest;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("ThermostatConditionSaveRequest tests")
public class ThermostatConditionSaveRequestTests {
private ThermostatConditionSaveRequest saveRequest;
@BeforeEach
private void createSaveRequest() {
this.saveRequest = new ThermostatConditionSaveRequest();
}
@Test
@DisplayName("test setDeviceId")
public void testSetDeviceId() {
this.saveRequest.setDeviceId(42l);
assertEquals(42l, saveRequest.getDeviceId());
}
@Test
@DisplayName("test setAutomationId")
public void testSetAutomationId() {
this.saveRequest.setAutomationId(42l);
assertEquals(42l, saveRequest.getAutomationId());
}
@Test
@DisplayName("test setOperator")
public void testSetOperatorEqual() {
saveRequest.setOperator(ThermostatCondition.Operator.EQUAL);
assertEquals(ThermostatCondition.Operator.EQUAL, saveRequest.getOperator());
}
@Test
@DisplayName("test setOperator")
public void testSetOperatorNotEqual() {
saveRequest.setOperator(ThermostatCondition.Operator.NOTEQUAL);
assertEquals(ThermostatCondition.Operator.NOTEQUAL, saveRequest.getOperator());
}
@Test
@DisplayName("test setMode")
public void testSetMode() {
saveRequest.setMode(Thermostat.Mode.HEATING);
assertEquals(Thermostat.Mode.HEATING, saveRequest.getMode());
}
@Test
@DisplayName("test getId")
public void testGetId() {
assertEquals(0l, saveRequest.getId());
}
}

View file

@ -0,0 +1,82 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.ThermostatSaveRequest;
import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("ThermostatSaveRequest tests")
public class ThermostatSaveRequestTests {
private ThermostatSaveRequest saveRequest;
@BeforeEach
private void createSaveRequest() {
saveRequest = new ThermostatSaveRequest();
}
@Test
@DisplayName("test setRoomId")
public void testSetRoomId() {
saveRequest.setRoomId(42l);
assertEquals(42l, saveRequest.getRoomId());
}
@Test
@DisplayName("test setName")
public void testSetName() {
saveRequest.setName("Giovanni");
assertEquals("Giovanni", saveRequest.getName());
}
@Test
@DisplayName("test isOn()")
public void inOnTest() {
assertFalse(saveRequest.isTurnOn());
}
@Test
@DisplayName("test setOn(true) ")
public void setOnTestTrue() {
saveRequest.setTurnOn(true);
assertTrue(saveRequest.isTurnOn());
}
@Test
@DisplayName("test setOn(false) ")
public void setOnTestFalse() {
saveRequest.setTurnOn(false);
assertFalse(saveRequest.isTurnOn());
}
@Test
@DisplayName("test setId")
public void testSetId() {
saveRequest.setId(17l);
assertEquals(17l, saveRequest.getId());
}
@Test
@DisplayName("test setExternalSensor true")
public void testExternalSensorTrue() {
saveRequest.setUseExternalSensors(true);
assertTrue(saveRequest.isUseExternalSensors());
}
@Test
@DisplayName("test setExternalSensor false")
public void testExternalSensorFalse() {
saveRequest.setUseExternalSensors(false);
assertFalse(saveRequest.isUseExternalSensors());
}
@Test
@DisplayName("test targetTemperature")
public void testTargetTemperature() {
saveRequest.setTargetTemperature(new BigDecimal(23));
assertEquals(new BigDecimal(23), saveRequest.getTargetTemperature());
}
}

View file

@ -0,0 +1,46 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserRegistrationRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("userRegistrationRequest tests")
public class UserRegistrationRequestTests {
private UserRegistrationRequest request;
@BeforeEach
private void createRequest() {
request = new UserRegistrationRequest();
}
@Test
@DisplayName("test setName")
public void testSetName() {
request.setName("Tizio Sempronio");
assertEquals("Tizio Sempronio", request.getName());
}
@Test
@DisplayName("test setUserName")
public void testUserName() {
request.setUsername("xXDarkAngelCraftXx");
assertEquals("xXDarkAngelCraftXx", request.getUsername());
}
@Test
@DisplayName("test setPassword")
public void testPassword() {
request.setPassword("password123");
assertEquals("password123", request.getPassword());
}
@Test
@DisplayName("test setEmail")
public void testEmail() {
request.setEmail("fakemail@service.ussr");
assertEquals("fakemail@service.ussr", request.getEmail());
}
}

View file

@ -0,0 +1,42 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserResponse;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("test UserResponse")
public class UserResponseTests {
private UserResponse response;
private User user;
@BeforeEach
private void createUser() {
user = new User();
user.setName("John RealName");
user.setId(29l);
user.setUsername("pseudonym");
response = response.fromUser(user);
}
@Test
@DisplayName("test getId")
public void testGetId() {
assertEquals(29l, response.getId());
}
@Test
@DisplayName("test getUsername")
public void testGetUsername() {
assertEquals("pseudonym", response.getUsername());
}
@Test
@DisplayName("test getName")
public void testGetaName() {
assertEquals("John RealName", response.getName());
}
}

View file

@ -0,0 +1,3 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
public class UserUpdateRequestTests {}