### Question:
JobRequestHandlerImpl implements JobRequestHandler { @Override public Job updateMinionType(String jobId, String minionType, String username, String token, String sudo) throws Exception { checkUserCredentials(username, token); spawn.acquireJobLock(); try { Job job = spawn.getJob(jobId); if (job != null) { checkJobWritePrivileges(job, username, token, sudo); checkMinionTypeUpdatePrerequisite(job, job.getState() == JobState.IDLE, "Job is not idle"); checkMinionTypeUpdatePrerequisite(job, isJobOnMinionType(job, minionType), "Not all tasks and replicas are on " + minionType); job.setMinionType(minionType); spawn.updateJob(job); log.info("User {} updated job {} minion type to {}", username, jobId, minionType); } return job; } finally { spawn.releaseJobLock(); } } JobRequestHandlerImpl(Spawn spawn); @Override Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults); @Override Job updateMinionType(String jobId, String minionType, String username, String token, String sudo); @Override boolean maybeKickJobOrTask(KVPairs kv, Job job);  }### Answer:
@Test public void updateMinionType() throws Exception { Job job = new Job(); job.setState(JobState.IDLE); job.setMinionType("oldMinion"); when(spawn.getJob("job_id")).thenReturn(job); impl.updateMinionType("job_id","newMinion", username, token, sudo); verify(spawn).updateJob(job); assertEquals("newMinion", job.getMinionType()); }
@Test public void updateMinionType_notOnTargetType() throws Exception { Job job = new Job(); job.setState(JobState.IDLE); job.setMinionType("oldMinion"); JobTask task = new JobTask(); job.addTask(task); when(spawn.getJob("job_id")).thenReturn(job); try { impl.updateMinionType("job_id","newMinion", username, token, sudo); fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } verify(spawn, never()).updateJob(job); assertEquals("oldMinion", job.getMinionType()); }
@Test(expected = IllegalArgumentException.class) public void updateMinionType_jobNotIdle() throws Exception { Job job = new Job(); job.setState(JobState.RUNNING); job.setMinionType("oldMinion"); when(spawn.getJob("job_id")).thenReturn(job); impl.updateMinionType("job_id", "newMinion", username, token, sudo); }