-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
727fc34
commit 3566e09
Showing
7 changed files
with
158 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/bugs/stackoverflow/belisarius/filters/CodeRemovedFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package bugs.stackoverflow.belisarius.filters; | ||
|
||
import java.io.IOException; | ||
|
||
import bugs.stackoverflow.belisarius.models.Post; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CodeRemovedFilterTest { | ||
@Test | ||
public void hitTest() throws IOException { | ||
// body is null | ||
Post post1 = FilterTestUtils.getSamplePost( | ||
null, | ||
"don't care what <blockquote>this</blockquote> text <code>says</code>", | ||
"title1", | ||
"title", | ||
"edit", | ||
"question" | ||
); | ||
|
||
// last body is null | ||
Post post2 = FilterTestUtils.getSamplePost( | ||
"don't care what this text says", | ||
null, | ||
"title", | ||
null, | ||
"edit", | ||
"question" | ||
); | ||
|
||
// code removed in answer (shouldn't be considered) | ||
Post post3 = FilterTestUtils.getSamplePost( | ||
"This is the new answer body.", | ||
"This was the last answer body.", | ||
"title", | ||
null, | ||
"edit", | ||
"answer" | ||
); | ||
|
||
// code removed in question | ||
Post post4 = FilterTestUtils.getSamplePost( | ||
"<p>Oops! All code was removed!</p>", | ||
"<p>Question text includes <code>some inline code</code>" | ||
+ ", but some <pre><code>blocks of code</code></pre>, too</p>", | ||
"title", | ||
null, | ||
"removed 20 characters from body", | ||
"question" | ||
); | ||
|
||
assertEquals(new CodeRemovedFilter(0, post1).isHit(), false); | ||
assertEquals(new CodeRemovedFilter(0, post2).isHit(), false); | ||
assertEquals(new CodeRemovedFilter(0, post3).isHit(), false); | ||
|
||
CodeRemovedFilter filter4 = new CodeRemovedFilter(0, post4); | ||
assertEquals(filter4.isHit(), true); | ||
// total score is always 1 | ||
assertEquals(filter4.getTotalScore(), 1.0); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/test/java/bugs/stackoverflow/belisarius/filters/FilterTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package bugs.stackoverflow.belisarius.filters; | ||
|
||
import java.io.IOException; | ||
|
||
import bugs.stackoverflow.belisarius.models.Post; | ||
import bugs.stackoverflow.belisarius.services.ApiService; | ||
import bugs.stackoverflow.belisarius.utils.PostUtils; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
public class FilterTestUtils { | ||
public static final ApiService apiService = new ApiService("stackoverflow"); | ||
public static JsonObject json; | ||
|
||
public static Post getSamplePost( | ||
String body, | ||
String lastBody, | ||
String title, | ||
String lastTitle, | ||
String summary, | ||
String postType | ||
) throws IOException { | ||
setJson(); | ||
|
||
JsonObject clone = json.deepCopy(); | ||
|
||
if (body == null) { | ||
clone.remove("body"); | ||
} else { | ||
clone.addProperty("body", body); | ||
} | ||
|
||
if (lastBody == null) { | ||
clone.remove("last_body"); | ||
} else { | ||
clone.addProperty("last_body", lastBody); | ||
} | ||
|
||
if (title == null) { | ||
clone.remove("title"); | ||
} else { | ||
clone.addProperty("title", title); | ||
} | ||
|
||
if (lastTitle == null) { | ||
clone.remove("last_title"); | ||
} else { | ||
clone.addProperty("last_title", lastTitle); | ||
} | ||
|
||
if (summary == null) { | ||
clone.remove("comment"); | ||
} else { | ||
clone.addProperty("comment", summary); | ||
} | ||
|
||
if (postType == null) { | ||
clone.remove("post_type"); | ||
} else { | ||
clone.addProperty("post_type", postType); | ||
} | ||
|
||
return PostUtils.getPost(clone, "stackoverflow", "title"); | ||
} | ||
|
||
private static void setJson() throws IOException { | ||
if (json != null) { | ||
return; | ||
} | ||
|
||
json = apiService.getLatestRevisions("2276572", 1) | ||
.get("items").getAsJsonArray() | ||
.get(2).getAsJsonObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters