OnDemandSchedulerManager extends SchedulerManager { public void triggerScheduler(String[] jobs) { String identifier = "NetOps-PC1502295457753"; for(String job: jobs) { switch (job) { case BULK_UPLOAD: case SHADOW_USER: scheduleOnDemand(identifier, job); break; default: ProjectLogger.log( "OnDemandSchedulerManager:triggerScheduler: There is no such job", LoggerEnum.INFO.name()); } } } OnDemandSchedulerManager(); void scheduleOnDemand(String identifier, String job); static OnDemandSchedulerManager getInstance(); void triggerScheduler(String[] jobs); static Map<String, String> schedulerMap; }
@Test public void testTriggerScheduler() throws SchedulerException { PowerMockito.suppress(PowerMockito.constructor(SchedulerManager.class)); PowerMockito.suppress(PowerMockito.methodsDeclaredIn(SchedulerManager.class)); scheduler = mock(Scheduler.class); PowerMockito.mockStatic(SchedulerManager.class); String[] jobs = {"shadowuser"}; onDemandSchedulerManager = spy(OnDemandSchedulerManager.class); when(scheduler.checkExists((JobKey) Mockito.anyObject())).thenReturn(false); onDemandSchedulerManager.triggerScheduler(jobs); verify(onDemandSchedulerManager).scheduleOnDemand(Mockito.anyString(), Mockito.anyString()); }