1 21 22 package org.jacorb.test.notification; 23 24 import junit.framework.Test; 25 import junit.framework.TestCase; 26 import junit.framework.TestSuite; 27 28 import org.easymock.MockControl; 29 import org.jacorb.notification.FilterManager; 30 import org.omg.CosNotifyFilter.Filter; 31 import org.omg.CosNotifyFilter.FilterNotFound; 32 33 37 public class FilterManagerTest extends TestCase 38 { 39 private FilterManager objectUnderTest_; 40 41 private Filter mockFilter_; 42 43 private MockControl controlFilter_; 44 45 protected void setUp() throws Exception 46 { 47 super.setUp(); 48 49 objectUnderTest_ = new FilterManager(); 50 51 controlFilter_ = MockControl.createControl(Filter.class); 52 mockFilter_ = (Filter) controlFilter_.getMock(); 53 54 controlFilter_.replay(); 55 } 56 57 protected void tearDown() throws Exception 58 { 59 controlFilter_.verify(); 60 super.tearDown(); 61 } 62 63 public FilterManagerTest(String name) 64 { 65 super(name); 66 } 67 68 public void testAdd_filter() throws Exception 69 { 70 assertEquals(0, objectUnderTest_.get_all_filters().length); 71 72 objectUnderTest_.add_filter(mockFilter_); 73 74 assertEquals(1, objectUnderTest_.get_all_filters().length); 75 } 76 77 public void testRemove_filter() throws Exception 78 { 79 int id = objectUnderTest_.add_filter(mockFilter_); 80 81 assertEquals(1, objectUnderTest_.get_all_filters().length); 82 83 objectUnderTest_.remove_filter(id); 84 85 assertEquals(0, objectUnderTest_.get_all_filters().length); 86 87 try 88 { 89 objectUnderTest_.remove_filter(id); 90 fail(); 91 } catch (FilterNotFound e) 92 { 93 } 95 96 assertEquals(0, objectUnderTest_.get_all_filters().length); 97 } 98 99 public void testGet_filter() throws Exception 100 { 101 int id = objectUnderTest_.add_filter(mockFilter_); 102 103 assertEquals(mockFilter_, objectUnderTest_.get_filter(id)); 104 105 objectUnderTest_.remove_all_filters(); 106 107 try 108 { 109 objectUnderTest_.get_filter(id); 110 fail(); 111 } catch (FilterNotFound e) 112 { 113 } 115 } 116 117 public void testGet_all_filters() 118 { 119 assertEquals(0, objectUnderTest_.get_all_filters().length); 120 121 int id = objectUnderTest_.add_filter(mockFilter_); 122 123 int[] all = objectUnderTest_.get_all_filters(); 124 125 assertEquals(1, all.length); 126 127 assertEquals(id, all[0]); 128 } 129 130 public void testRemove_all_filters() 131 { 132 objectUnderTest_.add_filter(mockFilter_); 133 134 assertEquals(1, objectUnderTest_.get_all_filters().length); 135 136 objectUnderTest_.remove_all_filters(); 137 138 assertEquals(0, objectUnderTest_.get_all_filters().length); 139 } 140 141 public void testGetFilters() 142 { 143 assertTrue(objectUnderTest_.getFilters().isEmpty()); 144 145 objectUnderTest_.add_filter(mockFilter_); 146 assertEquals(1, objectUnderTest_.getFilters().size()); 147 assertEquals(mockFilter_, objectUnderTest_.getFilters().get(0)); 148 149 try { 150 objectUnderTest_.getFilters().clear(); 151 fail(); 152 } catch (Exception e) 153 { 154 } 156 157 objectUnderTest_.remove_all_filters(); 158 159 assertTrue(objectUnderTest_.getFilters().isEmpty()); 160 } 161 162 163 public static Test suite() 164 { 165 return new TestSuite(FilterManagerTest.class); 166 } 167 } | Popular Tags |