это мой контроллер ...java.lang.AssertionError: Статус ожидается: <200> но: <400> контроллер весной Джерси
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/categories")
public POSResponse getAllCategories() {
String countryCode="1";
return infoService.getAllCategories(countryCode);
}
это мой testController ....
@Mock
InfoService infoService;
@InjectMocks
private InfoController infoController;
private MockMvc mockMvc;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(infoController).build();
}
@Test
public void getAllCategoriesTest() throws Exception {
POSResponse response=new POSResponse();
Category category=new Category();
category.setCountryCode(1);
category.setDescription("Mother Dairy");
response.setResponse(category);
when(infoService.getAllCategories("1")).thenReturn(response);
mockMvc.perform(get("/categories"))
.andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.id", is(1)))
.andExpect(jsonPath("$.description", is("Mother Dairy")));
verify(infoService, times(1)).getAllCategories("1");
verifyNoMoreInteractions(infoService);
}
я используя контроллер джерси. , когда я называю метод я получил сообщ ошибка "java.lang.AssertionError: Статус ожидается: < 200>, но был: < 400>"
Вы уверены, что 'infoService' вводится в ваш контроллер? Мне кажется, что вы должны называть 'MockMvcBuilders.standaloneSetup', а затем' MockitoAnnotations.initMocks ' –