Merge branch 'tests' into 'dev'

Tests

See merge request sa4-2020/the-sanmarinoes/backend!186
This commit is contained in:
Claudio Maggioni 2020-05-25 11:57:16 +02:00
commit b49839cbdb
2 changed files with 17 additions and 0 deletions

View file

@ -14,6 +14,7 @@ public class SwitchableStateTests {
@BeforeEach
public void createSwitchableState() {
switchableState = new SwitchableState();
switchableState.setDevice(new RegularLight());
}
@Test
@ -22,5 +23,10 @@ public class SwitchableStateTests {
switchableState.setOn(true);
assertTrue(switchableState.isOn());
switchableState.apply();
assertTrue(((Switchable) switchableState.getDevice()).isOn());
assertTrue(switchableState.copy().isOn());
}
}

View file

@ -10,6 +10,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -63,4 +64,14 @@ public class ThermostatServiceTests {
when(thermostatRepository.findAllByUsername("user")).thenReturn(List.of(t));
assertThat(thermostatService.findAll("user")).containsExactly(t);
}
@Test
public void testFindById() {
final Thermostat t = new Thermostat();
when(thermostatRepository.findByIdAndUsername(2L, "user")).thenReturn(Optional.empty());
when(thermostatRepository.findByIdAndUsername(1L, "user")).thenReturn(Optional.of(t));
doNothing().when(thermostatPopulationService).populateMeasuredTemperature(t);
assertThat(thermostatService.findById(2L, "user")).isEmpty();
assertThat(thermostatService.findById(1L, "user")).isNotEmpty();
}
}