use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class UserStoreTest method testGetUser_byUsername_notFound.
@Test
public void testGetUser_byUsername_notFound() {
User resultUser = userStore.getUser("fake username");
Assert.assertNull(resultUser);
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class UserStoreTest method testAddUser.
@Test
public void testAddUser() {
User inputUser = new User(UUID.randomUUID(), "test_username", "test_password", Instant.now());
userStore.addUser(inputUser);
User resultUser = userStore.getUser("test_username");
assertEquals(inputUser, resultUser);
Mockito.verify(mockPersistentStorageAgent).writeThrough(inputUser);
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class UserStoreTest method testGetUser_byId_found.
@Test
public void testGetUser_byId_found() {
User resultUser = userStore.getUser(USER_ONE.getId());
assertEquals(USER_ONE, resultUser);
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class UserStoreTest method testGetUser_byId_notFound.
@Test
public void testGetUser_byId_notFound() {
User resultUser = userStore.getUser(UUID.randomUUID());
Assert.assertNull(resultUser);
}
use of codeu.model.data.User in project CodeU-Spring-2018 by maksymko.
the class LoginServletTest method testDoPost_ExistingUserWrongPassword.
@Test
public void testDoPost_ExistingUserWrongPassword() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
Mockito.when(mockRequest.getParameter("password")).thenReturn("wrong password");
UserStore mockUserStore = Mockito.mock(UserStore.class);
loginServlet.setUserStore(mockUserStore);
Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
User mockUser = Mockito.mock(User.class);
Mockito.when(mockUserStore.getUser("test username")).thenReturn(mockUser);
Mockito.when(mockUser.getPassword()).thenReturn(BCrypt.hashpw("correct password", BCrypt.gensalt()));
loginServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("error", "Invalid password.");
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Aggregations