findguests should be tested and imports should be fixed
This commit is contained in:
parent
420fed7f88
commit
67b2c3ae4f
1 changed files with 24 additions and 3 deletions
|
@ -16,6 +16,7 @@ import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.security.test.context.support.WithMockUser;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@WithMockUser(username = "user")
|
@WithMockUser(username = "user")
|
||||||
|
@ -59,11 +60,11 @@ public class GuestControllerTests {
|
||||||
assertThat(guestController.findAll()).isSameAs(List.of(host, guest));
|
assertThat(guestController.findAll()).isSameAs(List.of(host, guest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Check that we get empty host list")
|
@DisplayName("Check that the host list is empty")
|
||||||
@Test
|
@Test
|
||||||
public void findHostsEmptyTest() {
|
public void findHostsEmptyTest() {
|
||||||
when(mockPrincipal.getName()).thenReturn("user2");
|
when(mockPrincipal.getName()).thenReturn("user");
|
||||||
Mockito.doReturn(List.of()).when(userRepository.findByUsername("user2"));
|
Mockito.doReturn(List.of()).when(userRepository.findByUsername("user"));
|
||||||
assertThat(guestController.findHosts(mockPrincipal).isEmpty());
|
assertThat(guestController.findHosts(mockPrincipal).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +79,24 @@ public class GuestControllerTests {
|
||||||
Mockito.doReturn(List.of(host1, host2)).when(userRepository.findByUsername("user"));
|
Mockito.doReturn(List.of(host1, host2)).when(userRepository.findByUsername("user"));
|
||||||
assertThat(guestController.findHosts(mockPrincipal)).isSameAs(List.of(host1, host2));
|
assertThat(guestController.findHosts(mockPrincipal)).isSameAs(List.of(host1, host2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Check that the guest list is empty")
|
||||||
|
@Test
|
||||||
|
public void findGuestsEmptyTest() {
|
||||||
|
when(mockPrincipal.getName()).thenReturn("user");
|
||||||
|
Mockito.doReturn(List.of()).when(userRepository.findByUsername("user"));
|
||||||
|
assertThat(guestController.findGuests(mockPrincipal).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Check that the guest list contains the guests")
|
||||||
|
@Test
|
||||||
|
public void findGuestsTest() {
|
||||||
|
User guest1 = new User();
|
||||||
|
User guest2 = new User();
|
||||||
|
|
||||||
|
when(mockPrincipal.getName()).thenReturn("user");
|
||||||
|
when(userRepository.findByUsername(mockPrincipal.getName())).thenReturn(this.user);
|
||||||
|
Mockito.doReturn(List.of(guest1, guest2)).when(userRepository.findByUsername("user"));
|
||||||
|
assertThat(guestController.findGuests(mockPrincipal)).isSameAs(List.of(guest1, guest2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue