1 19 20 package org.openidex.search; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import junit.textui.TestRunner; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.junit.NbTestSuite; 27 28 29 33 public final class SearchHistoryTest extends NbTestCase { 34 35 36 38 public SearchHistoryTest(String name) { 39 super(name); 40 } 41 42 44 public static void main(String args[]) { 45 TestRunner.run(new NbTestSuite(SearchHistoryTest.class)); 46 } 47 48 49 51 public void testSearchPatternSize() throws Exception { 52 assertSize("SearchPattern size", 80, SearchPattern.create("searchText",true,true,false)); 53 } 54 55 public void testSearchHistoryListSize() throws Exception { 56 for (int i = 0; i<60; i++){ 57 SearchHistory.getDefault().add(SearchPattern.create(String.valueOf(i),true,true,false)); 58 } 59 assertTrue(SearchHistory.getDefault().getSearchPatterns().size() == 50); 60 } 61 62 public void testLastSelectedListener() throws Exception { 63 final boolean fired[] = new boolean[1]; 64 fired[0] = false; 65 PropertyChangeListener pcl = new PropertyChangeListener (){ 66 public void propertyChange(PropertyChangeEvent evt){ 67 if (evt!=null && SearchHistory.LAST_SELECTED.equals(evt.getPropertyName())){ 68 fired[0] = true; 69 } 70 } 71 }; 72 SearchHistory.getDefault().addPropertyChangeListener(pcl); 73 SearchHistory.getDefault().setLastSelected(SearchPattern.create("searchtext",true,true,false)); 74 SearchHistory.getDefault().removePropertyChangeListener(pcl); 75 assertTrue(fired[0]); 76 } 77 78 public void testAddToSearchHistoryListener() throws Exception { 79 final boolean fired[] = new boolean[2]; 80 PropertyChangeListener pcl = new PropertyChangeListener (){ 81 public void propertyChange(PropertyChangeEvent evt){ 82 if (evt!=null && SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())){ 83 fired[0] = true; 84 }else{ 85 fired[1] = true; 86 } 87 } 88 }; 89 SearchHistory.getDefault().addPropertyChangeListener(pcl); 90 SearchHistory.getDefault().add(SearchPattern.create("searchtext",true,true,false)); 91 SearchHistory.getDefault().removePropertyChangeListener(pcl); 92 assertTrue(fired[0]); 93 assertFalse("Only the expected change is fired", fired[1]); 94 } 95 96 public void testAddIncorrectItemToSearchHistoryListener() throws Exception { 97 final boolean fired[] = new boolean[2]; 98 99 PropertyChangeListener pcl = new PropertyChangeListener (){ 100 public void propertyChange(PropertyChangeEvent evt){ 101 if (evt!=null && SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())){ 102 fired[0] = true; 103 } else { 104 fired[1] = true; 105 } 106 } 107 }; 108 SearchHistory.getDefault().addPropertyChangeListener(pcl); 109 110 fired[0] = false; 112 fired[1] = false; 113 SearchHistory.getDefault().add(SearchPattern.create("searchtext2",true,true,false)); 114 assertTrue(fired[0]); 115 assertFalse("Only the expected change is fired", fired[1]); 116 117 fired[0] = false; 119 fired[1] = false; 120 SearchHistory.getDefault().add(SearchPattern.create("searchtext2",true,true,false)); 121 assertTrue(!fired[0]); 122 assertFalse("Only the expected change is fired", fired[1]); 123 124 fired[0] = false; 126 fired[1] = false; 127 SearchHistory.getDefault().add(null); 128 assertTrue(!fired[0]); 129 assertFalse("Only the expected change is fired", fired[1]); 130 131 fired[0] = false; 133 fired[1] = false; 134 SearchHistory.getDefault().add(SearchPattern.create(null,true,true,false)); 135 assertTrue(!fired[0]); 136 assertFalse("Only the expected change is fired", fired[1]); 137 138 fired[0] = false; 140 fired[1] = false; 141 SearchHistory.getDefault().add(SearchPattern.create("",true,true,false)); 142 assertTrue(!fired[0]); 143 assertFalse("Only the expected change is fired", fired[1]); 144 145 SearchHistory.getDefault().removePropertyChangeListener(pcl); 146 } 147 148 149 public void testEquals() throws Exception { 150 SearchPattern pattern_one = SearchPattern.create("one",false, false, false); 151 SearchPattern pattern_one_a = SearchPattern.create("one",true, false, false); 152 SearchPattern pattern_one_b = SearchPattern.create("one",false, true, false); 153 SearchPattern pattern_one_c = SearchPattern.create("one",false,false, true); 154 SearchPattern pattern_one_d = SearchPattern.create("one",true,true, false); 155 SearchPattern pattern_one_e = SearchPattern.create("one",true,false, true); 156 SearchPattern pattern_one_f = SearchPattern.create("one",true,true, true); 157 158 SearchPattern pattern_two = SearchPattern.create("two",false, false, false); 159 SearchPattern pattern_TwO = SearchPattern.create("TwO",false, false, false); 160 SearchPattern pattern_TwO_a = SearchPattern.create("TwO",false, true, false); 161 162 SearchPattern pattern_one_test = SearchPattern.create("one",false, false, false); 163 SearchPattern pattern_one_a_test = SearchPattern.create("one",true, false, false); 164 SearchPattern pattern_one_b_test = SearchPattern.create("one",false, true, false); 165 SearchPattern pattern_one_c_test = SearchPattern.create("one",false,false, true); 166 SearchPattern pattern_one_d_test = SearchPattern.create("one",true,true, false); 167 SearchPattern pattern_one_e_test = SearchPattern.create("one",true,false, true); 168 SearchPattern pattern_one_f_test = SearchPattern.create("one",true,true, true); 169 170 SearchPattern pattern_two_test = SearchPattern.create("two",false, false, false); 171 SearchPattern pattern_TwO_test = SearchPattern.create("TwO",false, false, false); 172 SearchPattern pattern_TwO_a_test = SearchPattern.create("TwO",false, true, false); 173 174 assertTrue(pattern_one.equals(pattern_one_test)); 175 assertTrue(pattern_one_test.equals(pattern_one)); 176 assertTrue(pattern_one_a_test.equals(pattern_one_a)); 177 assertTrue(pattern_one_b_test.equals(pattern_one_b)); 178 assertTrue(pattern_one_c_test.equals(pattern_one_c)); 179 assertTrue(pattern_one_d_test.equals(pattern_one_d)); 180 assertTrue(pattern_one_e_test.equals(pattern_one_e)); 181 assertTrue(pattern_one_f_test.equals(pattern_one_f)); 182 assertTrue(!pattern_one_a_test.equals(pattern_one_b)); 184 assertTrue(!pattern_one_a_test.equals(pattern_one_c)); 185 assertTrue(!pattern_one_b_test.equals(pattern_one_c)); 186 assertTrue(!pattern_one_d_test.equals(pattern_one_e)); 187 188 assertTrue(pattern_two.equals(pattern_two_test)); 189 assertTrue(pattern_TwO.equals(pattern_TwO_test)); 190 assertTrue(pattern_TwO_a.equals(pattern_TwO_a_test)); 191 assertTrue(!pattern_two.equals(pattern_TwO_test)); 192 assertTrue(!pattern_TwO_a.equals(pattern_TwO_test)); 193 } 194 195 public void testHashCode() throws Exception { 196 int pattern_one = SearchPattern.create("one",false, false, false).hashCode(); 197 int pattern_one_a = SearchPattern.create("one",true, false, false).hashCode(); 198 int pattern_one_b = SearchPattern.create("one",false, true, false).hashCode(); 199 int pattern_one_c = SearchPattern.create("one",false,false, true).hashCode(); 200 int pattern_one_d = SearchPattern.create("one",true,true, false).hashCode(); 201 int pattern_one_e = SearchPattern.create("one",true,false, true).hashCode(); 202 int pattern_one_f = SearchPattern.create("one",true,true, true).hashCode(); 203 204 int pattern_two = SearchPattern.create("two",false, false, false).hashCode(); 205 int pattern_TwO = SearchPattern.create("TwO",false, false, false).hashCode(); 206 int pattern_TwO_a = SearchPattern.create("TwO",false, true, false).hashCode(); 207 208 int pattern_one_test = SearchPattern.create("one",false, false, false).hashCode(); 209 int pattern_one_a_test = SearchPattern.create("one",true, false, false).hashCode(); 210 int pattern_one_b_test = SearchPattern.create("one",false, true, false).hashCode(); 211 int pattern_one_c_test = SearchPattern.create("one",false,false, true).hashCode(); 212 int pattern_one_d_test = SearchPattern.create("one",true,true, false).hashCode(); 213 int pattern_one_e_test = SearchPattern.create("one",true,false, true).hashCode(); 214 int pattern_one_f_test = SearchPattern.create("one",true,true, true).hashCode(); 215 216 int pattern_two_test = SearchPattern.create("two",false, false, false).hashCode(); 217 int pattern_TwO_test = SearchPattern.create("TwO",false, false, false).hashCode(); 218 int pattern_TwO_a_test = SearchPattern.create("TwO",false, true, false).hashCode(); 219 220 assertTrue(pattern_one == pattern_one_test); 221 assertTrue(pattern_one_test == pattern_one); 222 assertTrue(pattern_one_a_test == pattern_one_a); 223 assertTrue(pattern_one_b_test == pattern_one_b); 224 assertTrue(pattern_one_c_test == pattern_one_c); 225 assertTrue(pattern_one_d_test == pattern_one_d); 226 assertTrue(pattern_one_e_test == pattern_one_e); 227 assertTrue(pattern_one_f_test == pattern_one_f); 228 assertTrue(pattern_one_a_test != pattern_one_b); 230 assertTrue(pattern_one_a_test != pattern_one_c); 231 assertTrue(pattern_one_b_test != pattern_one_c); 232 assertTrue(pattern_one_d_test != pattern_one_e); 233 234 assertTrue(pattern_two == pattern_two_test); 235 assertTrue(pattern_TwO == pattern_TwO_test); 236 assertTrue(pattern_TwO_a == pattern_TwO_a_test); 237 assertTrue(pattern_two != pattern_TwO_test); 238 assertTrue(pattern_TwO_a != pattern_TwO_test); 239 } 240 241 } 242 | Popular Tags |