JobDelegator extends BaseDelegator implements IJobDelegator { @Override public String deleteJob(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[] { "-d", jobId }, null); return ResultMapParser.parseCommandResultMapIfIsInfoMessageAsString(resultMaps); } 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 testJobDeleteNull() throws P4JavaException { jobDelegator.deleteJob(null); }
@Test(expected = IllegalArgumentException.class) public void testJobDeleteEmpty() throws P4JavaException { jobDelegator.deleteJob(""); }
@Test(expected = ConnectionException.class) public void testJobDeleteConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null))) .thenThrow(ConnectionException.class); jobDelegator.deleteJob(TEST_JOB); }
@Test(expected = AccessException.class) public void testJobDeleteAccessException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null))) .thenThrow(AccessException.class); jobDelegator.deleteJob(TEST_JOB); }
@Test(expected = RequestException.class) public void testJobDeleteRequestException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null))) .thenThrow(RequestException.class); jobDelegator.deleteJob(TEST_JOB); }
@Test(expected = P4JavaException.class) public void testJobDeleteP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null))) .thenThrow(P4JavaException.class); jobDelegator.deleteJob(TEST_JOB); }
@Test public void testJobDelete() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null))) .thenReturn(buildValidDeleteResultMap()); String result = jobDelegator.deleteJob(TEST_JOB); verify(server).execMapCmdList(eq(JOB.toString()), argThat(DELETE_MATCHER), eq(null)); assertTrue(result.startsWith("Job " + TEST_JOB + " deleted")); }