SearchDelegator extends BaseDelegator implements ISearchDelegator { @Override public List<String> searchJobs( final String words, final SearchJobsOptions opts) throws P4JavaException { Validate.notBlank(words, "Null or empty words passed to searchJobs method"); List<Map<String, Object>> resultMaps = execMapCmdList( SEARCH, Parameters.processParameters(opts, null, new String[]{words}, server), null); List<String> jobIdList = new ArrayList<>(); if (resultMaps != null) { for (Map<String, Object> map : resultMaps) { if (map != null) { throwRequestExceptionIfErrorMessageFound(map); jobIdList.add(getInfoStr(map)); } } } return jobIdList; } SearchDelegator(IOptionsServer server); @Override List<String> searchJobs(
            final String words,
            final SearchJobsOptions opts);  }
@Test public void shouldReturnEmptySearchJobsWhenCommandReturnNullResultMaps() throws Exception { cmdArgument = new String[]{words}; when(server.execMapCmdList(eq(SEARCH.toString()), eq(cmdArgument), eq((Map<String, Object>)null))) .thenReturn(null); opts = null; assertThat(searchDelegator.searchJobs(words, opts).size(), is(0)); }
@Test public void shouldThrowsIllegalArgumentExceptionWhenSearchWordsIsBlank() throws Exception { thrown.expect(IllegalArgumentException.class); words = EMPTY; opts = null; searchDelegator.searchJobs(words, opts); }
@Test public void shouldReturnEmptySearchJobsWhenCommandReturnNullResultMaps() throws Exception { cmdArgument = new String[]{words}; when(server.execMapCmdList(eq(SEARCH.toString()), eq(cmdArgument), eq(null))) .thenReturn(null); opts = null; assertThat(searchDelegator.searchJobs(words, opts).size(), is(0)); }
@Test public void shouldThrowsRequestExceptionWhenInnerMethodCallThrowsIt() throws Exception { thrown.expect(RequestException.class); givenErrorMessageCode(); searchDelegator.searchJobs(words, opts); }
@Test public void shouldReturnNonEmptySearchJobs() throws Exception { givenInfoMessageCode(); List<String> searchJobs = searchDelegator.searchJobs(words, opts); assertThat(searchJobs.size(), is(1)); assertThat(searchJobs.get(0), is(SEARCH_JOB_ID)); }