### Question:
APIProcess extends ConsoleAPI<ProcessItem> implements
        APIHasAdd<ProcessItem>,
        APIHasUpdate<ProcessItem>,
        APIHasGet<ProcessItem>,
        APIHasSearch<ProcessItem>,
        APIHasDelete { @Override protected void fillCounters(final ProcessItem item, final List<String> counters) { fillNumberOfFailedCasesIfFailedCounterExists(item, counters); fillNumberOfOpenCasesIfOpenCounterExists(item, counters); }  @Override String defineDefaultSearchOrder(); @Override ProcessItem add(final ProcessItem item); @Override ProcessItem update(final APIID id, final Map<String, String> attributes); @Override ProcessItem get(final APIID id); @Override ItemSearchResult<ProcessItem> search(final int page, final int resultsByPage, final String search, final String orders,
            final Map<String, String> filters); @Override void delete(final List<APIID> ids);  }### Answer:
@Test public final void fillCounters_should_fill_number_of_failed_cases_when_counter_of_failed_cases_is_active() { final APIID id = APIID.makeAPIID(78L); final ProcessItem item = mock(ProcessItem.class); doReturn(id).when(item).getId(); final List<String> counters = Arrays.asList(ProcessItem.COUNTER_FAILED_CASES); final long numberOfFailedCases = 2L; final Map<String, String> filters = new HashMap<>(); filters.put(CaseItem.FILTER_CALLER, "any"); filters.put(CaseItem.ATTRIBUTE_PROCESS_ID, item.getId().toString()); filters.put(CaseItem.FILTER_STATE, ProcessInstanceState.ERROR.name()); doReturn(numberOfFailedCases).when(caseDatastore).count(null, null, filters); apiProcess.fillCounters(item, counters); verify(item).setAttribute(ProcessItem.COUNTER_FAILED_CASES, numberOfFailedCases); }
@Test public final void fillCounters_should_do_nothing_when_counter_of_failed_cases_is_not_active() { final ProcessItem item = mock(ProcessItem.class); final List<String> counters = new ArrayList<>(); apiProcess.fillCounters(item, counters); verify(item, never()).setAttribute(anyString(), anyLong()); }
@Test public final void fillCounters_should_fill_number_of_open_cases_when_counter_of_open_cases_is_active() { final APIID id = APIID.makeAPIID(78L); final ProcessItem item = mock(ProcessItem.class); doReturn(id).when(item).getId(); final List<String> counters = Arrays.asList(ProcessItem.COUNTER_OPEN_CASES); final Map<String, String> filters = new HashMap<>(); filters.put(CaseItem.FILTER_CALLER, "any"); filters.put(CaseItem.ATTRIBUTE_PROCESS_ID, id.toString()); final long numberOfOpenCases = 2L; doReturn(numberOfOpenCases).when(caseDatastore).count(null, null, filters); apiProcess.fillCounters(item, counters); verify(item).setAttribute(ProcessItem.COUNTER_OPEN_CASES, numberOfOpenCases); }
@Test public final void fillCounters_should_do_nothing_when_counter_of_open_cases_is_not_active() { final ProcessItem item = mock(ProcessItem.class); final List<String> counters = new ArrayList<>(); apiProcess.fillCounters(item, counters); verify(item, never()).setAttribute(anyString(), anyLong()); }