diff options
author | LifeIsAParadox <LifeIsAParadox@users.noreply.github.com> | 2021-09-22 20:36:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 20:36:25 +0200 |
commit | 9486ac91f2effef19ea4d4910d22dc65f70ca89c (patch) | |
tree | 3cc7b7b79fe84f40095ce653a483e2f32dfbdcad /src/test/java/me/xmrvizzy/skyblocker/chat | |
parent | d25a4190c14ffac11a5f4c18f47a6e42fc402bb2 (diff) | |
parent | d99eff762a97c09b4581d6527beedf4a32af485e (diff) | |
download | Skyblocker-9486ac91f2effef19ea4d4910d22dc65f70ca89c.tar.gz Skyblocker-9486ac91f2effef19ea4d4910d22dc65f70ca89c.tar.bz2 Skyblocker-9486ac91f2effef19ea4d4910d22dc65f70ca89c.zip |
Merge pull request #15 from ExternalTime/add-tests
Added tests for chat listeners
Diffstat (limited to 'src/test/java/me/xmrvizzy/skyblocker/chat')
6 files changed, 160 insertions, 0 deletions
diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/ChatListenerTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/ChatListenerTest.java new file mode 100644 index 00000000..78574c74 --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/ChatListenerTest.java @@ -0,0 +1,35 @@ +package me.xmrvizzy.skyblocker.chat; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.*; + +public abstract class ChatListenerTest<T extends ChatListener> { + private final Pattern pattern; + + public ChatListenerTest(T chatListener) { + pattern = chatListener.getPattern(); + } + + protected void assertMatches(String text) { + assertTrue(pattern.matcher(text).matches()); + } + + protected void assertNotMatches(String text) { + assertFalse(pattern.matcher(text).matches()); + } + + protected String[] getGroups(String text) { + Matcher matcher = pattern.matcher(text); + assertTrue(matcher.matches()); + String[] groups = new String[matcher.groupCount() + 1]; + for (int i = 0; i < groups.length; i++) + groups[i] = matcher.group(i); + return groups; + } + + protected void assertGroup(String text, int group, String expect) { + assertEquals(getGroups(text)[group], expect); + } +}
\ No newline at end of file diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AbilityFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AbilityFilterTest.java new file mode 100644 index 00000000..b8a5f9da --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AbilityFilterTest.java @@ -0,0 +1,20 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.chat.ChatListenerTest; +import org.junit.jupiter.api.Test; + +class AbilityFilterTest extends ChatListenerTest<AbilityFilter> { + public AbilityFilterTest() { + super(new AbilityFilter()); + } + + @Test + void charges() { + assertMatches("No more charges, next one in 13.2s!"); + } + + @Test + void cooldown() { + assertMatches("This ability is on cooldown for 42s."); + } +}
\ No newline at end of file diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java new file mode 100644 index 00000000..54e1643d --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AdFilterTest.java @@ -0,0 +1,50 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.chat.ChatListenerTest; +import org.junit.jupiter.api.Test; + +class AdFilterTest extends ChatListenerTest<AdFilter> { + public AdFilterTest() { + super(new AdFilter()); + } + + @Test + void noRank() { + assertMatches("§7Advertiser§7: buy"); + } + + @Test + void vip() { + assertMatches("§a[VIP] Advertiser§f: buy"); + } + + @Test + void mvp() { + assertMatches("§b[MVP§c+§b] Advertiser§f: buy"); + } + + @Test + void plusPlus() { + assertMatches("§6[MVP§c++§6] Advertiser§f: buy"); + } + + @Test + void simpleAd() { + assertMatches("§b[MVP§c+§b] b2dderr§f: buying prismapump"); + } + + @Test + void uppercaseAd() { + assertMatches("§a[VIP] Tecnoisnoob§f: SELLING REJUVENATE 5 Book on ah!"); + } + + @Test + void characterSpam() { + assertMatches("§a[VIP] Benyyy_§f: Hey, Visit my Island, i spent lots of time to build it! I also made donate room! <<<<<<<<<<<<<<<<<<<"); + } + + @Test + void notAd() { + assertNotMatches("§a[VIP] NotMatching§f: This message shouldn't match!"); + } +}
\ No newline at end of file diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AoteFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AoteFilterTest.java new file mode 100644 index 00000000..52ab5fe9 --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/AoteFilterTest.java @@ -0,0 +1,15 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.chat.ChatListenerTest; +import org.junit.jupiter.api.Test; + +class AoteFilterTest extends ChatListenerTest<AoteFilter> { + public AoteFilterTest() { + super(new AoteFilter()); + } + + @Test + void testRegex() { + assertMatches("There are blocks in the way!"); + } +}
\ No newline at end of file diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/HealFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/HealFilterTest.java new file mode 100644 index 00000000..49ceadb3 --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/HealFilterTest.java @@ -0,0 +1,20 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.chat.ChatListenerTest; +import org.junit.jupiter.api.Test; + +class HealFilterTest extends ChatListenerTest<HealFilter> { + public HealFilterTest() { + super(new HealFilter()); + } + + @Test + void healSelf() { + assertMatches("You healed yourself for 18.3 health!"); + } + + @Test + void healedYou() { + assertMatches("H3aler_ healed you for 56 health!"); + } +}
\ No newline at end of file diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ImplosionFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ImplosionFilterTest.java new file mode 100644 index 00000000..8ee58564 --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ImplosionFilterTest.java @@ -0,0 +1,20 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.chat.ChatListenerTest; +import org.junit.jupiter.api.Test; + +class ImplosionFilterTest extends ChatListenerTest<ImplosionFilter> { + public ImplosionFilterTest() { + super(new ImplosionFilter()); + } + + @Test + void oneEnemy() { + assertMatches("Your Implosion hit 1 enemy for 636,116.8 damage."); + } + + @Test + void multipleEnemies() { + assertMatches("Your Implosion hit 7 enemies for 4,452,817.4 damage."); + } +}
\ No newline at end of file |