use of codeu.model.store.basic.UserStore in project codeu-2018-team12 by codeu-2018-team12.
the class RegisterServletTest method testDoPost_ExistingUser.
@Test
public void testDoPost_ExistingUser() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
Mockito.when(mockRequest.getParameter("password")).thenReturn("test password");
Mockito.when(mockRequest.getParameter("confirmPassword")).thenReturn("test password");
UserStore mockUserStore = Mockito.mock(UserStore.class);
Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
registerServlet.setUserStore(mockUserStore);
ActivityStore mockActivityStore = Mockito.mock(ActivityStore.class);
registerServlet.setActivityStore(mockActivityStore);
HttpSession mockSession = Mockito.mock(HttpSession.class);
Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
registerServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("error", "That username is already taken.");
Mockito.verify(mockUserStore, Mockito.never()).addUser(Mockito.any(User.class));
Mockito.verify(mockActivityStore, Mockito.never()).addActivity(Mockito.any(Activity.class));
}
use of codeu.model.store.basic.UserStore in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationTest method testCreate.
@Test
public void testCreate() {
UUID id = UUID.randomUUID();
UUID owner = UUID.randomUUID();
String title = "Test_Title";
Instant creation = Instant.now();
Conversation conversation = new Conversation(id, owner, title, creation);
UserStore userStore = UserStore.getInstance();
User ownerUser = userStore.getUser(owner);
List<User> conversationUsers = conversation.getConversationUsers();
Assert.assertEquals(id, conversation.getId());
Assert.assertEquals(owner, conversation.getOwnerId());
Assert.assertEquals(title, conversation.getTitle());
Assert.assertEquals(creation, conversation.getCreationTime());
Assert.assertTrue(conversationUsers.contains(ownerUser));
}
use of codeu.model.store.basic.UserStore 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);
}
use of codeu.model.store.basic.UserStore in project CodeU-Spring-2018 by maksymko.
the class RegisterServletTest method testDoPost_ExistingUser.
@Test
public void testDoPost_ExistingUser() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
UserStore mockUserStore = Mockito.mock(UserStore.class);
Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
registerServlet.setUserStore(mockUserStore);
HttpSession mockSession = Mockito.mock(HttpSession.class);
Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
registerServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("error", "That username is already taken.");
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
use of codeu.model.store.basic.UserStore in project CodeU-Spring-2018 by jwang281.
the class LoginServletTest method testDoPost_UnregisteredUser.
@Test
public void testDoPost_UnregisteredUser() throws IOException, ServletException {
UserStore mockUserStore = Mockito.mock(UserStore.class);
Mockito.when(mockUserStore.isUserRegistered("unregistered_username")).thenReturn(false);
loginServlet.setUserStore(mockUserStore);
HttpSession mockSession = Mockito.mock(HttpSession.class);
Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
loginServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockRequest).setAttribute("error", "That username was not found.");
Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Aggregations