Partial tests on DeviceService
This commit is contained in:
parent
0ce873dc52
commit
319206334e
1 changed files with 23 additions and 2 deletions
|
@ -1,11 +1,11 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.service.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -115,4 +115,25 @@ public class DeviceServiceTests {
|
||||||
|
|
||||||
assertThat(passed[0]).isTrue();
|
assertThat(passed[0]).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveAsGuest() throws NotFoundException {
|
||||||
|
Thermostat t = new Thermostat();
|
||||||
|
|
||||||
|
User u = new User();
|
||||||
|
u.setUsername("user");
|
||||||
|
|
||||||
|
User host = new User();
|
||||||
|
host.setId(1L);
|
||||||
|
host.setUsername("host");
|
||||||
|
host.getGuests().add(u);
|
||||||
|
u.getHosts().add(host);
|
||||||
|
|
||||||
|
when(userRepository.findByUsername("user")).thenReturn(u);
|
||||||
|
when(userRepository.findById(1L)).thenReturn(Optional.of(host));
|
||||||
|
doNothing().when(devicePropagationService).renameIfDuplicate(t, "host");
|
||||||
|
when(deviceRepository.save(t)).thenAnswer(ta -> ta.getArguments()[0]);
|
||||||
|
|
||||||
|
assertThat(deviceService.saveAsGuest(t, "user", 1L)).isEqualTo(t);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue