From cffeeca9f845357daae6670a57b981bde124bf06 Mon Sep 17 00:00:00 2001 From: Jacob Salvi Date: Mon, 25 May 2020 16:47:06 +0200 Subject: [PATCH] added DevicePopulationServiceTests --- .../service/DevicePopulationServiceTests.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePopulationServiceTests.java diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePopulationServiceTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePopulationServiceTests.java new file mode 100644 index 0000000..693d11b --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/DevicePopulationServiceTests.java @@ -0,0 +1,42 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.service; + +import static org.mockito.Mockito.*; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import java.math.BigDecimal; +import java.util.ArrayList; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.test.context.support.WithMockUser; + +@ExtendWith(MockitoExtension.class) +@WithMockUser(username = "user") +@DisplayName("DevicePopulationService test") +public class DevicePopulationServiceTests { + @InjectMocks private DevicePopulationService service; + + @Mock private ThermostatPopulationService populationService; + + private void helper(Thermostat t) { + t.setMeasuredTemperature(new BigDecimal(1)); + } + + @Test + public void testPopulateComputedFields() { + Curtains curtains = new Curtains(); + RegularLight light = new RegularLight(); + Thermostat t1 = new Thermostat(); + RegularLight light2 = new RegularLight(); + ArrayList list = new ArrayList<>(); + list.add(curtains); + list.add(light); + list.add(t1); + list.add(light2); + doNothing().when(populationService).populateMeasuredTemperature(t1); + service.populateComputedFields(list); + } +}