BanlistTestCase.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 2k
Category:

Java Develop

Development Platform:

Java

  1. package net.jforum.entities;
  2. import junit.framework.Assert;
  3. import junit.framework.TestCase;
  4. /**
  5.  * @author Rafael Steil
  6.  * @version $Id: BanlistTestCase.java,v 1.1 2006/12/12 00:44:50 rafaelsteil Exp $
  7.  */
  8. public class BanlistTestCase extends TestCase {
  9. public void testMatchIpUsingOnlyStarsExpectsFalse() {
  10. Banlist b = this.newBanlist(0, null, "*.*.*.*");
  11. Assert.assertFalse(b.matches(this.newBanlist(0, null, "172.55.7.2")));
  12. }
  13. public void testMatchIpUsingStarExpectsTrue2() {
  14. Banlist b = this.newBanlist(0, null, "172.*.7.2");
  15. Assert.assertTrue(b.matches(this.newBanlist(0, null, "172.55.7.2")));
  16. }
  17. public void testMatchIpUsingStarExpectsTrue() {
  18. Banlist b = this.newBanlist(0, null, "*.168.7.*");
  19. Assert.assertTrue(b.matches(this.newBanlist(0, null, "172.168.7.2")));
  20. }
  21. public void testMatchIpUsingStarExpectsFalse2() {
  22. Banlist b = this.newBanlist(0, null, "*.168.7.*");
  23. Assert.assertFalse(b.matches(this.newBanlist(0, null, "172.168.1.2")));
  24. }
  25. public void testMatchIpUsingStarExpectsFalse() {
  26. Banlist b = this.newBanlist(0, null, "192.168.7.*");
  27. Assert.assertFalse(b.matches(this.newBanlist(0, null, "192.168.1.2")));
  28. }
  29. public void testMatchIpUsingDifferentLengthExpectsFalse() {
  30. Banlist b = this.newBanlist(0, null, "192.168.7");
  31. Assert.assertFalse(b.matches(this.newBanlist(0, null, "192.168.1.2")));
  32. }
  33. public void testMatchIpExpectsTrue() {
  34. Banlist b = this.newBanlist(0, "email@3", "192.168.1.1");
  35. Assert.assertTrue(b.matches(this.newBanlist(0, "email@2", "192.168.1.1")));
  36. }
  37. public void testMatchIpExpectsFalse() {
  38. Banlist b = this.newBanlist(0, null, "192.168.1.1");
  39. Assert.assertFalse(b.matches(this.newBanlist(0, null, "192.168.1.2")));
  40. }
  41. public void testMatchEmailExpectsTrue() {
  42. Banlist b = this.newBanlist(0, "email@2", null);
  43. Assert.assertTrue(b.matches(this.newBanlist(0, "email@2", null)));
  44. }
  45. public void testMatchEmailExpectsFalse() {
  46. Banlist b = this.newBanlist(0, "email@1", null);
  47. Assert.assertFalse(b.matches(this.newBanlist(0, "email@2", null)));
  48. }
  49. public void testMatchUserIdExpectsTrue() {
  50. Banlist b = this.newBanlist(2, null, null);
  51. Assert.assertTrue(b.matches(this.newBanlist(2, null, null)));
  52. }
  53. public void testMatchUserIdExpectsFalse() {
  54. Banlist b = this.newBanlist(1, null, null);
  55. Assert.assertFalse(b.matches(this.newBanlist(2, null, null)));
  56. }
  57. private Banlist newBanlist(int userId, String email, String ip) {
  58. Banlist b = new Banlist();
  59. b.setUserId(userId);
  60. b.setEmail(email);
  61. b.setIp(ip);
  62. return b;
  63. }
  64. }