01: package net.jforum.entities;
02:
03: import junit.framework.Assert;
04: import junit.framework.TestCase;
05:
06: /**
07: * @author Rafael Steil
08: * @version $Id: BanlistTestCase.java,v 1.1 2006/12/12 00:44:50 rafaelsteil Exp $
09: */
10: public class BanlistTestCase extends TestCase {
11: public void testMatchIpUsingOnlyStarsExpectsFalse() {
12: Banlist b = this .newBanlist(0, null, "*.*.*.*");
13: Assert.assertFalse(b.matches(this .newBanlist(0, null,
14: "172.55.7.2")));
15: }
16:
17: public void testMatchIpUsingStarExpectsTrue2() {
18: Banlist b = this .newBanlist(0, null, "172.*.7.2");
19: Assert.assertTrue(b.matches(this .newBanlist(0, null,
20: "172.55.7.2")));
21: }
22:
23: public void testMatchIpUsingStarExpectsTrue() {
24: Banlist b = this .newBanlist(0, null, "*.168.7.*");
25: Assert.assertTrue(b.matches(this .newBanlist(0, null,
26: "172.168.7.2")));
27: }
28:
29: public void testMatchIpUsingStarExpectsFalse2() {
30: Banlist b = this .newBanlist(0, null, "*.168.7.*");
31: Assert.assertFalse(b.matches(this .newBanlist(0, null,
32: "172.168.1.2")));
33: }
34:
35: public void testMatchIpUsingStarExpectsFalse() {
36: Banlist b = this .newBanlist(0, null, "192.168.7.*");
37: Assert.assertFalse(b.matches(this .newBanlist(0, null,
38: "192.168.1.2")));
39: }
40:
41: public void testMatchIpUsingDifferentLengthExpectsFalse() {
42: Banlist b = this .newBanlist(0, null, "192.168.7");
43: Assert.assertFalse(b.matches(this .newBanlist(0, null,
44: "192.168.1.2")));
45: }
46:
47: public void testMatchIpExpectsTrue() {
48: Banlist b = this .newBanlist(0, "email@3", "192.168.1.1");
49: Assert.assertTrue(b.matches(this .newBanlist(0, "email@2",
50: "192.168.1.1")));
51: }
52:
53: public void testMatchIpExpectsFalse() {
54: Banlist b = this .newBanlist(0, null, "192.168.1.1");
55: Assert.assertFalse(b.matches(this .newBanlist(0, null,
56: "192.168.1.2")));
57: }
58:
59: public void testMatchEmailExpectsTrue() {
60: Banlist b = this .newBanlist(0, "email@2", null);
61: Assert.assertTrue(b
62: .matches(this .newBanlist(0, "email@2", null)));
63: }
64:
65: public void testMatchEmailExpectsFalse() {
66: Banlist b = this .newBanlist(0, "email@1", null);
67: Assert.assertFalse(b.matches(this
68: .newBanlist(0, "email@2", null)));
69: }
70:
71: public void testMatchUserIdExpectsTrue() {
72: Banlist b = this .newBanlist(2, null, null);
73: Assert.assertTrue(b.matches(this .newBanlist(2, null, null)));
74: }
75:
76: public void testMatchUserIdExpectsFalse() {
77: Banlist b = this .newBanlist(1, null, null);
78: Assert.assertFalse(b.matches(this .newBanlist(2, null, null)));
79: }
80:
81: private Banlist newBanlist(int userId, String email, String ip) {
82: Banlist b = new Banlist();
83:
84: b.setUserId(userId);
85: b.setEmail(email);
86: b.setIp(ip);
87:
88: return b;
89: }
90: }
|