1 52 53 package org.jivesoftware.smack.filter; 54 55 import junit.framework.TestCase; 56 import org.jivesoftware.smack.packet.*; 57 58 61 public class OrFilterTest extends TestCase { 62 63 public void testNullArgs() { 64 PacketFilter filter = null; 65 try { 66 OrFilter or = new OrFilter(filter, filter); 67 fail("Should have thrown IllegalArgumentException"); 68 } 69 catch (IllegalArgumentException e) { 70 assertTrue(true); 71 } 72 } 73 74 public void testAccept() { 75 MockPacketFilter trueFilter = new MockPacketFilter(true); 76 MockPacketFilter falseFilter = new MockPacketFilter(false); 77 78 MockPacket packet = new MockPacket(); 79 80 OrFilter orFilter = new OrFilter(trueFilter, trueFilter); 82 assertTrue(orFilter.accept(packet)); 83 84 orFilter = new OrFilter(trueFilter, falseFilter); 86 assertTrue(orFilter.accept(packet)); 87 88 orFilter = new OrFilter(falseFilter, trueFilter); 90 assertTrue(orFilter.accept(packet)); 91 92 orFilter = new OrFilter(falseFilter, falseFilter); 94 assertFalse(orFilter.accept(packet)); 95 96 orFilter = new OrFilter( 98 new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, trueFilter) 99 ); 100 assertTrue(orFilter.accept(packet)); 101 102 orFilter = new OrFilter( 104 new OrFilter(trueFilter, falseFilter), new OrFilter(trueFilter, trueFilter) 105 ); 106 assertTrue(orFilter.accept(packet)); 107 108 orFilter = new OrFilter( 110 new OrFilter(trueFilter, trueFilter), new OrFilter(falseFilter, trueFilter) 111 ); 112 assertTrue(orFilter.accept(packet)); 113 114 orFilter = new OrFilter( 116 new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, falseFilter) 117 ); 118 assertTrue(orFilter.accept(packet)); 119 120 orFilter = new OrFilter( 122 new OrFilter(falseFilter, falseFilter), new OrFilter(falseFilter, falseFilter) 123 ); 124 assertFalse(orFilter.accept(packet)); 125 126 orFilter = new OrFilter(); 127 orFilter.addFilter(trueFilter); 128 orFilter.addFilter(trueFilter); 129 orFilter.addFilter(falseFilter); 130 orFilter.addFilter(trueFilter); 131 assertTrue(orFilter.accept(packet)); 132 } 133 } 134 | Popular Tags |