KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > highlight > DefaultHighlightManagerTest


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.modules.xml.xam.ui.highlight;
21
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28 import org.netbeans.modules.xml.schema.model.Schema;
29 import org.netbeans.modules.xml.schema.model.SchemaModel;
30 import org.netbeans.modules.xml.xam.Component;
31 import org.netbeans.modules.xml.xam.ui.Util;
32
33 /**
34  * Tests DefaultHighlightManager class.
35  *
36  * @author Nathan Fiedler
37  */

38 public class DefaultHighlightManagerTest extends TestCase {
39     private Schema schema;
40     private SchemaModel model;
41     
42     public DefaultHighlightManagerTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     @Override JavaDoc
47     protected void setUp() throws Exception JavaDoc {
48         model = Util.loadSchemaModel(Util.PO_XSD);
49         schema = model.getSchema();
50     }
51
52     @Override JavaDoc
53     protected void tearDown() throws Exception JavaDoc {
54     }
55
56     /**
57      * Test highlight group management.
58      */

59     public void testHighlightGroups() {
60         DefaultHighlightManager instance = new DefaultHighlightManager();
61         HighlightGroup group = new HighlightGroup("type");
62         group.addHighlight(new TestHighlight(schema, "a"));
63         group.addHighlight(new TestHighlight(schema, "b"));
64         group.addHighlight(new TestHighlight(schema, "c"));
65         instance.addHighlightGroup(group);
66         List JavaDoc<HighlightGroup> groups = instance.getHighlightGroups("type");
67         assertTrue(groups.contains(group));
68         assertEquals(1, groups.size());
69         instance.removeHighlightGroup(group);
70         groups = instance.getHighlightGroups("type");
71         assertFalse(groups.contains(group));
72         assertEquals(0, groups.size());
73     }
74
75     /**
76      * Test highlight listener management.
77      */

78     public void testHighlightListeners() {
79     DefaultHighlightManager instance = new DefaultHighlightManager();
80         TestLighter l1 = new TestLighter();
81         instance.addHighlighted(l1);
82         TestLighter l2 = new TestLighter();
83         instance.addHighlighted(l2);
84         instance.removeHighlighted(l1);
85         instance.removeHighlighted(l2);
86     }
87
88     private static class TestLighter implements Highlighted {
89
90         public Set JavaDoc<Component> getComponents() {
91             return Collections.emptySet();
92         }
93
94         public void highlightAdded(Highlight hl) {
95         }
96
97         public void highlightRemoved(Highlight hl) {
98         }
99     }
100 }
101
Popular Tags