Я тест Mockito, который использует Аргумент Captor для проверки нового пользователя был вывешен правильно:Mockito Довод Captor Test Возвратившись Всего JSON объект
@Test
public void testPostUser() throws Exception{
User user = new User(1L, "tonkatruck");
when(userService.addUser(any(User.class))).thenReturn(user);
mockMvc.perform(post("/api/user")
.content("{\"userId\":\"1\",\"userName\":\"tonkatruck\"}")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.userName", is(user.getUserName())))
.andExpect(status().isCreated())
.andDo(print());
//verify(userService).addUser(any(User.class));
verify(userService).addUser(userCaptor.capture());
//get the username from what was captured in the POST method and assert that it posted the correct username
String username = userCaptor.getValue().getUserName();
assertEquals("tonkatruck", username);
}
тест завершается с ошибкой:
Failed tests: testPostUser(com.ucrisko.libroomreserve.tests.UserControllerTest): expected:<[tonkatruck]> but was:<[{"userId":"1","userName":"tonkatruck"}]>
Я вызываю метод getUserName() класса User на объекте userCaptor, поэтому любая идея, почему утверждение выдается как весь пользовательский объект JSON?