Merge branch 'tests' into 'dev'

Tests on exception classes

See merge request sa4-2020/the-sanmarinoes/backend!144
This commit is contained in:
Claudio Maggioni 2020-05-17 13:30:01 +02:00
commit 590e675811
2 changed files with 74 additions and 39 deletions

View file

@ -1,13 +1,12 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.dto; package ch.usi.inf.sa4.sanmarinoes.smarthut.dto;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat.Mode;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatCondition.Operator;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.Data;
@Data
public class ThermostatConditionSaveRequest { public class ThermostatConditionSaveRequest {
@NotNull private long id; @NotNull private long id;
@NotNull private Long deviceId; @NotNull private Long deviceId;
@ -17,40 +16,4 @@ public class ThermostatConditionSaveRequest {
@NotNull private ThermostatCondition.Operator operator; @NotNull private ThermostatCondition.Operator operator;
@NotNull private Thermostat.Mode mode; @NotNull private Thermostat.Mode mode;
public long getId() {
return id;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Long getAutomationId() {
return automationId;
}
public void setAutomationId(Long automationId) {
this.automationId = automationId;
}
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
}
} }

View file

@ -0,0 +1,72 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut;
import static org.junit.jupiter.api.Assertions.assertEquals;
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Exception tests")
public class ExceptionTests {
@Test
public void testBadData() {
try {
throw new BadDataException("message");
} catch (BadDataException e) {
assertEquals(e.getMessage(), "message");
}
}
@Test
public void testDuplicateRegistration() {
try {
throw new DuplicateRegistrationException();
} catch (DuplicateRegistrationException e) {
assertEquals(e.getMessage(), "Email or username already belonging to another user");
}
}
@Test
public void testDuplicateState() {
try {
throw new DuplicateStateException();
} catch (DuplicateStateException e) {
assertEquals(
e.getMessage(),
"Cannot create state since it has already been created for this scene and this device");
}
}
@Test
public void testEmailTokenNotFound() {
try {
throw new EmailTokenNotFoundException();
} catch (EmailTokenNotFoundException e) {
assertEquals(e.getMessage(), "Email verification token not found in DB");
}
}
@Test
public void testNotFound() {
try {
throw new NotFoundException();
} catch (NotFoundException e) {
assertEquals(e.getMessage(), "Not found");
}
try {
throw new NotFoundException("message");
} catch (NotFoundException e) {
assertEquals(e.getMessage(), "message not found");
}
}
@Test
public void testUserNotFound() {
try {
throw new UserNotFoundException();
} catch (UserNotFoundException e) {
assertEquals(e.getMessage(), "No user found with given email");
}
}
}