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 FromContainsFilterTest extends TestCase { 62 63 public void testNullArgs() { 64 try { 65 new FromContainsFilter(null); 66 fail("Parameter can not be null"); 67 } 68 catch (IllegalArgumentException e) { 69 assertTrue(true); 70 } 71 } 72 73 public void testAccept() { 74 MockFromPacket packet = new MockFromPacket("foo@bar.com"); 75 76 FromContainsFilter fromContainsFilter = new FromContainsFilter(""); 77 assertTrue(fromContainsFilter.accept(packet)); 78 79 fromContainsFilter = new FromContainsFilter("foo"); 80 assertTrue(fromContainsFilter.accept(packet)); 81 82 fromContainsFilter = new FromContainsFilter("foo@bar.com"); 83 assertTrue(fromContainsFilter.accept(packet)); 84 85 fromContainsFilter = new FromContainsFilter("bar@foo.com"); 86 assertFalse(fromContainsFilter.accept(packet)); 87 88 fromContainsFilter = new FromContainsFilter("blah-stuff,net"); 89 assertFalse(fromContainsFilter.accept(packet)); 90 } 91 92 95 private class MockFromPacket extends MockPacket { 96 private String from; 97 public MockFromPacket(String from) { 98 this.from = from; 99 } 100 public String getFrom() { 101 return from; 102 } 103 } 104 } 105 | Popular Tags |