parent
89d362a747
commit
40ca1d756e
24
pom.xml
24
pom.xml
|
|
@ -116,9 +116,27 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--Tests-->
|
<!--Tests-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.13</version>
|
<version>5.6.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.6.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>3.4.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>3.4.6</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
||||||
53
src/test/java/me/ryanhamshire/GriefPrevention/ClaimTest.java
Normal file
53
src/test/java/me/ryanhamshire/GriefPrevention/ClaimTest.java
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class ClaimTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClaimOverlap()
|
||||||
|
{
|
||||||
|
World world = Mockito.mock(World.class);
|
||||||
|
|
||||||
|
// One corner inside
|
||||||
|
Claim claimA = new Claim(new Location(world, 0, 0, 0), new Location(world, 10, 0, 10), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
Claim claimB = new Claim(new Location(world, 5, 0, 5), new Location(world, 15, 0, 15), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
Claim claimC = new Claim(new Location(world, -5, 0, -5), new Location(world, 4, 0, 4), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
|
||||||
|
assertTrue(claimA.overlaps(claimB));
|
||||||
|
assertTrue(claimB.overlaps(claimA));
|
||||||
|
assertTrue(claimA.overlaps(claimC));
|
||||||
|
assertTrue(claimC.overlaps(claimA));
|
||||||
|
assertFalse(claimB.overlaps(claimC));
|
||||||
|
assertFalse(claimC.overlaps(claimB));
|
||||||
|
|
||||||
|
// Complete containment
|
||||||
|
claimA = new Claim(new Location(world, 0, 0, 0), new Location(world, 20, 0, 20), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
claimB = new Claim(new Location(world, 5, 0, 5), new Location(world, 15, 0, 15), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
|
||||||
|
assertTrue(claimA.overlaps(claimB));
|
||||||
|
assertTrue(claimB.overlaps(claimA));
|
||||||
|
|
||||||
|
// Central intersection
|
||||||
|
claimA = new Claim(new Location(world, 0, 0, 5), new Location(world, 10, 0, 15), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
claimB = new Claim(new Location(world, 5, 0, 0), new Location(world, 15, 0, 10), null,
|
||||||
|
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, 0L);
|
||||||
|
|
||||||
|
assertTrue(claimA.overlaps(claimB));
|
||||||
|
assertTrue(claimB.overlaps(claimA));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,23 +1,28 @@
|
||||||
package me.ryanhamshire.GriefPrevention;
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class Tests
|
public class Tests
|
||||||
{
|
{
|
||||||
@Test
|
@Test
|
||||||
public void TrivialTest()
|
public void testTrivial()
|
||||||
{
|
{
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_BeginningMiddleEnd()
|
public void testWordFinderBeginningMiddleEnd()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("alpha", "beta", "gamma"));
|
WordFinder finder = new WordFinder(Arrays.asList("alpha", "beta", "gamma"));
|
||||||
assertTrue(finder.hasMatch("alpha"));
|
assertTrue(finder.hasMatch("alpha"));
|
||||||
|
|
@ -37,9 +42,9 @@ public class Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_Casing()
|
public void testWordFinderCasing()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("aLPhA"));
|
WordFinder finder = new WordFinder(Collections.singletonList("aLPhA"));
|
||||||
assertTrue(finder.hasMatch("alpha"));
|
assertTrue(finder.hasMatch("alpha"));
|
||||||
assertTrue(finder.hasMatch("aLPhA"));
|
assertTrue(finder.hasMatch("aLPhA"));
|
||||||
assertTrue(finder.hasMatch("AlpHa"));
|
assertTrue(finder.hasMatch("AlpHa"));
|
||||||
|
|
@ -47,206 +52,206 @@ public class Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_Punctuation()
|
public void testWordFinderPunctuation()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("alpha"));
|
WordFinder finder = new WordFinder(Collections.singletonList("alpha"));
|
||||||
assertTrue(finder.hasMatch("What do you think,alpha?"));
|
assertTrue(finder.hasMatch("What do you think,alpha?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_NoMatch()
|
public void testWordFinderNoMatch()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("alpha"));
|
WordFinder finder = new WordFinder(Collections.singletonList("alpha"));
|
||||||
assertFalse(finder.hasMatch("Unit testing is smart."));
|
assertFalse(finder.hasMatch("Unit testing is smart."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_EmptyList()
|
public void testWordFinderEmptyList()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(new ArrayList<String>());
|
WordFinder finder = new WordFinder(new ArrayList<>());
|
||||||
assertFalse(finder.hasMatch("alpha"));
|
assertFalse(finder.hasMatch("alpha"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_PunctuationOnly()
|
public void testWordFinderPunctuationOnly()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("alpha"));
|
WordFinder finder = new WordFinder(Collections.singletonList("alpha"));
|
||||||
assertFalse(finder.hasMatch("!"));
|
assertFalse(finder.hasMatch("!"));
|
||||||
assertFalse(finder.hasMatch("?"));
|
assertFalse(finder.hasMatch("?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WordFinder_StartingPunctuation()
|
public void testWordFinderStartingPunctuation()
|
||||||
{
|
{
|
||||||
WordFinder finder = new WordFinder(Arrays.asList("alpha"));
|
WordFinder finder = new WordFinder(Collections.singletonList("alpha"));
|
||||||
assertFalse(finder.hasMatch("!asas dfasdf"));
|
assertFalse(finder.hasMatch("!asas dfasdf"));
|
||||||
assertFalse(finder.hasMatch("?asdfa sdfas df"));
|
assertFalse(finder.hasMatch("?asdfa sdfas df"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID player1 = UUID.fromString("f13c5a98-3777-4659-a111-5617adb7d7fb");
|
private final UUID player1 = UUID.fromString("f13c5a98-3777-4659-a111-5617adb7d7fb");
|
||||||
private UUID player2 = UUID.fromString("8667ba71-b85a-4004-af54-457a9734eed7");
|
private final UUID player2 = UUID.fromString("8667ba71-b85a-4004-af54-457a9734eed7");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_BasicChatOK()
|
public void testSpamDetectorBasicChatOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
String message = "Hi, everybody! :)";
|
String message = "Hi, everybody! :)";
|
||||||
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
||||||
assertTrue(result.muteReason == null);
|
assertNull(result.muteReason);
|
||||||
assertFalse(result.shouldWarnChatter);
|
assertFalse(result.shouldWarnChatter);
|
||||||
assertFalse(result.shouldBanChatter);
|
assertFalse(result.shouldBanChatter);
|
||||||
assertTrue(result.finalMessage.equals(message));
|
assertEquals(result.finalMessage, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_CoordinatesOK()
|
public void testSpamDetectorCoordinatesOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "1029,2945", 0).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "1029,2945", 0).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "x1029 z2945", 100000).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "x1029 z2945", 100000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "x=1029; y=60; z=2945", 200000).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "x=1029; y=60; z=2945", 200000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_NumbersOK()
|
public void testSpamDetectorNumbersOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "25", 0).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "25", 0).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "12,234.89", 100000).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "12,234.89", 100000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "20078", 200000).muteReason == null);
|
assertNull(detector.AnalyzeMessage(player1, "20078", 200000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_RepetitionExact()
|
public void testSpamDetectorRepetitionExact()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
String message = "Hi, everybody! :)";
|
String message = "Hi, everybody! :)";
|
||||||
assertFalse(detector.AnalyzeMessage(player1, message, 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, message, 1000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, message, 28000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, message, 28000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_RepetitionExactOK()
|
public void testSpamDetectorRepetitionExactOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
String message = "Hi, everybody! :)";
|
String message = "Hi, everybody! :)";
|
||||||
assertFalse(detector.AnalyzeMessage(player1, message, 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, message, 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, message, 35000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, message, 35000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_Padding()
|
public void testSpamDetectorPadding()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hacking is really fun guys!! :) 123123123456.12398127498762935", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hacking is really fun guys!! :) 123123123456.12398127498762935", 1000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hacking is really fun guys!! :) 112321523456.1239345498762935", 1000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hacking is really fun guys!! :) 112321523456.1239345498762935", 1000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_Repetition()
|
public void testSpamDetectorRepetition()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 9000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 9000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_TeamRepetition()
|
public void testSpamDetectorTeamRepetition()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player2, "Hi, everybody! :)", 2500).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player2, "Hi, everybody! :)", 2500).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_TeamRepetitionOK()
|
public void testSpamDetectorTeamRepetitionOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "hi", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "hi", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player2, "hi", 3000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player2, "hi", 3000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_Gibberish()
|
public void testSpamDetectorGibberish()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "poiufpoiuasdfpoiuasdfuaufpoiasfopiuasdfpoiuasdufsdf", 1000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "poiufpoiuasdfpoiuasdfuaufpoiasfopiuasdfpoiuasdufsdf", 1000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player2, "&^%(& (&^%(% (*%#@^ #$&(_||", 3000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player2, "&^%(& (&^%(% (*%#@^ #$&(_||", 3000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_RepetitionOK()
|
public void testSpamDetectorRepetitionOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 12000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 12000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_TooFast()
|
public void testSpamDetectorTooFast()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_TooMuchVolume()
|
public void testSpamDetectorTooMuchVolume()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Once upon a time there was this guy who wanted to be a hacker. So he started logging into Minecraft servers and threatening to DDOS them.", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Once upon a time there was this guy who wanted to be a hacker. So he started logging into Minecraft servers and threatening to DDOS them.", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Everybody knew that he couldn't be a real hacker, because no real hacker would consider hacking Minecraft to be worth their time, but he didn't understand that even after it was explained to him.", 3000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Everybody knew that he couldn't be a real hacker, because no real hacker would consider hacking Minecraft to be worth their time, but he didn't understand that even after it was explained to him.", 3000).muteReason);
|
||||||
|
|
||||||
//start of mute
|
//start of mute
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "After I put him in jail and he wasted half an hour of his time trying to solve the (unsolvable) jail 'puzzle', he offered his services to me in exchange for being let out of jail.", 10000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "After I put him in jail and he wasted half an hour of his time trying to solve the (unsolvable) jail 'puzzle', he offered his services to me in exchange for being let out of jail.", 10000).muteReason);
|
||||||
|
|
||||||
//forgiven after taking a break
|
//forgiven after taking a break
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "He promised to DDOS any of my 'rival servers'. So I offered him an opportunity to prove he could do what he said, and I gave him his own IP address from our server logs. Then he disappeared for a while.", 16000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "He promised to DDOS any of my 'rival servers'. So I offered him an opportunity to prove he could do what he said, and I gave him his own IP address from our server logs. Then he disappeared for a while.", 16000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "When he finally came back, I /SoftMuted him and left him in the jail.", 28000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "When he finally came back, I /SoftMuted him and left him in the jail.", 28000).muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_Caps()
|
public void testSpamDetectorCaps()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
String message = "OMG I LUFF U KRISTINAAAAAA!";
|
String message = "OMG I LUFF U KRISTINAAAAAA!";
|
||||||
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
||||||
assertTrue(result.finalMessage.equals(message.toLowerCase()));
|
assertEquals(result.finalMessage, message.toLowerCase());
|
||||||
assertTrue(result.muteReason == null);
|
assertNull(result.muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_CapsOK()
|
public void testSpamDetectorCapsOK()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
String message = "=D";
|
String message = "=D";
|
||||||
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
SpamAnalysisResult result = detector.AnalyzeMessage(player1, message, 1000);
|
||||||
assertTrue(result.finalMessage.equals(message));
|
assertEquals(result.finalMessage, message);
|
||||||
assertTrue(result.muteReason == null);
|
assertNull(result.muteReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_WarnAndBan()
|
public void testSpamDetectorWarnAndBan()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
|
|
||||||
//allowable noise
|
//allowable noise
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason);
|
||||||
|
|
||||||
//begin mute and warning
|
//begin mute and warning
|
||||||
SpamAnalysisResult result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000);
|
SpamAnalysisResult result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000);
|
||||||
assertTrue(result.muteReason != null);
|
assertNotNull(result.muteReason);
|
||||||
assertTrue(result.shouldWarnChatter);
|
assertTrue(result.shouldWarnChatter);
|
||||||
assertFalse(result.shouldBanChatter);
|
assertFalse(result.shouldBanChatter);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 6000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 6000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 7000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 7000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "How's it going? :)", 8000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "How's it going? :)", 8000).muteReason);
|
||||||
|
|
||||||
//ban
|
//ban
|
||||||
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 9000);
|
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 9000);
|
||||||
|
|
@ -254,35 +259,35 @@ public class Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SpamDetector_Forgiveness()
|
public void testSpamDetectorForgiveness()
|
||||||
{
|
{
|
||||||
SpamDetector detector = new SpamDetector();
|
SpamDetector detector = new SpamDetector();
|
||||||
|
|
||||||
//allowable noise
|
//allowable noise
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 1000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "How's it going? :)", 2000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 3000).muteReason);
|
||||||
|
|
||||||
//start of mutes, and a warning
|
//start of mutes, and a warning
|
||||||
SpamAnalysisResult result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000);
|
SpamAnalysisResult result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 4000);
|
||||||
assertTrue(result.muteReason != null);
|
assertNotNull(result.muteReason);
|
||||||
assertTrue(result.shouldWarnChatter);
|
assertTrue(result.shouldWarnChatter);
|
||||||
assertFalse(result.shouldBanChatter);
|
assertFalse(result.shouldBanChatter);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 5000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 6000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 6000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 7000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 7000).muteReason);
|
||||||
assertTrue(detector.AnalyzeMessage(player1, "How's it going? :)", 8000).muteReason != null);
|
assertNotNull(detector.AnalyzeMessage(player1, "How's it going? :)", 8000).muteReason);
|
||||||
|
|
||||||
//long delay before next message, not muted anymore
|
//long delay before next message, not muted anymore
|
||||||
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 20000);
|
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 20000);
|
||||||
assertFalse(result.shouldBanChatter);
|
assertFalse(result.shouldBanChatter);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 21000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Hi, everybody! :)", 21000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "How's it going? :)", 22000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "How's it going? :)", 22000).muteReason);
|
||||||
assertFalse(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 23000).muteReason != null);
|
assertNull(detector.AnalyzeMessage(player1, "Oh how I've missed you all! :)", 23000).muteReason);
|
||||||
|
|
||||||
//mutes start again, and warning appears again
|
//mutes start again, and warning appears again
|
||||||
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 24000);
|
result = detector.AnalyzeMessage(player1, "Why is nobody responding to me??!", 24000);
|
||||||
assertTrue(result.muteReason != null);
|
assertNotNull(result.muteReason);
|
||||||
assertTrue(result.shouldWarnChatter);
|
assertTrue(result.shouldWarnChatter);
|
||||||
assertFalse(result.shouldBanChatter);
|
assertFalse(result.shouldBanChatter);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user