KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > NotifyExcPanelTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.concurrent.Callable JavaDoc;
25 import java.util.logging.Handler JavaDoc;
26 import java.util.logging.LogRecord JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import org.netbeans.junit.NbTestCase;
30
31 /**
32  *
33  * @author Jaroslav Tulach
34  */

35 public class NotifyExcPanelTest extends NbTestCase {
36     Logger JavaDoc main;
37     
38     public NotifyExcPanelTest(String JavaDoc testName) {
39         super(testName);
40     }
41     
42     protected void setUp() throws Exception JavaDoc {
43         main = Logger.getLogger("");
44         for (Handler JavaDoc h : main.getHandlers()) {
45             main.removeHandler(h);
46         }
47     }
48     
49     public void testHandlesThatImplementCallableForJButtonAreIncluded() throws Exception JavaDoc {
50         class H extends Handler JavaDoc
51         implements Callable JavaDoc<JButton JavaDoc> {
52             public JButton JavaDoc button = new JButton JavaDoc("Extra");
53         
54             public void publish(LogRecord JavaDoc arg0) {
55             }
56
57             public void flush() {
58             }
59
60             public void close() throws SecurityException JavaDoc {
61             }
62
63             public JButton JavaDoc call() throws Exception JavaDoc {
64                 return button;
65             }
66         } // end of H
67

68         H handler = new H();
69         
70         main.addHandler(handler);
71         
72         List JavaDoc<Object JavaDoc> options = Arrays.asList(NotifyExcPanel.computeOptions("prev", "next"));
73         
74         assertTrue("Contains our button: " + options, options.contains(handler.button));
75     }
76
77     public void testHandlesThatImplementCallableForOtherObjectsAreNotIncluded() throws Exception JavaDoc {
78         class H extends Handler JavaDoc
79         implements Callable JavaDoc<Object JavaDoc> {
80             public JButton JavaDoc button = new JButton JavaDoc("Extra");
81         
82             public void publish(LogRecord JavaDoc arg0) {
83             }
84
85             public void flush() {
86             }
87
88             public void close() throws SecurityException JavaDoc {
89             }
90
91             public JButton JavaDoc call() throws Exception JavaDoc {
92                 return button;
93             }
94         } // end of H
95

96         H handler = new H();
97         
98         main.addHandler(handler);
99         
100         List JavaDoc<Object JavaDoc> options = Arrays.asList(NotifyExcPanel.computeOptions("prev", "next"));
101         
102         assertFalse("Does not contain our button: " + options, options.contains(handler.button));
103     }
104 }
105
Popular Tags