### Question:
ProducerManager { public void register(final CloudJobConfiguration jobConfig) { if (disableJobService.isDisabled(jobConfig.getJobName())) { throw new JobConfigurationException("Job '%s' has been disable.", jobConfig.getJobName()); } Optional<CloudAppConfiguration> appConfigFromZk = appConfigService.load(jobConfig.getAppName()); if (!appConfigFromZk.isPresent()) { throw new AppConfigurationException("Register app '%s' firstly.", jobConfig.getAppName()); } Optional<CloudJobConfiguration> jobConfigFromZk = configService.load(jobConfig.getJobName()); if (jobConfigFromZk.isPresent()) { throw new JobConfigurationException("Job '%s' already existed.", jobConfig.getJobName()); } configService.add(jobConfig); schedule(jobConfig); } ProducerManager(final SchedulerDriver schedulerDriver, final CoordinatorRegistryCenter regCenter); void startup(); void register(final CloudJobConfiguration jobConfig); void update(final CloudJobConfiguration jobConfig); void deregister(final String jobName); void schedule(final CloudJobConfiguration jobConfig); void unschedule(final String jobName); void reschedule(final String jobName); void sendFrameworkMessage(final ExecutorID executorId, final SlaveID slaveId, final byte[] data); void shutdown();  }### Answer:
@Test(expected = AppConfigurationException.class) public void assertRegisterJobWithoutApp() { when(appConfigService.load("test_app")).thenReturn(Optional.<CloudAppConfiguration>absent()); producerManager.register(transientJobConfig); }
@Test(expected = JobConfigurationException.class) public void assertRegisterExistedJob() { when(appConfigService.load("test_app")).thenReturn(Optional.of(appConfig)); when(configService.load("transient_test_job")).thenReturn(Optional.of(transientJobConfig)); producerManager.register(transientJobConfig); }
@Test(expected = JobConfigurationException.class) public void assertRegisterDisabledJob() { when(disableJobService.isDisabled("transient_test_job")).thenReturn(true); producerManager.register(transientJobConfig); }
@Test public void assertRegisterTransientJob() { when(appConfigService.load("test_app")).thenReturn(Optional.of(appConfig)); when(configService.load("transient_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent()); producerManager.register(transientJobConfig); verify(configService).add(transientJobConfig); verify(transientProducerScheduler).register(transientJobConfig); }
@Test public void assertRegisterDaemonJob() { when(appConfigService.load("test_app")).thenReturn(Optional.of(appConfig)); when(configService.load("daemon_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent()); producerManager.register(daemonJobConfig); verify(configService).add(daemonJobConfig); verify(readyService).addDaemon("daemon_test_job"); }