Improve testing and change playtime permissions
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.messages.Message;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.RankElement;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RankupCommandTest extends RankupTest {
|
||||
@Test
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.placeholders.RankupExpansion;
|
||||
|
||||
public class RankupPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -10,12 +10,11 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import sh.okx.rankup.economy.TestEconomyProvider;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import sh.okx.rankup.providers.TestEconomyProvider;
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
import sh.okx.rankup.hook.TestGroupProvider;
|
||||
import sh.okx.rankup.hook.TestPermissionManager;
|
||||
import sh.okx.rankup.providers.TestGroupProvider;
|
||||
import sh.okx.rankup.providers.TestPermissionManager;
|
||||
|
||||
public abstract class RankupTest {
|
||||
private final File testResourceFolder;
|
||||
@@ -37,7 +36,7 @@ public abstract class RankupTest {
|
||||
protected ServerMock server;
|
||||
protected RankupPlugin plugin;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
System.setProperty("RANKUP_TEST", "true");
|
||||
|
||||
@@ -77,7 +76,7 @@ public abstract class RankupTest {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@BeforeEach
|
||||
public void tearDown() {
|
||||
MockBukkit.unmock();
|
||||
System.clearProperty("RANKUP_TEST");
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package sh.okx.rankup.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Statistic;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class ComandPlaytimeTest extends RankupTest {
|
||||
@Test
|
||||
public void testAdd() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(10));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime", true);
|
||||
player.performCommand("pru playtime add " + player.getName() + " 20");
|
||||
|
||||
assertEquals(ticks(30), player.getStatistic(Statistic.PLAY_ONE_MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(20));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime", true);
|
||||
player.performCommand("pru playtime set " + player.getName() + " 25");
|
||||
|
||||
assertEquals(ticks(25), player.getStatistic(Statistic.PLAY_ONE_MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSelf() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(5));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime.get", true);
|
||||
player.performCommand("pru playtime get " + player.getName());
|
||||
|
||||
player.assertSaid(ChatColor.LIGHT_PURPLE + "You have played for 5 minutes.");
|
||||
player.assertNoMoreSaid();
|
||||
}
|
||||
|
||||
private int ticks(int minutes) {
|
||||
return minutes * 20 * 60;
|
||||
}
|
||||
|
||||
private int minutes(int ticks) {
|
||||
return ticks / 20 / 60;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package sh.okx.rankup.legacy;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import java.text.DecimalFormat;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class LegacyPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package sh.okx.rankup.messages;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MessageBuilderTest {
|
||||
@Test
|
||||
public void testFailIfEmpty() {
|
||||
assertThat(new StringMessageBuilder("").failIfEmpty(), instanceOf(NullMessageBuilder.class));
|
||||
assertTrue(new StringMessageBuilder("").failIfEmpty() instanceof NullMessageBuilder);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package sh.okx.rankup.messages;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class RankupPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package sh.okx.rankup.pebble;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.text.pebble.PebbleTextProcessor;
|
||||
|
||||
public class PebbleTest {
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup.economy;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import sh.okx.rankup.economy.Economy;
|
||||
|
||||
public class TestEconomy implements Economy {
|
||||
private final Map<UUID, Double> balances = new HashMap<>();
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
package sh.okx.rankup.economy;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import sh.okx.rankup.economy.Economy;
|
||||
import sh.okx.rankup.economy.EconomyProvider;
|
||||
|
||||
public class TestEconomyProvider implements EconomyProvider {
|
||||
@Override
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
package sh.okx.rankup.hook;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.UUID;
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
|
||||
public class TestGroupProvider implements GroupProvider {
|
||||
private Multimap<UUID, String> groups = ArrayListMultimap.create();
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
package sh.okx.rankup.hook;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
import sh.okx.rankup.hook.PermissionManager;
|
||||
|
||||
public class TestPermissionManager implements PermissionManager {
|
||||
private final GroupProvider groupProvider;
|
||||
Reference in New Issue
Block a user