KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > config > ProjectFilterSettingsTest


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2004, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.config;
21
22 import junit.framework.Assert;
23 import junit.framework.TestCase;
24 import edu.umd.cs.findbugs.Detector;
25 import edu.umd.cs.findbugs.I18N;
26
27 public class ProjectFilterSettingsTest extends TestCase {
28     ProjectFilterSettings plain;
29     ProjectFilterSettings otherPlain;
30     ProjectFilterSettings changed;
31     ProjectFilterSettings changed2;
32     ProjectFilterSettings changed3;
33     ProjectFilterSettings changed4;
34
35     @Override JavaDoc
36          protected void setUp() {
37         plain = ProjectFilterSettings.createDefault();
38
39         otherPlain = ProjectFilterSettings.createDefault();
40
41         changed = ProjectFilterSettings.createDefault();
42         changed.setMinPriority("High");
43
44         changed2 = ProjectFilterSettings.createDefault();
45         changed2.removeCategory("MALICIOUS_CODE");
46
47         changed3 = ProjectFilterSettings.createDefault();
48         changed3.addCategory("FAKE_CATEGORY");
49
50         changed4 = ProjectFilterSettings.createDefault();
51         changed4.setMinPriority("High");
52         changed4.removeCategory("MALICIOUS_CODE");
53         changed4.addCategory("FAKE_CATEGORY");
54         
55     }
56
57     public void testPlainPrio() {
58         Assert.assertTrue(plain.getMinPriority().equals(ProjectFilterSettings.DEFAULT_PRIORITY));
59     }
60
61     public void testPlainCategories() {
62         int count = 0;
63         for (String JavaDoc category : I18N.instance().getBugCategories()) {
64             Assert.assertTrue(plain.containsCategory(category));
65             ++count;
66         }
67         Assert.assertTrue(plain.getActiveCategorySet().size() == count);
68     }
69
70     public void testAddCategory() {
71         Assert.assertTrue(plain.containsCategory("FAKE_CATEGORY")); // unkown categories should be unhidden by default
72
plain.addCategory("FAKE_CATEGORY");
73         Assert.assertTrue(plain.containsCategory("FAKE_CATEGORY"));
74     }
75
76     public void testRemoveCategory() {
77         Assert.assertTrue(plain.containsCategory("MALICIOUS_CODE"));
78         plain.removeCategory("MALICIOUS_CODE");
79         Assert.assertFalse(plain.containsCategory("MALICIOUS_CODE"));
80     }
81
82     public void testSetMinPriority() {
83         plain.setMinPriority("High");
84         Assert.assertTrue(plain.getMinPriority().equals("High"));
85         Assert.assertTrue(plain.getMinPriorityAsInt() == Detector.HIGH_PRIORITY);
86         plain.setMinPriority("Medium");
87         Assert.assertTrue(plain.getMinPriority().equals("Medium"));
88         Assert.assertTrue(plain.getMinPriorityAsInt() == Detector.NORMAL_PRIORITY);
89         plain.setMinPriority("Low");
90         Assert.assertTrue(plain.getMinPriority().equals("Low"));
91         Assert.assertTrue(plain.getMinPriorityAsInt() == Detector.LOW_PRIORITY);
92     }
93
94     public void testEquals() {
95         Assert.assertEquals(plain, otherPlain);
96
97         Assert.assertFalse(plain.equals(changed));
98         Assert.assertFalse(changed.equals(plain));
99
100         Assert.assertFalse(plain.equals(changed2));
101         Assert.assertFalse(changed2.equals(plain));
102
103         // The activeBugCategorySet doesn't matter for equals(), only
104
// the hiddenBugCategorySet does (along with minPriority and
105
// displayFalseWarnings) so 'plain' and 'changed3' should test equal.
106
Assert.assertTrue(plain.equals(changed3));
107         Assert.assertTrue(changed3.equals(plain));
108
109         Assert.assertFalse(plain.equals(changed4));
110         Assert.assertFalse(changed4.equals(plain));
111     }
112
113     public void testEncodeDecode() {
114         ProjectFilterSettings copyOfPlain =
115             ProjectFilterSettings.fromEncodedString(plain.toEncodedString());
116         ProjectFilterSettings.hiddenFromEncodedString(copyOfPlain, plain.hiddenToEncodedString());
117         Assert.assertEquals(plain, copyOfPlain);
118
119         ProjectFilterSettings copyOfChanged4 =
120             ProjectFilterSettings.fromEncodedString(changed4.toEncodedString());
121         ProjectFilterSettings.hiddenFromEncodedString(copyOfChanged4, changed4.hiddenToEncodedString());
122         Assert.assertEquals(changed4, copyOfChanged4);
123     }
124     
125     public void testDisplayFalseWarnings() {
126         Assert.assertEquals(plain, otherPlain);
127
128         Assert.assertFalse(plain.displayFalseWarnings());
129         plain.setDisplayFalseWarnings(true);
130         
131         Assert.assertFalse(plain.equals(otherPlain));
132         
133         ProjectFilterSettings copyOfPlain =
134             ProjectFilterSettings.fromEncodedString(plain.toEncodedString());
135         
136         Assert.assertTrue(copyOfPlain.displayFalseWarnings());
137         Assert.assertEquals(copyOfPlain, plain);
138         Assert.assertEquals(plain, copyOfPlain);
139     }
140 }
141
142 // vim:ts=4
143
Popular Tags