Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
53   143   6   8,83
0   76   0,11   6
6     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  LinkSpamListenerTest       Line # 43 53 0% 6 0 100% 1.0
 
  (10)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.event.response;
33   
34    import net.sourceforge.pebble.domain.*;
35    import net.sourceforge.pebble.api.event.comment.CommentEvent;
36    import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
37   
38    /**
39    * Tests for the LinkSpamListener class.
40    *
41    * @author Simon Brown
42    */
 
43    public class LinkSpamListenerTest extends SingleBlogTestCase {
44   
45    private LinkSpamListener listener;
46    private Comment comment;
47    private CommentEvent commentEvent;
48    private TrackBack trackBack;
49    private TrackBackEvent trackBackEvent;
50   
51    /**
52    * Common setup code.
53    */
 
54  10 toggle protected void setUp() throws Exception {
55  10 super.setUp();
56   
57  10 listener = new LinkSpamListener();
58  10 comment = new BlogEntry(blog).createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
59  10 commentEvent = new CommentEvent(comment, CommentEvent.COMMENT_ADDED);
60    }
61   
62    /**
63    * Tests a comment with no links.
64    */
 
65  2 toggle public void testCommentAddedWithNoLinks() {
66  2 assertTrue(comment.isApproved());
67  2 listener.commentAdded(commentEvent);
68  2 assertTrue(comment.isApproved());
69    }
70   
71    /**
72    * Tests a comment with two links, the default threshold being three.
73    */
 
74  2 toggle public void testCommentAddedWithTwoLinks() {
75  2 StringBuffer buf = new StringBuffer();
76  2 buf.append("Here is some content ...");
77  2 buf.append("<a href=\"http://www.somedomain1.com\">link</a>");
78  2 buf.append("<a href=\"http://www.somedomain2.com\">link</a>");
79  2 comment.setBody(buf.toString());
80  2 assertTrue(comment.isApproved());
81  2 listener.commentAdded(commentEvent);
82  2 assertTrue(comment.isApproved());
83   
84  2 blog.getPluginProperties().setProperty(LinkSpamListener.COMMENT_THRESHOLD_KEY, "1");
85  2 listener.commentAdded(commentEvent);
86  2 assertTrue(comment.isPending());
87    }
88   
89    /**
90    * Tests a comment with three links, the default threshold being three.
91    */
 
92  2 toggle public void testCommentAddedWithThreeLinks() {
93  2 StringBuffer buf = new StringBuffer();
94  2 buf.append("Here is some content ...");
95  2 buf.append("<a href=\"http://www.somedomain1.com\">link</a>");
96  2 buf.append("<a href=\"http://www.somedomain2.com\">link</a>");
97  2 buf.append("<a href=\"http://www.somedomain3.com\">link</a>");
98  2 comment.setBody(buf.toString());
99  2 assertTrue(comment.isApproved());
100  2 listener.commentAdded(commentEvent);
101  2 assertTrue(comment.isApproved());
102    }
103   
104    /**
105    * Tests a comment with four links, the default threshold being three.
106    */
 
107  2 toggle public void testCommentAddedWithFourLinks() {
108  2 StringBuffer buf = new StringBuffer();
109  2 buf.append("Here is some content ...");
110  2 buf.append("<a href=\"http://www.somedomain1.com\">link</a>");
111  2 buf.append("<a href=\"http://www.somedomain2.com\">link</a>");
112  2 buf.append("<A HREF=\"http://www.somedomain3.com\">link</A>");
113  2 buf.append("<a href=\"http://www.somedomain4.com\">link</a>");
114  2 comment.setBody(buf.toString());
115  2 assertTrue(comment.isApproved());
116  2 listener.commentAdded(commentEvent);
117  2 assertTrue(comment.isPending());
118   
119  2 comment.setApproved();
120  2 blog.getPluginProperties().setProperty(LinkSpamListener.COMMENT_THRESHOLD_KEY, "4");
121  2 listener.commentAdded(commentEvent);
122  2 assertTrue(comment.isApproved());
123    }
124   
125    /**
126    * Tests that the spam score is increased if the link threshold is exceeded.
127    */
 
128  2 toggle public void testSpamScoreIncremented() {
129  2 StringBuffer buf = new StringBuffer();
130  2 buf.append("Here is some content ...");
131  2 buf.append("<a href=\"http://www.somedomain1.com\">link</a>");
132  2 buf.append("<a href=\"http://www.somedomain2.com\">link</a>");
133  2 buf.append("<A HREF=\"http://www.somedomain3.com\">link</A>");
134  2 buf.append("<a href=\"http://www.somedomain4.com\">link</a>");
135  2 comment.setBody(buf.toString());
136  2 assertTrue(comment.isApproved());
137  2 assertEquals(0, comment.getSpamScore());
138  2 listener.commentAdded(commentEvent);
139  2 assertTrue(comment.isPending());
140  2 assertEquals(1, comment.getSpamScore());
141    }
142   
143    }