Merge branch 'tests' into 'dev'
Tests See merge request sa4-2020/the-sanmarinoes/backend!186
This commit is contained in:
commit
b49839cbdb
2 changed files with 17 additions and 0 deletions
|
@ -14,6 +14,7 @@ public class SwitchableStateTests {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void createSwitchableState() {
|
public void createSwitchableState() {
|
||||||
switchableState = new SwitchableState();
|
switchableState = new SwitchableState();
|
||||||
|
switchableState.setDevice(new RegularLight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,5 +23,10 @@ public class SwitchableStateTests {
|
||||||
switchableState.setOn(true);
|
switchableState.setOn(true);
|
||||||
|
|
||||||
assertTrue(switchableState.isOn());
|
assertTrue(switchableState.isOn());
|
||||||
|
|
||||||
|
switchableState.apply();
|
||||||
|
assertTrue(((Switchable) switchableState.getDevice()).isOn());
|
||||||
|
|
||||||
|
assertTrue(switchableState.copy().isOn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
@ -63,4 +64,14 @@ public class ThermostatServiceTests {
|
||||||
when(thermostatRepository.findAllByUsername("user")).thenReturn(List.of(t));
|
when(thermostatRepository.findAllByUsername("user")).thenReturn(List.of(t));
|
||||||
assertThat(thermostatService.findAll("user")).containsExactly(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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue