@Test public void testFailValidationSaveLink() throws Exception { when(bindingResult.hasErrors()).thenReturn(true); JsonResponse expected = controller.saveLink(link(), bindingResult); assertEquals(expected.getStatus(), JsonResponseStatus.FAIL); }
@Test public void testDeleteLink() throws Exception { boolean expectedResult = true; long id = 1L; doReturn(expectedResult).when(service).deleteLink(eq(id), any(Component.class)); JsonResponse expected = controller.deleteLink(id); assertEquals(expected.getStatus(), JsonResponseStatus.SUCCESS); verify(service).deleteLink(eq(id), any(Component.class)); }
@Test public void savingLinkShouldPassIfNoValidationErrorsFound() throws Exception { when(bindingResult.hasErrors()).thenReturn(false); JsonResponse expected = controller.saveLink(link(), bindingResult); assertEquals(expected.getStatus(), JsonResponseStatus.SUCCESS); verify(service).saveLink(any(ExternalLink.class), any(Component.class)); }