Advertisement
VladNitu

Test Ex MockMVC ptr Controller

Dec 18th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. @Test
  2. public void chooseActivity() throws Exception {
  3. Matching savedMatching = new Matching("Niq", 2L, "side", true);
  4.  
  5. when(activityPublisher.check(any(Matching.class))).thenReturn(true);
  6. when(matchingServiceImpl.findMatchingWithPendingFalse(anyString(), anyLong())).thenReturn(Optional.empty());
  7. lenient().when(matchingServiceImpl.save(any(Matching.class))).thenReturn(savedMatching);
  8. when(activityPublisher.getOwnerId(anyLong())).thenReturn("dummyString");
  9. doNothing().when(notificationPublisher).notifyUser(anyString(), anyString(), anyLong(), anyString(), anyString());
  10.  
  11.  
  12. MvcResult mvcResult = mockMvc
  13. .perform(post("/chooseActivity")
  14. .contentType(MediaType.APPLICATION_JSON)
  15. .content(objectMapper.writeValueAsString(matching))
  16. )
  17. .andDo(MockMvcResultHandlers.print())
  18. .andExpect(status().isOk())
  19. .andReturn();
  20.  
  21. String contentAsString = mvcResult.getResponse().getContentAsString();
  22. Matching obtained = objectMapper.readValue(contentAsString, Matching.class);
  23.  
  24. assertThat(savedMatching).isEqualTo(obtained);
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement