use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_Markdown.
@Test
public void testDoPost_Markdown() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "testbio", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(fakeUser);
Mockito.when(mockRequest.getParameter("message")).thenReturn("**test**");
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("<strong>test</strong>", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_Emoji.
@Test
public void testDoPost_Emoji() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "testbio", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(fakeUser);
Mockito.when(mockRequest.getParameter("message")).thenReturn(":japanese_goblin:");
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("👺", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_ConversationNotFound.
@Test
public void testDoPost_ConversationNotFound() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(null);
chatServlet.doPost(mockRequest, mockResponse);
Mockito.verify(mockMessageStore, Mockito.never()).addMessage(Mockito.any(Message.class));
Mockito.verify(mockResponse).sendRedirect("/conversations");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServletTest method testDoPost_StoresMessage.
@Test
public void testDoPost_StoresMessage() throws IOException, ServletException {
Mockito.when(mockRequest.getRequestURI()).thenReturn("/chat/test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Conversation fakeConversation = new Conversation(UUID.randomUUID(), UUID.randomUUID(), "test_conversation", Instant.now());
Mockito.when(mockConversationStore.getConversationWithTitle("test_conversation")).thenReturn(fakeConversation);
fakeConversation.getConversationUsers().add(fakeUser);
Mockito.when(mockRequest.getParameter("message")).thenReturn("Test message.");
chatServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(mockMessageStore).addMessage(messageArgumentCaptor.capture());
Assert.assertEquals("Test message.", messageArgumentCaptor.getValue().getContent());
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServletTest method testDoPost_NewConversation.
@Test
public void testDoPost_NewConversation() throws IOException, ServletException {
Mockito.when(mockRequest.getParameter("conversationTitle")).thenReturn("test_conversation");
Mockito.when(mockSession.getAttribute("user")).thenReturn("test_username");
User fakeUser = new User(UUID.randomUUID(), "test_username", "password", "test biography", Instant.now());
Mockito.when(mockUserStore.getUser("test_username")).thenReturn(fakeUser);
Mockito.when(mockConversationStore.isTitleTaken("test_conversation")).thenReturn(false);
conversationServlet.doPost(mockRequest, mockResponse);
ArgumentCaptor<Conversation> conversationArgumentCaptor = ArgumentCaptor.forClass(Conversation.class);
Mockito.verify(mockConversationStore).addConversation(conversationArgumentCaptor.capture());
Assert.assertEquals(conversationArgumentCaptor.getValue().getTitle(), "test_conversation");
Mockito.verify(mockResponse).sendRedirect("/chat/test_conversation");
}
Aggregations