1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Added slightly more robust tetsing of OrFilter and PacketTypeFilter... can't break it :)

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2070 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Bill Lynch 2003-08-26 19:21:18 +00:00 committed by blynch
parent bceff343af
commit 3429142b5c
2 changed files with 102 additions and 12 deletions

View file

@ -77,16 +77,50 @@ public class OrFilterTest extends TestCase {
MockPacket packet = new MockPacket();
OrFilter OrFilter = new OrFilter(trueFilter, trueFilter);
assertTrue(OrFilter.accept(packet));
// Testing TT == T
OrFilter orFilter = new OrFilter(trueFilter, trueFilter);
assertTrue(orFilter.accept(packet));
OrFilter = new OrFilter(trueFilter, falseFilter);
assertTrue(OrFilter.accept(packet));
// Testing TF = F
orFilter = new OrFilter(trueFilter, falseFilter);
assertTrue(orFilter.accept(packet));
OrFilter = new OrFilter(falseFilter, trueFilter);
assertTrue(OrFilter.accept(packet));
// Testing FT = F
orFilter = new OrFilter(falseFilter, trueFilter);
assertTrue(orFilter.accept(packet));
OrFilter = new OrFilter(falseFilter, falseFilter);
assertFalse(OrFilter.accept(packet));
// Testing FF = F
orFilter = new OrFilter(falseFilter, falseFilter);
assertFalse(orFilter.accept(packet));
// Testing TTTT = T
orFilter = new OrFilter(
new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, trueFilter)
);
assertTrue(orFilter.accept(packet));
// Testing TFTT = F
orFilter = new OrFilter(
new OrFilter(trueFilter, falseFilter), new OrFilter(trueFilter, trueFilter)
);
assertTrue(orFilter.accept(packet));
// Testing TTFT = F
orFilter = new OrFilter(
new OrFilter(trueFilter, trueFilter), new OrFilter(falseFilter, trueFilter)
);
assertTrue(orFilter.accept(packet));
// Testing TTTF = F
orFilter = new OrFilter(
new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, falseFilter)
);
assertTrue(orFilter.accept(packet));
// Testing FFFF = F
orFilter = new OrFilter(
new OrFilter(falseFilter, falseFilter), new OrFilter(falseFilter, falseFilter)
);
assertFalse(orFilter.accept(packet));
}
}

View file

@ -56,36 +56,92 @@ import junit.framework.TestCase;
import org.jivesoftware.smack.packet.*;
/**
*
* Test cases for the PacketTypeFilter class.
*/
public class PacketTypeFilterTest extends TestCase {
private class Dummy {}
private class InnerClassDummy {
public class DummyPacket extends Packet {
public String toXML() {
return null;
}
}
public DummyPacket getInnerInstance() {
return new DummyPacket();
}
}
private static class StaticInnerClassDummy {
public static class StaticDummyPacket extends Packet {
public String toXML() {
return null;
}
}
public static StaticDummyPacket getInnerInstance() {
return new StaticDummyPacket();
}
}
/**
* Test case for the constructor of PacketTypeFilter objects.
*/
public void testConstructor() {
// Test a class that is not a subclass of Packet
try {
new PacketTypeFilter(Dummy.class);
fail("Parameter must be a subclass of Packet.");
}
catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {}
// Test a class that is a subclass of Packet
try {
new PacketTypeFilter(MockPacket.class);
}
catch (IllegalArgumentException e) {
fail();
}
// Test another class which is a subclass of Packet
try {
new PacketTypeFilter(IQ.class);
}
catch (IllegalArgumentException e) {
fail();
}
// Test an internal class which is a subclass of Packet
try {
new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
}
catch (IllegalArgumentException e) {
fail();
}
// Test an internal static class which is a static subclass of Packet
try {
new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
}
catch (IllegalArgumentException e) {
fail();
}
}
/**
* Test case to test the accept() method of PacketTypeFilter objects.
*/
public void testAccept() {
MockPacket packet = new MockPacket();
Packet packet = new MockPacket();
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class);
assertTrue(filter.accept(packet));
packet = (new InnerClassDummy()).getInnerInstance();
filter = new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
assertTrue(filter.accept(packet));
packet = StaticInnerClassDummy.getInnerInstance();
filter = new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
assertTrue(filter.accept(packet));
}
}