KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > AnnotationLoadingTest


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.editor;
21
22 import java.net.URL JavaDoc;
23 import java.awt.Color JavaDoc;
24 import junit.framework.TestCase;
25 import org.netbeans.editor.AnnotationType;
26 import org.netbeans.editor.AnnotationTypes;
27
28 /**
29  *
30  * @author Jan Lahoda
31  */

32 public class AnnotationLoadingTest extends TestCase {
33
34     public AnnotationLoadingTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     // TODO add test methods here. The name must begin with 'test'. For example:
39
// public void testHello() {}
40

41     protected void setUp() throws Exception JavaDoc {
42         EditorTestLookup.setLookup(
43                 new URL JavaDoc[] {
44             EditorTestConstants.EDITOR_LAYER_URL,
45                     getClass().getClassLoader().getResource(
46                     "org/netbeans/modules/editor/resources/annotations-test-layer.xml")
47         },
48                 new Object JavaDoc[] {},
49                 getClass().getClassLoader()
50                 );
51                 
52                 AnnotationTypes.getTypes().registerLoader(new AnnotationsTest.AnnotationsLoader());
53     }
54
55     public void testAnnotationStatusAndColorRead() {
56 // <file name="test-annotation-1">
57
// <attr name="AnnotationStatus" stringvalue="error" />
58
// </file>
59
assertEquals(AnnotationType.Severity.STATUS_ERROR, AnnotationTypes.getTypes().getType("test-annotation-1").getSeverity());
60         assertEquals(false, AnnotationTypes.getTypes().getType("test-annotation-1").isUseCustomSidebarColor());
61         assertEquals(0, AnnotationTypes.getTypes().getType("test-annotation-1").getPriority());
62 // <file name="test-annotation-2">
63
// <attr name="AnnotationStatus" stringvalue="warning" />
64
// <attr name="priority" stringvalue="100" />
65
// </file>
66
assertEquals(AnnotationType.Severity.STATUS_WARNING, AnnotationTypes.getTypes().getType("test-annotation-2").getSeverity());
67         assertEquals(false, AnnotationTypes.getTypes().getType("test-annotation-2").isUseCustomSidebarColor());
68         assertEquals(100, AnnotationTypes.getTypes().getType("test-annotation-2").getPriority());
69 // <file name="test-annotation-3">
70
// <attr name="AnnotationStatus" stringvalue="ok" />
71
// </file>
72
assertEquals(AnnotationType.Severity.STATUS_OK, AnnotationTypes.getTypes().getType("test-annotation-3").getSeverity());
73         assertEquals(false, AnnotationTypes.getTypes().getType("test-annotation-3").isUseCustomSidebarColor());
74 // <file name="test-annotation-4">
75
// <attr name="AnnotationStatus" stringvalue="error" />
76
// <attr name="color" stringvalue="0x000000" />
77
// </file>
78
assertEquals(AnnotationType.Severity.STATUS_ERROR, AnnotationTypes.getTypes().getType("test-annotation-4").getSeverity());
79         assertEquals(true, AnnotationTypes.getTypes().getType("test-annotation-4").isUseCustomSidebarColor());
80         assertEquals(new Color JavaDoc(0, 0, 0), AnnotationTypes.getTypes().getType("test-annotation-4").getCustomSidebarColor());
81 // <file name="test-annotation-5">
82
// <attr name="AnnotationStatus" stringvalue="warning" />
83
// <attr name="color" stringvalue="0x000000" />
84
// </file>
85
assertEquals(AnnotationType.Severity.STATUS_WARNING, AnnotationTypes.getTypes().getType("test-annotation-5").getSeverity());
86         assertEquals(true, AnnotationTypes.getTypes().getType("test-annotation-5").isUseCustomSidebarColor());
87         assertEquals(new Color JavaDoc(0, 0, 0), AnnotationTypes.getTypes().getType("test-annotation-5").getCustomSidebarColor());
88 // <file name="test-annotation-6">
89
// <attr name="AnnotationStatus" stringvalue="ok" />
90
// <attr name="color" stringvalue="0x000000" />
91
// </file>
92
assertEquals(AnnotationType.Severity.STATUS_OK, AnnotationTypes.getTypes().getType("test-annotation-6").getSeverity());
93         assertEquals(true, AnnotationTypes.getTypes().getType("test-annotation-6").isUseCustomSidebarColor());
94         assertEquals(new Color JavaDoc(0, 0, 0), AnnotationTypes.getTypes().getType("test-annotation-6").getCustomSidebarColor());
95 // <file name="test-annotation-7">
96
// <attr name="AnnotationStatus" stringvalue="ok" />
97
// <attr name="color" stringvalue="unparseable" />
98
// </file>
99
//not possible, throws exception
100
// assertEquals(AnnotationType.Severity.STATUS_OK, AnnotationTypes.getTypes().getType("test-annotation-7").getSeverity());
101
// assertEquals(false, AnnotationTypes.getTypes().getType("test-annotation-7").isUseCustomSidebarColor());
102
// <file name="test-annotation-8">
103
// <attr name="AnnotationStatus" stringvalue="unknown" />
104
// </file>
105
assertEquals(AnnotationType.Severity.STATUS_NONE, AnnotationTypes.getTypes().getType("test-annotation-8").getSeverity());
106         assertEquals(false, AnnotationTypes.getTypes().getType("test-annotation-8").isUseCustomSidebarColor());
107 // <file name="test-annotation-browseable-1">
108
// <attr name="AnnotationStatus" stringvalue="unknown" />
109
// <attr name="browseable" boolvalue="true" />
110
// </file>
111
assertTrue(AnnotationTypes.getTypes().getType("test-annotation-browseable-1").isBrowseable());
112 // <file name="test-annotation-browseable-2">
113
// <attr name="AnnotationStatus" stringvalue="unknown" />
114
// <attr name="browseable" boolvalue="false" />
115
// </file>
116
assertFalse(AnnotationTypes.getTypes().getType("test-annotation-browseable-2").isBrowseable());
117     }
118     
119 // public void testEquals() {
120
// AnnotationStatus testAnnotationStatus = StatusForAnnotationTypeQuery.getDefault().getStatusForAnnotationType("test-annotation-5");
121
//
122
// assertFalse(testAnnotationStatus.equals(null));
123
// assertFalse(testAnnotationStatus.equals("test"));
124
// assertFalse(testAnnotationStatus.equals(new AnnotationStatus(Status.STATUS_OK)));
125
// assertFalse(testAnnotationStatus.equals(new AnnotationStatus(Status.STATUS_WARNING)));
126
// assertFalse(testAnnotationStatus.equals(new AnnotationStatus(Status.STATUS_OK, new Color(0, 0, 0))));
127
//
128
// assertTrue(testAnnotationStatus.equals(new AnnotationStatus(Status.STATUS_WARNING, new Color(0, 0, 0))));
129
// }
130

131     public void testNotFoundAnnotation() {
132         assertNull(AnnotationTypes.getTypes().getType("non-existent"));
133     }
134     
135 }
136
Popular Tags