Provide accessors to scheduled tasks

Updated ScheduledTaskRegistrar to offer accessors to the tasks
it is responsible to schedule.

Issue: SPR-12748
This commit is contained in:
Tobias Montagna-Hay
2015-02-24 17:20:47 +13:00
committed by Stephane Nicoll
parent dff2a3d180
commit 64467b4f59
2 changed files with 109 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.config;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Tobias Montagna-Hay
*/
public class ScheduledTaskRegistrarTest {
private final ScheduledTaskRegistrar taskRegistrar = new ScheduledTaskRegistrar();
@Test
public void getTriggerTasks() {
TriggerTask mockTriggerTask = mock(TriggerTask.class);
List<TriggerTask> triggerTaskList = Collections.singletonList(mockTriggerTask);
this.taskRegistrar.setTriggerTasksList(triggerTaskList);
List<TriggerTask> retrievedList = this.taskRegistrar.getTriggerTaskList();
assertEquals(1, retrievedList.size());
assertEquals(mockTriggerTask, retrievedList.get(0));
}
@Test
public void getCronTasks() {
CronTask mockCronTask = mock(CronTask.class);
List<CronTask> cronTaskList = Collections.singletonList(mockCronTask);
this.taskRegistrar.setCronTasksList(cronTaskList);
List<CronTask> retrievedList = this.taskRegistrar.getCronTaskList();
assertEquals(1, retrievedList.size());
assertEquals(mockCronTask, retrievedList.get(0));
}
@Test
public void testGetFixedRateTasks() {
IntervalTask mockFixedRateTask = mock(IntervalTask.class);
List<IntervalTask> fixedRateTaskList = Collections.singletonList(mockFixedRateTask);
this.taskRegistrar.setFixedRateTasksList(fixedRateTaskList);
List<IntervalTask> retrievedList = this.taskRegistrar.getFixedRateTaskList();
assertEquals(1, retrievedList.size());
assertEquals(mockFixedRateTask, retrievedList.get(0));
}
@Test
public void testGetFixedDelayTasks() {
IntervalTask mockFixedDelayTask = mock(IntervalTask.class);
List<IntervalTask> fixedDelayTaskList = Collections.singletonList(mockFixedDelayTask);
this.taskRegistrar.setFixedDelayTasksList(fixedDelayTaskList);
List<IntervalTask> retrievedList = this.taskRegistrar.getFixedDelayTaskList();
assertEquals(1, retrievedList.size());
assertEquals(mockFixedDelayTask, retrievedList.get(0));
}
}