mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-16 12:12: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:
parent
bceff343af
commit
3429142b5c
2 changed files with 102 additions and 12 deletions
|
@ -77,16 +77,50 @@ public class OrFilterTest extends TestCase {
|
||||||
|
|
||||||
MockPacket packet = new MockPacket();
|
MockPacket packet = new MockPacket();
|
||||||
|
|
||||||
OrFilter OrFilter = new OrFilter(trueFilter, trueFilter);
|
// Testing TT == T
|
||||||
assertTrue(OrFilter.accept(packet));
|
OrFilter orFilter = new OrFilter(trueFilter, trueFilter);
|
||||||
|
assertTrue(orFilter.accept(packet));
|
||||||
|
|
||||||
OrFilter = new OrFilter(trueFilter, falseFilter);
|
// Testing TF = F
|
||||||
assertTrue(OrFilter.accept(packet));
|
orFilter = new OrFilter(trueFilter, falseFilter);
|
||||||
|
assertTrue(orFilter.accept(packet));
|
||||||
|
|
||||||
OrFilter = new OrFilter(falseFilter, trueFilter);
|
// Testing FT = F
|
||||||
assertTrue(OrFilter.accept(packet));
|
orFilter = new OrFilter(falseFilter, trueFilter);
|
||||||
|
assertTrue(orFilter.accept(packet));
|
||||||
|
|
||||||
OrFilter = new OrFilter(falseFilter, falseFilter);
|
// Testing FF = F
|
||||||
assertFalse(OrFilter.accept(packet));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,36 +56,92 @@ import junit.framework.TestCase;
|
||||||
import org.jivesoftware.smack.packet.*;
|
import org.jivesoftware.smack.packet.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Test cases for the PacketTypeFilter class.
|
||||||
*/
|
*/
|
||||||
public class PacketTypeFilterTest extends TestCase {
|
public class PacketTypeFilterTest extends TestCase {
|
||||||
|
|
||||||
private class Dummy {}
|
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() {
|
public void testConstructor() {
|
||||||
|
// Test a class that is not a subclass of Packet
|
||||||
try {
|
try {
|
||||||
new PacketTypeFilter(Dummy.class);
|
new PacketTypeFilter(Dummy.class);
|
||||||
fail("Parameter must be a subclass of Packet.");
|
fail("Parameter must be a subclass of Packet.");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {}
|
||||||
}
|
|
||||||
|
// Test a class that is a subclass of Packet
|
||||||
try {
|
try {
|
||||||
new PacketTypeFilter(MockPacket.class);
|
new PacketTypeFilter(MockPacket.class);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test another class which is a subclass of Packet
|
||||||
try {
|
try {
|
||||||
new PacketTypeFilter(IQ.class);
|
new PacketTypeFilter(IQ.class);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
fail();
|
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() {
|
public void testAccept() {
|
||||||
MockPacket packet = new MockPacket();
|
Packet packet = new MockPacket();
|
||||||
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class);
|
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class);
|
||||||
assertTrue(filter.accept(packet));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue