KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > JobDetailTest


1 /*
2  * Copyright 2004-2006 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */

16 package org.quartz;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Arrays JavaDoc;
20 import java.util.HashSet JavaDoc;
21
22 import junit.framework.TestCase;
23
24 /**
25  * Unit test for JobDetail.
26  */

27 public class JobDetailTest extends TestCase {
28     public void testAddJobListener() {
29         String JavaDoc[] listenerNames = new String JavaDoc[] {"X", "A", "B"};
30         
31         // Verify that a HashSet shuffles order, so we know that order test
32
// below is actually testing something
33
HashSet JavaDoc hashSet = new HashSet JavaDoc(Arrays.asList(listenerNames));
34         assertFalse(Arrays.asList(listenerNames).equals(new ArrayList JavaDoc(hashSet)));
35         
36         JobDetail jobDetail = new JobDetail();
37         for (int i = 0; i < listenerNames.length; i++) {
38             jobDetail.addJobListener(listenerNames[i]);
39         }
40
41         // Make sure order was maintained
42
assertEquals(Arrays.asList(listenerNames),
43                      Arrays.asList(jobDetail.getJobListenerNames()));
44         
45         // Make sure uniqueness is enforced
46
for (int i = 0; i < listenerNames.length; i++) {
47             try {
48                 jobDetail.addJobListener(listenerNames[i]);
49                 fail();
50             } catch (IllegalArgumentException JavaDoc e) {
51             }
52         }
53     }
54     
55     public void testClone() {
56         JobDetail jobDetail = new JobDetail();
57         jobDetail.addJobListener("A");
58         
59         JobDetail clonedJobDetail = (JobDetail)jobDetail.clone();
60         assertEquals(Arrays.asList(clonedJobDetail.getJobListenerNames()),
61                      Arrays.asList(jobDetail.getJobListenerNames()));
62         
63         jobDetail.addJobListener("B");
64         
65         // Verify deep clone of jobListenerNames
66
assertTrue(Arrays.asList(jobDetail.getJobListenerNames()).contains("A"));
67         assertTrue(Arrays.asList(jobDetail.getJobListenerNames()).contains("B"));
68         assertTrue(Arrays.asList(clonedJobDetail.getJobListenerNames()).contains("A"));
69         assertFalse(Arrays.asList(clonedJobDetail.getJobListenerNames()).contains("B"));
70     }
71 }
72
Popular Tags