From 6abedac3ccbe9e6b3e532be73f996f5d63de958d Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sat, 23 May 2020 17:50:39 +0200 Subject: [PATCH] It wasn't, but now it is --- .../controller/GuestControllerTests.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestControllerTests.java index c116667..26af2b6 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestControllerTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/GuestControllerTests.java @@ -8,6 +8,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.EagerUserRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User; import java.security.Principal; import java.util.List; +import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; 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") @Test public void findAllEmptyTest() { - when(mockPrincipal.getName()).thenReturn("user"); - when(userRepository.findByUsername("user")).thenReturn(user); List l = guestController.findAll(); assertThat(l.isEmpty()); } @@ -46,9 +45,13 @@ public class GuestControllerTests { @Test public void findAllTest() { User host1 = new User(); + host1.setId(2L); User host2 = new User(); + host2.setId(3L); User guest1 = new User(); + guest1.setId(4L); User guest2 = new User(); + guest2.setId(5L); user.addHost(host1); user.addHost(host2); @@ -58,17 +61,17 @@ public class GuestControllerTests { when(mockPrincipal.getName()).thenReturn("user"); when(userRepository.findByUsername(mockPrincipal.getName())).thenReturn(this.user); 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)) - .isSameAs(List.of(UserResponse.fromUser(host1), UserResponse.fromUser(host2))); - - when(guestController.findGuests(mockPrincipal)) - .thenReturn(List.of(UserResponse.fromUser(guest1), UserResponse.fromUser(guest2))); + .containsExactly(UserResponse.fromUser(host1), UserResponse.fromUser(host2)); 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")