### Question:
CaseInfoResource extends CommonResource { @Get("json") public CaseInfo getCaseInfo() { try { final long caseId = Long.parseLong(getAttribute(CASE_ID)); final CaseInfo caseInfo = new CaseInfo(); caseInfo.setId(caseId); caseInfo.setFlowNodeStatesCounters(getFlownodeCounters(caseId)); return caseInfo; } catch (final Exception e) { throw new APIException(e); } } CaseInfoResource(final ProcessAPI processAPI); @Get("json") CaseInfo getCaseInfo(); static final String CASE_ID; }### Answer:
@Test(expected = APIException.class) public void shouldDoGetWithNothingThowsAnApiException() throws DataNotFoundException { caseInfoResource.getCaseInfo(); }
@Test(expected = APIException.class) public void should_throw_exception_if_attribute_is_not_found() throws Exception { doReturn(null).when(caseInfoResource).getAttribute(anyString()); caseInfoResource.getCaseInfo(); }
@Test public void should_return_case_info_123() throws DataNotFoundException { final long id = 123; doReturn(String.valueOf(id)).when(caseInfoResource).getAttribute(CaseInfoResource.CASE_ID); final HashMap<String, Map<String, Long>> taskWithCounters = new HashMap<String, Map<String, Long>>(); when(processAPI.getFlownodeStateCounters(anyLong())).thenReturn(taskWithCounters); final CaseInfo caseInfo = caseInfoResource.getCaseInfo(); assertThat(caseInfo).isNotNull(); assertThat(caseInfo.getId()).isSameAs(id); assertThat(caseInfo.getFlowNodeStatesCounters()).isEqualTo(taskWithCounters); }