It wasn't, but now it is
This commit is contained in:
parent
5c2ee4c55f
commit
6abedac3cc
1 changed files with 13 additions and 10 deletions
|
@ -8,6 +8,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.EagerUserRepository;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
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;
|
||||||
|
@ -35,8 +36,6 @@ public class GuestControllerTests {
|
||||||
@DisplayName("Check that the list is empty when we have no hosts/guests")
|
@DisplayName("Check that the list is empty when we have no hosts/guests")
|
||||||
@Test
|
@Test
|
||||||
public void findAllEmptyTest() {
|
public void findAllEmptyTest() {
|
||||||
when(mockPrincipal.getName()).thenReturn("user");
|
|
||||||
when(userRepository.findByUsername("user")).thenReturn(user);
|
|
||||||
List<UserResponse> l = guestController.findAll();
|
List<UserResponse> l = guestController.findAll();
|
||||||
assertThat(l.isEmpty());
|
assertThat(l.isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -46,9 +45,13 @@ public class GuestControllerTests {
|
||||||
@Test
|
@Test
|
||||||
public void findAllTest() {
|
public void findAllTest() {
|
||||||
User host1 = new User();
|
User host1 = new User();
|
||||||
|
host1.setId(2L);
|
||||||
User host2 = new User();
|
User host2 = new User();
|
||||||
|
host2.setId(3L);
|
||||||
User guest1 = new User();
|
User guest1 = new User();
|
||||||
|
guest1.setId(4L);
|
||||||
User guest2 = new User();
|
User guest2 = new User();
|
||||||
|
guest2.setId(5L);
|
||||||
|
|
||||||
user.addHost(host1);
|
user.addHost(host1);
|
||||||
user.addHost(host2);
|
user.addHost(host2);
|
||||||
|
@ -58,17 +61,17 @@ public class GuestControllerTests {
|
||||||
when(mockPrincipal.getName()).thenReturn("user");
|
when(mockPrincipal.getName()).thenReturn("user");
|
||||||
when(userRepository.findByUsername(mockPrincipal.getName())).thenReturn(this.user);
|
when(userRepository.findByUsername(mockPrincipal.getName())).thenReturn(this.user);
|
||||||
when(userRepository.findAll()).thenReturn(List.of(host1, host2, guest1, guest2));
|
when(userRepository.findAll()).thenReturn(List.of(host1, host2, guest1, guest2));
|
||||||
assertThat(guestController.findAll()).isSameAs(List.of(host1, host2, guest1, guest2));
|
assertThat(guestController.findAll())
|
||||||
|
.containsAll(
|
||||||
|
List.of(host1, host2, guest1, guest2)
|
||||||
|
.stream()
|
||||||
|
.map(UserResponse::fromUser)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
when(guestController.findHosts(mockPrincipal))
|
|
||||||
.thenReturn(List.of(UserResponse.fromUser(host1), UserResponse.fromUser(host2)));
|
|
||||||
assertThat(guestController.findHosts(mockPrincipal))
|
assertThat(guestController.findHosts(mockPrincipal))
|
||||||
.isSameAs(List.of(UserResponse.fromUser(host1), UserResponse.fromUser(host2)));
|
.containsExactly(UserResponse.fromUser(host1), UserResponse.fromUser(host2));
|
||||||
|
|
||||||
when(guestController.findGuests(mockPrincipal))
|
|
||||||
.thenReturn(List.of(UserResponse.fromUser(guest1), UserResponse.fromUser(guest2)));
|
|
||||||
assertThat(guestController.findGuests(mockPrincipal))
|
assertThat(guestController.findGuests(mockPrincipal))
|
||||||
.isSameAs(List.of(UserResponse.fromUser(guest1), UserResponse.fromUser(guest2)));
|
.containsExactly(UserResponse.fromUser(guest1), UserResponse.fromUser(guest2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Check that the host list is empty")
|
@DisplayName("Check that the host list is empty")
|
||||||
|
|
Loading…
Reference in a new issue