### Question:
ReadyService { public void addTransient(final String jobName) { if (regCenter.getNumChildren(ReadyNode.ROOT) > env.getFrameworkConfiguration().getJobStateQueueSize()) { log.warn("Cannot add transient job, caused by read state queue size is larger than {}.", env.getFrameworkConfiguration().getJobStateQueueSize()); return; } Optional<CloudJobConfiguration> cloudJobConfig = configService.load(jobName); if (!cloudJobConfig.isPresent() || CloudJobExecutionType.TRANSIENT != cloudJobConfig.get().getJobExecutionType()) { return; } String readyJobNode = ReadyNode.getReadyJobNodePath(jobName); String times = regCenter.getDirectly(readyJobNode); if (cloudJobConfig.get().getTypeConfig().getCoreConfig().isMisfire()) { regCenter.persist(readyJobNode, Integer.toString(null == times ? 1 : Integer.parseInt(times) + 1)); } else { regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1"); } } ReadyService(final CoordinatorRegistryCenter regCenter); void addTransient(final String jobName); void addDaemon(final String jobName); void setMisfireDisabled(final String jobName); Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts); void remove(final Collection<String> jobNames); Map<String, Integer> getAllReadyTasks();  }### Answer:
@Test public void assertAddTransientWithJobConfigIsNotPresent() { Mockito.when(configService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent()); readyService.addTransient("test_job"); Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready"); Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("")); }
@Test public void assertAddTransientWithJobConfigIsNotTransient() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON))); readyService.addTransient("test_job"); Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready"); Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("")); }
@Test public void assertAddTransientWhenJobExistedAndEnableMisfired() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); Mockito.when(regCenter.getDirectly("/state/ready/test_job")).thenReturn("1"); readyService.addTransient("test_job"); Mockito.verify(regCenter).persist("/state/ready/test_job", "2"); }
@Test public void assertAddTransientWhenJobExistedAndDisableMisfired() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", false))); Mockito.when(regCenter.getDirectly("/state/ready/test_job")).thenReturn("1"); readyService.addTransient("test_job"); Mockito.verify(regCenter).persist("/state/ready/test_job", "1"); }
@Test public void assertAddTransientWhenJobNotExisted() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); readyService.addTransient("test_job"); Mockito.verify(regCenter).persist("/state/ready/test_job", "1"); }
@Test public void assertAddTransientWithOverJobQueueSize() { Mockito.when(regCenter.getNumChildren(ReadyNode.ROOT)).thenReturn(BootstrapEnvironment.getInstance().getFrameworkConfiguration().getJobStateQueueSize() + 1); readyService.addTransient("test_job"); Mockito.verify(regCenter, Mockito.times(0)).persist("/state/ready/test_job", "1"); }