mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02:00
[Test] Renamed MockUtils to Mockers
This commit is contained in:
parent
76df161fc7
commit
de7eb5ddef
|
@ -10,7 +10,7 @@ import org.junit.*;
|
|||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import utilities.mocks.BukkitMockUtil;
|
||||
import utilities.mocks.PlanBukkitMocker;
|
||||
|
||||
/**
|
||||
* Test for Bukkit PlanSystem.
|
||||
|
@ -27,7 +27,7 @@ public class BukkitSystemTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
BukkitMockUtil mockUtil = BukkitMockUtil.setUp()
|
||||
PlanBukkitMocker mockUtil = PlanBukkitMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withPluginDescription()
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.junit.rules.ExpectedException;
|
|||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import utilities.mocks.BukkitMockUtil;
|
||||
import utilities.mocks.BungeeMockUtil;
|
||||
import utilities.mocks.PlanBukkitMocker;
|
||||
import utilities.mocks.PlanBungeeMocker;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -39,21 +39,21 @@ public class BungeeBukkitConnectionTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
BukkitMockUtil bukkitMockUtil = BukkitMockUtil.setUp()
|
||||
PlanBukkitMocker planBukkitMocker = PlanBukkitMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withPluginDescription()
|
||||
.withResourceFetchingFromJar()
|
||||
.withServer();
|
||||
bukkitMock = bukkitMockUtil.getPlanMock();
|
||||
bukkitMock = planBukkitMocker.getPlanMock();
|
||||
|
||||
BungeeMockUtil bungeeMockUtil = BungeeMockUtil.setUp()
|
||||
PlanBungeeMocker planBungeeMocker = PlanBungeeMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withPluginDescription()
|
||||
.withResourceFetchingFromJar()
|
||||
.withProxy();
|
||||
bungeeMock = bungeeMockUtil.getPlanMock();
|
||||
bungeeMock = planBungeeMocker.getPlanMock();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.junit.rules.ExpectedException;
|
|||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import utilities.mocks.BungeeMockUtil;
|
||||
import utilities.mocks.PlanBungeeMocker;
|
||||
|
||||
/**
|
||||
* Test for Bungee PlanSystem.
|
||||
|
@ -30,7 +30,7 @@ public class BungeeSystemTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
BungeeMockUtil mockUtil = BungeeMockUtil.setUp()
|
||||
PlanBungeeMocker mockUtil = PlanBungeeMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withPluginDescription()
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.*;
|
|||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import utilities.mocks.SpongeMockUtil;
|
||||
import utilities.mocks.PlanSpongeMocker;
|
||||
|
||||
/**
|
||||
* Test for Sponge PlanSystem.
|
||||
|
@ -27,7 +27,7 @@ public class SpongeSystemTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
SpongeMockUtil mockUtil = SpongeMockUtil.setUp()
|
||||
PlanSpongeMocker mockUtil = PlanSpongeMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withResourceFetchingFromJar();
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.*;
|
|||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import utilities.mocks.BukkitMockUtil;
|
||||
import utilities.mocks.PlanBukkitMocker;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.File;
|
||||
|
@ -27,7 +27,7 @@ public class HTTPSWebServerAuthTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
BukkitMockUtil mockUtil = BukkitMockUtil.setUp()
|
||||
PlanBukkitMocker mockUtil = PlanBukkitMocker.setUp()
|
||||
.withDataFolder(temporaryFolder.getRoot())
|
||||
.withLogging()
|
||||
.withPluginDescription()
|
||||
|
|
|
@ -12,11 +12,11 @@ import java.io.FileInputStream;
|
|||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
/**
|
||||
* Abstract MockUtil for methods that can be used for both Bungee and Bukkit.
|
||||
* Abstract Mocker for methods that can be used for both Bungee and Bukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
abstract class MockUtil {
|
||||
abstract class Mocker {
|
||||
|
||||
PlanPlugin planMock;
|
||||
|
|
@ -29,18 +29,18 @@ import static org.mockito.Mockito.doReturn;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BukkitMockUtil extends MockUtil {
|
||||
public class PlanBukkitMocker extends Mocker {
|
||||
|
||||
private Plan planMock;
|
||||
|
||||
private BukkitMockUtil() {
|
||||
private PlanBukkitMocker() {
|
||||
}
|
||||
|
||||
public static BukkitMockUtil setUp() {
|
||||
return new BukkitMockUtil().mockPlugin();
|
||||
public static PlanBukkitMocker setUp() {
|
||||
return new PlanBukkitMocker().mockPlugin();
|
||||
}
|
||||
|
||||
private BukkitMockUtil mockPlugin() {
|
||||
private PlanBukkitMocker mockPlugin() {
|
||||
planMock = Mockito.mock(Plan.class);
|
||||
super.planMock = planMock;
|
||||
|
||||
|
@ -53,12 +53,12 @@ public class BukkitMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BukkitMockUtil withDataFolder(File tempFolder) {
|
||||
public PlanBukkitMocker withDataFolder(File tempFolder) {
|
||||
doReturn(tempFolder).when(planMock).getDataFolder();
|
||||
return this;
|
||||
}
|
||||
|
||||
public BukkitMockUtil withLogging() {
|
||||
public PlanBukkitMocker withLogging() {
|
||||
TestLogger testLogger = new TestLogger();
|
||||
doReturn(testLogger).when(planMock).getLogger();
|
||||
TestPluginLogger testPluginLogger = new TestPluginLogger();
|
||||
|
@ -68,8 +68,7 @@ public class BukkitMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public BukkitMockUtil withPluginDescription() {
|
||||
public PlanBukkitMocker withPluginDescription() {
|
||||
try {
|
||||
File pluginYml = getFile("/plugin.yml");
|
||||
PluginDescriptionFile description = new PluginDescriptionFile(new FileInputStream(pluginYml));
|
||||
|
@ -80,12 +79,12 @@ public class BukkitMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BukkitMockUtil withResourceFetchingFromJar() throws Exception {
|
||||
public PlanBukkitMocker withResourceFetchingFromJar() throws Exception {
|
||||
withPluginFiles();
|
||||
return this;
|
||||
}
|
||||
|
||||
public BukkitMockUtil withServer() {
|
||||
public PlanBukkitMocker withServer() {
|
||||
Server serverMock = Mockito.mock(Server.class);
|
||||
doReturn("").when(serverMock).getIp();
|
||||
doReturn("Bukkit").when(serverMock).getName();
|
|
@ -28,18 +28,18 @@ import static org.mockito.Mockito.when;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeeMockUtil extends MockUtil {
|
||||
public class PlanBungeeMocker extends Mocker {
|
||||
|
||||
private PlanBungee planMock;
|
||||
|
||||
private BungeeMockUtil() {
|
||||
private PlanBungeeMocker() {
|
||||
}
|
||||
|
||||
public static BungeeMockUtil setUp() {
|
||||
return new BungeeMockUtil().mockPlugin();
|
||||
public static PlanBungeeMocker setUp() {
|
||||
return new PlanBungeeMocker().mockPlugin();
|
||||
}
|
||||
|
||||
private BungeeMockUtil mockPlugin() {
|
||||
private PlanBungeeMocker mockPlugin() {
|
||||
planMock = Mockito.mock(PlanBungee.class);
|
||||
super.planMock = planMock;
|
||||
|
||||
|
@ -52,17 +52,17 @@ public class BungeeMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BungeeMockUtil withDataFolder(File tempFolder) {
|
||||
public PlanBungeeMocker withDataFolder(File tempFolder) {
|
||||
when(planMock.getDataFolder()).thenReturn(tempFolder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BungeeMockUtil withResourceFetchingFromJar() throws Exception {
|
||||
public PlanBungeeMocker withResourceFetchingFromJar() throws Exception {
|
||||
withPluginFiles();
|
||||
return this;
|
||||
}
|
||||
|
||||
public BungeeMockUtil withLogging() {
|
||||
public PlanBungeeMocker withLogging() {
|
||||
TestLogger testLogger = new TestLogger();
|
||||
doReturn(testLogger).when(planMock).getLogger();
|
||||
TestPluginLogger testPluginLogger = new TestPluginLogger();
|
||||
|
@ -72,7 +72,7 @@ public class BungeeMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BungeeMockUtil withProxy() {
|
||||
public PlanBungeeMocker withProxy() {
|
||||
ProxyServer proxyMock = Mockito.mock(ProxyServer.class);
|
||||
doReturn("1.12.2").when(proxyMock).getVersion();
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class BungeeMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BungeeMockUtil withPluginDescription() {
|
||||
public PlanBungeeMocker withPluginDescription() {
|
||||
File pluginYml = getFile("/bungee.yml");
|
||||
HashSet<String> empty = new HashSet<>();
|
||||
PluginDescription pluginDescription = new PluginDescription("Plan", "", "9.9.9", "Rsl1122", empty, empty, pluginYml, "");
|
69
Plan/src/test/java/utilities/mocks/PlanPluginMocker.java
Normal file
69
Plan/src/test/java/utilities/mocks/PlanPluginMocker.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* License is provided in the jar as LICENSE also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
|
||||
*/
|
||||
package utilities.mocks;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plugin.command.ColorScheme;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||
import com.djrapitops.plugin.task.thread.ThreadRunnableFactory;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
/**
|
||||
* Mocking Utility for Bukkit version of Plan.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanPluginMocker extends Mocker {
|
||||
|
||||
private PlanPlugin planMock;
|
||||
|
||||
private PlanPluginMocker() {
|
||||
}
|
||||
|
||||
public static PlanPluginMocker setUp() {
|
||||
return new PlanPluginMocker().mockPlugin();
|
||||
}
|
||||
|
||||
private PlanPluginMocker mockPlugin() {
|
||||
planMock = Mockito.mock(Plan.class);
|
||||
super.planMock = planMock;
|
||||
|
||||
doReturn(new ColorScheme("§1", "§2", "§3")).when(planMock).getColorScheme();
|
||||
doReturn("1.0.0").when(planMock).getVersion();
|
||||
|
||||
ThreadRunnableFactory runnableFactory = new ThreadRunnableFactory();
|
||||
doReturn(runnableFactory).when(planMock).getRunnableFactory();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanPluginMocker withDataFolder(File tempFolder) {
|
||||
doReturn(tempFolder).when(planMock).getDataFolder();
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanPluginMocker withLogging() {
|
||||
TestPluginLogger testPluginLogger = new TestPluginLogger();
|
||||
doReturn(testPluginLogger).when(planMock).getPluginLogger();
|
||||
ConsoleErrorLogger consoleErrorLogger = new ConsoleErrorLogger(testPluginLogger);
|
||||
doReturn(consoleErrorLogger).when(planMock).getErrorHandler();
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanPluginMocker withResourceFetchingFromJar() throws Exception {
|
||||
withPluginFiles();
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlanPlugin getPlanMock() {
|
||||
return planMock;
|
||||
}
|
||||
}
|
|
@ -20,18 +20,18 @@ import static org.mockito.Mockito.*;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SpongeMockUtil extends MockUtil {
|
||||
public class PlanSpongeMocker extends Mocker {
|
||||
|
||||
private PlanSponge planMock;
|
||||
|
||||
private SpongeMockUtil() {
|
||||
private PlanSpongeMocker() {
|
||||
}
|
||||
|
||||
public static SpongeMockUtil setUp() {
|
||||
return new SpongeMockUtil().mockPlugin();
|
||||
public static PlanSpongeMocker setUp() {
|
||||
return new PlanSpongeMocker().mockPlugin();
|
||||
}
|
||||
|
||||
private SpongeMockUtil mockPlugin() {
|
||||
private PlanSpongeMocker mockPlugin() {
|
||||
planMock = Mockito.mock(PlanSponge.class);
|
||||
super.planMock = planMock;
|
||||
|
||||
|
@ -44,12 +44,12 @@ public class SpongeMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SpongeMockUtil withDataFolder(File tempFolder) {
|
||||
public PlanSpongeMocker withDataFolder(File tempFolder) {
|
||||
when(planMock.getDataFolder()).thenReturn(tempFolder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpongeMockUtil withLogging() {
|
||||
public PlanSpongeMocker withLogging() {
|
||||
TestLogger testLogger = new TestLogger();
|
||||
doReturn(testLogger).when(planMock).getLogger();
|
||||
TestPluginLogger testPluginLogger = new TestPluginLogger();
|
||||
|
@ -59,8 +59,7 @@ public class SpongeMockUtil extends MockUtil {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SpongeMockUtil withResourceFetchingFromJar() throws Exception {
|
||||
public PlanSpongeMocker withResourceFetchingFromJar() throws Exception {
|
||||
withPluginFiles();
|
||||
return this;
|
||||
}
|
|
@ -19,6 +19,7 @@ import java.io.File;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class SystemMockUtil {
|
||||
|
||||
private PlanSystem bukkitSystem;
|
||||
|
@ -39,7 +40,7 @@ public class SystemMockUtil {
|
|||
}
|
||||
|
||||
private SystemMockUtil initializeBukkitSystem(File dataFolder) throws Exception {
|
||||
Plan planMock = BukkitMockUtil.setUp()
|
||||
Plan planMock = PlanBukkitMocker.setUp()
|
||||
.withDataFolder(dataFolder)
|
||||
.withLogging()
|
||||
.withResourceFetchingFromJar()
|
||||
|
|
Loading…
Reference in New Issue
Block a user