use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class LoginServletTest method testDoPost_BadPass.
@Test
public void testDoPost_BadPass() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("username")).thenReturn("test_username");
Mockito.when(mockRequest.getParameter("password")).thenReturn("badpass");
UserStore mockUserStore = Mockito.mock(UserStore.class);
Mockito.when(mockUserStore.isUserRegistered("test_username")).thenReturn(true);
String hashedPassword = BCrypt.hashpw("password", BCrypt.gensalt());
User testUser = new User(UUID.randomUUID(), "test_username", hashedPassword, "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(testUser);
loginServlet.setUserStore(mockUserStore);
HttpSession mockSession = Mockito.mock(HttpSession.class);
Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
loginServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockUserStore, Mockito.never()).addUser(Mockito.any(User.class));
Mockito.verify(mockRequest).setAttribute("error", "Invalid password.");
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
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-2018-team12 by codeu-2018-team12.
the class UserStoreTest method testGetUser_byUsername_found.
@Test
public void testGetUser_byUsername_found() {
User resultUser = userStore.getUser(USER_ONE.getName());
assertEquals(USER_ONE, resultUser);
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
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-2018-team12 by codeu-2018-team12.
the class UserStoreTest method testAddUser.
@Test
public void testAddUser() {
User inputUser = new User(UUID.randomUUID(), "test_username", "password", null, Instant.now());
userStore.addUser(inputUser);
User resultUser = userStore.getUser("test_username");
assertEquals(inputUser, resultUser);
Mockito.verify(mockPersistentStorageAgent).writeThrough(inputUser);
}
Aggregations