### Question:
ReadyService { public void addDaemon(final String jobName) { if (regCenter.getNumChildren(ReadyNode.ROOT) > env.getFrameworkConfiguration().getJobStateQueueSize()) { log.warn("Cannot add daemon job, caused by read state queue size is larger than {}.", env.getFrameworkConfiguration().getJobStateQueueSize()); return; } Optional<CloudJobConfiguration> cloudJobConfig = configService.load(jobName); if (!cloudJobConfig.isPresent() || CloudJobExecutionType.DAEMON != cloudJobConfig.get().getJobExecutionType() || runningService.isJobRunning(jobName)) { return; } 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 assertAddDaemonWithOverJobQueueSize() { Mockito.when(regCenter.getNumChildren(ReadyNode.ROOT)).thenReturn(BootstrapEnvironment.getInstance().getFrameworkConfiguration().getJobStateQueueSize() + 1); readyService.addDaemon("test_job"); Mockito.verify(regCenter, Mockito.times(0)).persist("/state/ready/test_job", "1"); }
@Test public void assertAddDaemonWithJobConfigIsNotPresent() { Mockito.when(configService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent()); readyService.addDaemon("test_job"); Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready"); Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1")); }
@Test public void assertAddDaemonWithJobConfigIsNotDaemon() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); readyService.addDaemon("test_job"); Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready"); Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1")); }
@Test public void assertAddDaemonWithoutRootNode() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON))); readyService.addDaemon("test_job"); Mockito.verify(regCenter).persist("/state/ready/test_job", "1"); }
@Test public void assertAddDaemonWithSameJobName() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON))); readyService.addDaemon("test_job"); Mockito.verify(regCenter).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1")); }
@Test public void assertAddRunningDaemon() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON))); Mockito.when(runningService.isJobRunning("test_job")).thenReturn(true); readyService.addDaemon("test_job"); Mockito.verify(regCenter, Mockito.never()).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1")); }
@Test public void assertAddDaemonWithoutSameJobName() { Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON))); readyService.addDaemon("test_job"); Mockito.verify(regCenter).persist("/state/ready/test_job", "1"); }