JobDelegator extends BaseDelegator implements IJobDelegator { @SuppressWarnings("unchecked") @Override public IJob getJob(final String jobId) throws ConnectionException, RequestException, AccessException { Validate.notBlank(jobId, "JobId shouldn't null or empty"); List<Map<String, Object>> resultMaps = execMapCmdList(JOB, new String[] { "-o", jobId }, null); return ResultListBuilder.buildNullableObjectFromNonInfoMessageCommandResultMaps( resultMaps, new Function<Map, IJob>() { @Override public IJob apply(Map map) { return new Job(server, map); } } ); } JobDelegator(final IOptionsServer server); @Override IJob createJob(@Nonnull final Map<String, Object> fieldMap); @Override String deleteJob(final String jobId); @SuppressWarnings("unchecked") @Override IJob getJob(final String jobId); @Override String updateJob(@Nonnull final IJob job);  }
@Test(expected = NullPointerException.class) public void testJobGetNull() throws P4JavaException { jobDelegator.getJob(null); }
@Test(expected = IllegalArgumentException.class) public void testJobGetEmpty() throws P4JavaException { jobDelegator.getJob(""); }
@Test(expected = ConnectionException.class) public void testJobGetConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenThrow(ConnectionException.class); jobDelegator.getJob(TEST_JOB); }
@Test(expected = AccessException.class) public void testJobGetAccessException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenThrow(AccessException.class); jobDelegator.getJob(TEST_JOB); }
@Test(expected = RequestException.class) public void testJobGetRequestException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenThrow(RequestException.class); jobDelegator.getJob(TEST_JOB); }
@Test(expected = P4JavaException.class) public void testJobGetP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenThrow(P4JavaException.class); jobDelegator.getJob(TEST_JOB); }
@Test public void testJobGet() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenReturn(buildValidGetResultMap()); IJob job = jobDelegator.getJob(TEST_JOB); verify(server).execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null)); assertJob(job); }