1 package com.atlassian.scheduler.core;
2
3 import com.atlassian.scheduler.config.JobConfig;
4 import com.atlassian.scheduler.core.impl.RunningJobImpl;
5 import org.junit.Test;
6
7 import java.util.Date;
8
9 import static com.atlassian.scheduler.core.Constants.JOB_ID;
10 import static com.atlassian.scheduler.core.Constants.KEY;
11 import static org.hamcrest.Matchers.equalTo;
12 import static org.hamcrest.Matchers.is;
13 import static org.hamcrest.Matchers.sameInstance;
14 import static org.junit.Assert.assertThat;
15
16
17
18
19 @SuppressWarnings({"ResultOfObjectAllocationIgnored", "ConstantConditions"})
20 public class RunningJobImplTest {
21 @Test(expected = IllegalArgumentException.class)
22 public void testStartTimeNull() {
23 new RunningJobImpl(null, JOB_ID, JobConfig.forJobRunnerKey(KEY));
24 }
25
26 @Test(expected = IllegalArgumentException.class)
27 public void testJobIdNull() {
28 new RunningJobImpl(new Date(), null, JobConfig.forJobRunnerKey(KEY));
29 }
30
31 @Test(expected = IllegalArgumentException.class)
32 public void testJobConfigNull() {
33 new RunningJobImpl(new Date(), JOB_ID, null);
34 }
35
36 @Test
37 public void testValues() {
38 final Date startTime = new Date();
39 final long originalTime = startTime.getTime();
40 final JobConfig config = JobConfig.forJobRunnerKey(KEY);
41 final RunningJob job = new RunningJobImpl(startTime, JOB_ID, config);
42
43 assertThat(job.getStartTime(), equalTo(startTime));
44 assertThat(job.getJobId(), equalTo(JOB_ID));
45 assertThat(job.getJobConfig(), sameInstance(config));
46
47
48 startTime.setTime(42L);
49 assertThat(job.getStartTime().getTime(), equalTo(originalTime));
50 job.getStartTime().setTime(42L);
51 assertThat(job.getStartTime().getTime(), equalTo(originalTime));
52 }
53
54 @Test
55 public void testCancelFlag() {
56 final JobConfig config = JobConfig.forJobRunnerKey(KEY);
57 final RunningJob job = new RunningJobImpl(new Date(), JOB_ID, config);
58
59 assertThat("Not cancelled initially", job.isCancellationRequested(), is(false));
60
61 job.cancel();
62 assertThat("Cancelled once requested", job.isCancellationRequested(), is(true));
63
64 job.cancel();
65 assertThat("Redundant cancel() has no effect", job.isCancellationRequested(), is(true));
66 }
67 }