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 AndFilterTest extends TestCase { 62 63 public void testNullArgs() { 64 PacketFilter filter = null; 65 try { 66 AndFilter and = new AndFilter(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 AndFilter andFilter = new AndFilter(trueFilter, trueFilter); 81 assertTrue(andFilter.accept(packet)); 82 83 andFilter = new AndFilter(trueFilter, falseFilter); 84 assertFalse(andFilter.accept(packet)); 85 86 andFilter = new AndFilter(falseFilter, trueFilter); 87 assertFalse(andFilter.accept(packet)); 88 89 andFilter = new AndFilter(falseFilter, falseFilter); 90 assertFalse(andFilter.accept(packet)); 91 92 andFilter = new AndFilter(); 93 andFilter.addFilter(trueFilter); 94 andFilter.addFilter(trueFilter); 95 andFilter.addFilter(falseFilter); 96 andFilter.addFilter(trueFilter); 97 assertFalse(andFilter.accept(packet)); 98 } 99 } 100 | Popular Tags |