diff --git a/Plan/velocity/src/test/java/com/djrapitops/plan/VelocitySystemTest.java b/Plan/velocity/src/test/java/com/djrapitops/plan/VelocitySystemTest.java index 2dab20393..d2ac72d1b 100644 --- a/Plan/velocity/src/test/java/com/djrapitops/plan/VelocitySystemTest.java +++ b/Plan/velocity/src/test/java/com/djrapitops/plan/VelocitySystemTest.java @@ -23,35 +23,31 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.paths.ProxySettings; import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.google.common.util.concurrent.MoreExecutors; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; -import rules.ComponentMocker; -import rules.VelocityComponentMocker; import utilities.RandomData; +import utilities.mocks.VelocityMockComponent; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.Assert.assertTrue; /** * Test for Velocity PlanSystem. * * @author Rsl1122 */ -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(JUnitPlatform.class) public class VelocitySystemTest { - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - @ClassRule - public static ComponentMocker component = new VelocityComponentMocker(temporaryFolder); - private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); @Test - public void velocityEnables() throws Exception { - PlanSystem velocitySystem = component.getPlanSystem(); + void velocityEnables(@TempDir Path temp) throws Exception { + PlanSystem velocitySystem = new VelocityMockComponent(temp).getPlanSystem(); try { PlanConfig config = velocitySystem.getConfigSystem().getConfig(); config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); diff --git a/Plan/velocity/src/test/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocityTest.java b/Plan/velocity/src/test/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocityTest.java index 6933a94a4..e70698819 100644 --- a/Plan/velocity/src/test/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocityTest.java +++ b/Plan/velocity/src/test/java/com/djrapitops/plan/system/tasks/velocity/PingCountTimerVelocityTest.java @@ -19,16 +19,18 @@ package com.djrapitops.plan.system.tasks.velocity; import com.djrapitops.plan.PlanVelocity; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; import org.mockito.Mockito; import utilities.TestConstants; import utilities.mocks.PlanVelocityMocker; import java.util.Optional; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; /** @@ -36,13 +38,14 @@ import static org.mockito.Mockito.when; * * @author Rsl1122 */ +@RunWith(JUnitPlatform.class) public class PingCountTimerVelocityTest { private PlanVelocity plugin; private Player player; - @Before - public void setUp() { + @BeforeEach + void setUp() { PlanVelocityMocker mocker = PlanVelocityMocker.setUp() .withProxy(); plugin = mocker.getPlanMock(); @@ -56,7 +59,7 @@ public class PingCountTimerVelocityTest { } @Test - public void offlinePlayerIsRemovedFromPlayerHistory() { + void offlinePlayerIsRemovedFromPlayerHistory() { PingCountTimerVelocity counter = new PingCountTimerVelocity(plugin, null, null, null, null); assertTrue(counter.playerHistory.isEmpty()); diff --git a/Plan/velocity/src/test/java/rules/VelocityComponentMocker.java b/Plan/velocity/src/test/java/utilities/mocks/VelocityMockComponent.java similarity index 54% rename from Plan/velocity/src/test/java/rules/VelocityComponentMocker.java rename to Plan/velocity/src/test/java/utilities/mocks/VelocityMockComponent.java index 0db5df95d..85fba9b64 100644 --- a/Plan/velocity/src/test/java/rules/VelocityComponentMocker.java +++ b/Plan/velocity/src/test/java/utilities/mocks/VelocityMockComponent.java @@ -14,42 +14,46 @@ * You should have received a copy of the GNU Lesser General Public License * along with Plan. If not, see . */ -package rules; +package utilities.mocks; import com.djrapitops.plan.DaggerPlanVelocityComponent; -import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanVelocity; import com.djrapitops.plan.PlanVelocityComponent; import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; -import utilities.mocks.PlanVelocityMocker; -public class VelocityComponentMocker extends ExternalResource implements ComponentMocker { - private final TemporaryFolder testFolder; +import java.nio.file.Path; + +/** + * Test utility for creating a dagger PlanComponent using a mocked Plan. + * + * @author Rsl1122 + */ +public class VelocityMockComponent { + + private final Path tempDir; private PlanVelocity planMock; private PlanVelocityComponent component; - public VelocityComponentMocker(TemporaryFolder testFolder) { - this.testFolder = testFolder; + public VelocityMockComponent(Path tempDir) { + this.tempDir = tempDir; } - @Override - protected void before() throws Throwable { - PlanVelocityMocker mocker = PlanVelocityMocker.setUp() - .withDataFolder(testFolder.newFolder()) - .withResourceFetchingFromJar() - .withProxy(); - planMock = mocker.getPlanMock(); - component = DaggerPlanVelocityComponent.builder().plan(planMock).build(); - } - - public PlanPlugin getPlanMock() { + public PlanVelocity getPlanMock() throws Exception { + if (planMock == null) { + planMock = PlanVelocityMocker.setUp() + .withDataFolder(tempDir.toFile()) + .withResourceFetchingFromJar() + .withProxy() + .getPlanMock(); + } return planMock; } - public PlanSystem getPlanSystem() { + public PlanSystem getPlanSystem() throws Exception { + if (component == null) { + component = DaggerPlanVelocityComponent.builder().plan(getPlanMock()).build(); + } return component.system(); } -} +} \ No newline at end of file