### Question:
ActivityVariableResource extends CommonResource { @Get("json") public DataInstance getTaskVariable() { try { final String taskId = getAttribute(ACTIVITYDATA_ACTIVITY_ID); final String dataName = getAttribute(ACTIVITYDATA_DATA_NAME); return getTaskVariableInstance(dataName, Long.valueOf(taskId)); } catch (final Exception e) { throw new APIException(e); } } ActivityVariableResource(final ProcessAPI processAPI); @Get("json") DataInstance getTaskVariable(); static final String ACTIVITYDATA_ACTIVITY_ID; static final String ACTIVITYDATA_DATA_NAME; }### Answer:
@Test(expected = APIException.class) public void shouldDoGetWithNothingThowsAnApiException() throws DataNotFoundException { activityVariableResource.getTaskVariable(); }
@Test(expected = APIException.class) public void should_throw_exception_if_attribute_is_not_found() throws Exception { doReturn(null).when(activityVariableResource).getAttribute(anyString()); activityVariableResource.getTaskVariable(); }
@Test public void should_do_get_call_getAttribute() throws DataNotFoundException { doReturn("").when(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_DATA_NAME); doReturn("1").when(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_ACTIVITY_ID); doReturn(null).when(processAPI).getActivityDataInstance(anyString(), anyLong()); activityVariableResource.getTaskVariable(); verify(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_ACTIVITY_ID); verify(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_DATA_NAME); }
@Test public void should_return() throws DataNotFoundException { doReturn("").when(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_DATA_NAME); doReturn("1").when(activityVariableResource).getAttribute(ActivityVariableResource.ACTIVITYDATA_ACTIVITY_ID); final DataInstanceImpl dataInstance = createLongDataInstance(123L); doReturn(dataInstance).when(processAPI).getActivityDataInstance(anyString(), anyLong()); final DataInstance dataInstanceResult = activityVariableResource.getTaskVariable(); assertThat(dataInstanceResult).isEqualTo(dataInstance); }