From b5fb947724a0077a8d674544482ed878b5746a6d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 08:15:43 +0300 Subject: [PATCH 01/18] Moved Bungee tests to JUnit 5 --- .../com/djrapitops/plan/BungeeSystemTest.java | 110 +++++++++--------- .../mocks/BungeeMockComponent.java} | 49 ++++---- .../utilities/mocks/PlanBungeeMocker.java | 15 +-- .../src/test/java/utilities/DBPreparer.java | 32 +++-- 4 files changed, 103 insertions(+), 103 deletions(-) rename Plan/bungeecord/src/test/java/{rules/BungeeComponentMocker.java => utilities/mocks/BungeeMockComponent.java} (53%) diff --git a/Plan/bungeecord/src/test/java/com/djrapitops/plan/BungeeSystemTest.java b/Plan/bungeecord/src/test/java/com/djrapitops/plan/BungeeSystemTest.java index ab4a66fb0..c7a796ee5 100644 --- a/Plan/bungeecord/src/test/java/com/djrapitops/plan/BungeeSystemTest.java +++ b/Plan/bungeecord/src/test/java/com/djrapitops/plan/BungeeSystemTest.java @@ -21,45 +21,44 @@ import com.djrapitops.plan.db.SQLiteDB; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.settings.config.PlanConfig; -import com.djrapitops.plan.system.settings.paths.DatabaseSettings; 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.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +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.BungeeComponentMocker; -import rules.ComponentMocker; -import utilities.CIProperties; +import utilities.DBPreparer; import utilities.RandomData; +import utilities.mocks.BungeeMockComponent; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Test for Bungee PlanSystem. * * @author Rsl1122 */ -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(JUnitPlatform.class) public class BungeeSystemTest { - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); - @Rule - public ComponentMocker component = new BungeeComponentMocker(temporaryFolder); - @Rule - public ExpectedException thrown = ExpectedException.none(); + private BungeeMockComponent component; + private DBPreparer dbPreparer; + + @BeforeEach + void prepareSystem(@TempDir Path temp) throws Exception { + component = new BungeeMockComponent(temp); + dbPreparer = new DBPreparer(component.getPlanSystem(), TEST_PORT_NUMBER); + } @Test - public void bungeeEnables() throws Exception { + void bungeeEnables() throws Exception { PlanSystem bungeeSystem = component.getPlanSystem(); try { PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); @@ -79,56 +78,51 @@ public class BungeeSystemTest { } @Test - public void bungeeDoesNotEnableWithDefaultIP() throws Exception { - thrown.expect(EnableException.class); - thrown.expectMessage("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server."); + void bungeeDoesNotEnableWithDefaultIP() { + EnableException thrown = assertThrows(EnableException.class, () -> { + PlanSystem bungeeSystem = component.getPlanSystem(); + try { + PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); + config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); + config.set(ProxySettings.IP, "0.0.0.0"); - PlanSystem bungeeSystem = component.getPlanSystem(); - try { - PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); - config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); - config.set(ProxySettings.IP, "0.0.0.0"); + DBSystem dbSystem = bungeeSystem.getDatabaseSystem(); + SQLiteDB db = dbSystem.getSqLiteFactory().usingDefaultFile(); + db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService); + dbSystem.setActiveDatabase(db); - DBSystem dbSystem = bungeeSystem.getDatabaseSystem(); - SQLiteDB db = dbSystem.getSqLiteFactory().usingDefaultFile(); - db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService); - dbSystem.setActiveDatabase(db); + bungeeSystem.enable(); // Throws EnableException + } finally { + bungeeSystem.disable(); + } + }); - bungeeSystem.enable(); // Throws EnableException - } finally { - bungeeSystem.disable(); - } + assertEquals("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.", thrown.getMessage()); } @Test - public void testEnableNoMySQL() throws EnableException { - thrown.expect(EnableException.class); + void testEnableNoMySQL() { + assertThrows(EnableException.class, () -> { + PlanSystem bungeeSystem = component.getPlanSystem(); + try { + PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); + config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); + config.set(ProxySettings.IP, "8.8.8.8"); - PlanSystem bungeeSystem = component.getPlanSystem(); - try { - PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); - config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); - config.set(ProxySettings.IP, "8.8.8.8"); - - bungeeSystem.enable(); // Throws EnableException - } finally { - bungeeSystem.disable(); - } + bungeeSystem.enable(); // Throws EnableException + } finally { + bungeeSystem.disable(); + } + }); } @Test - public void testEnableWithMySQL() throws EnableException { - boolean isCI = Boolean.parseBoolean(System.getenv(CIProperties.IS_CI_SERVICE)); - assumeTrue(isCI); - + void testEnableWithMySQL() throws Exception { PlanSystem bungeeSystem = component.getPlanSystem(); try { PlanConfig config = bungeeSystem.getConfigSystem().getConfig(); - config.set(DatabaseSettings.MYSQL_DATABASE, "Plan"); - config.set(DatabaseSettings.MYSQL_USER, "travis"); - config.set(DatabaseSettings.MYSQL_PASS, ""); - config.set(DatabaseSettings.MYSQL_HOST, "127.0.0.1"); - config.set(DatabaseSettings.TYPE, "MySQL"); + // MySQL settings might not be available. + assumeTrue(dbPreparer.setUpMySQLSettings(config).isPresent()); config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); config.set(ProxySettings.IP, "8.8.8.8"); diff --git a/Plan/bungeecord/src/test/java/rules/BungeeComponentMocker.java b/Plan/bungeecord/src/test/java/utilities/mocks/BungeeMockComponent.java similarity index 53% rename from Plan/bungeecord/src/test/java/rules/BungeeComponentMocker.java rename to Plan/bungeecord/src/test/java/utilities/mocks/BungeeMockComponent.java index 3b9858a35..1cd2b74f4 100644 --- a/Plan/bungeecord/src/test/java/rules/BungeeComponentMocker.java +++ b/Plan/bungeecord/src/test/java/utilities/mocks/BungeeMockComponent.java @@ -14,44 +14,47 @@ * 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.DaggerPlanBungeeComponent; import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanBungeeComponent; -import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; -import utilities.mocks.PlanBungeeMocker; -public class BungeeComponentMocker extends ExternalResource implements ComponentMocker { +import java.nio.file.Path; - private final TemporaryFolder testFolder; +/** + * Test utility for creating a dagger PlanComponent using a mocked PlanBungee. + * + * @author Rsl1122 + */ +public class BungeeMockComponent { + + private final Path tempDir; private PlanBungee planMock; private PlanBungeeComponent component; - public BungeeComponentMocker(TemporaryFolder testFolder) { - this.testFolder = testFolder; + public BungeeMockComponent(Path tempDir) { + this.tempDir = tempDir; } - @Override - protected void before() throws Throwable { - PlanBungeeMocker mocker = PlanBungeeMocker.setUp() - .withDataFolder(testFolder.newFolder()) - .withPluginDescription() - .withResourceFetchingFromJar() - .withProxy(); - planMock = mocker.getPlanMock(); - component = DaggerPlanBungeeComponent.builder().plan(planMock).build(); - } - - public PlanPlugin getPlanMock() { + public PlanBungee getPlanMock() throws Exception { + if (planMock == null) { + planMock = PlanBungeeMocker.setUp() + .withDataFolder(tempDir.toFile()) + .withResourceFetchingFromJar() + .withProxy() + .withPluginDescription() + .getPlanMock(); + } return planMock; } - public PlanSystem getPlanSystem() { + public PlanSystem getPlanSystem() throws Exception { + if (component == null) { + component = DaggerPlanBungeeComponent.builder().plan(getPlanMock()).build(); + } return component.system(); } -} +} \ No newline at end of file diff --git a/Plan/bungeecord/src/test/java/utilities/mocks/PlanBungeeMocker.java b/Plan/bungeecord/src/test/java/utilities/mocks/PlanBungeeMocker.java index dd08f610a..c1ecd94aa 100644 --- a/Plan/bungeecord/src/test/java/utilities/mocks/PlanBungeeMocker.java +++ b/Plan/bungeecord/src/test/java/utilities/mocks/PlanBungeeMocker.java @@ -83,23 +83,18 @@ public class PlanBungeeMocker extends Mocker { return this; } - public PlanBungeeMocker withDataFolder(File tempFolder) { + PlanBungeeMocker withDataFolder(File tempFolder) { when(planMock.getDataFolder()).thenReturn(tempFolder); return this; } - public PlanBungeeMocker withResourceFetchingFromJar() throws Exception { + PlanBungeeMocker withResourceFetchingFromJar() throws Exception { withPluginFiles(); return this; } - @Deprecated - public PlanBungeeMocker withLogging() { - return this; - } - @SuppressWarnings("deprecation") - public PlanBungeeMocker withProxy() { + PlanBungeeMocker withProxy() { ProxyServer proxyMock = Mockito.mock(ProxyServer.class); doReturn("1.12.2").when(proxyMock).getVersion(); @@ -117,7 +112,7 @@ public class PlanBungeeMocker extends Mocker { return this; } - public PlanBungeeMocker withPluginDescription() { + PlanBungeeMocker withPluginDescription() { File pluginYml = getFile("/bungee.yml"); HashSet empty = new HashSet<>(); PluginDescription pluginDescription = new PluginDescription("Plan", "", "9.9.9", "Rsl1122", empty, empty, pluginYml, ""); @@ -125,7 +120,7 @@ public class PlanBungeeMocker extends Mocker { return this; } - public PlanBungee getPlanMock() { + PlanBungee getPlanMock() { return planMock; } } diff --git a/Plan/common/src/test/java/utilities/DBPreparer.java b/Plan/common/src/test/java/utilities/DBPreparer.java index dd32cb9b7..a09a8a923 100644 --- a/Plan/common/src/test/java/utilities/DBPreparer.java +++ b/Plan/common/src/test/java/utilities/DBPreparer.java @@ -65,7 +65,7 @@ public class DBPreparer { return db; } - public Optional prepareMySQL() throws EnableException { + public Optional setUpMySQLSettings(PlanConfig config) { String database = System.getenv(CIProperties.MYSQL_DATABASE); String user = System.getenv(CIProperties.MYSQL_USER); String pass = System.getenv(CIProperties.MYSQL_PASS); @@ -80,22 +80,30 @@ public class DBPreparer { String dbName = DBType.MYSQL.getName(); - PlanConfig config = system.getConfigSystem().getConfig(); config.set(DatabaseSettings.MYSQL_DATABASE, formattedDatabase); config.set(DatabaseSettings.MYSQL_USER, user); config.set(DatabaseSettings.MYSQL_PASS, pass); config.set(DatabaseSettings.MYSQL_HOST, "127.0.0.1"); config.set(DatabaseSettings.TYPE, dbName); + return Optional.of(formattedDatabase); + } - SQLDB mysql = prepareDBByName(dbName); - mysql.executeTransaction(new Transaction() { - @Override - protected void performOperations() { - execute("DROP DATABASE " + formattedDatabase); - execute("CREATE DATABASE " + formattedDatabase); - execute("USE " + formattedDatabase); - } - }); - return Optional.of(mysql); + public Optional prepareMySQL() throws EnableException { + PlanConfig config = system.getConfigSystem().getConfig(); + Optional formattedDB = setUpMySQLSettings(config); + if (formattedDB.isPresent()) { + String formattedDatabase = formattedDB.get(); + SQLDB mysql = prepareDBByName(DBType.MYSQL.getName()); + mysql.executeTransaction(new Transaction() { + @Override + protected void performOperations() { + execute("DROP DATABASE " + formattedDatabase); + execute("CREATE DATABASE " + formattedDatabase); + execute("USE " + formattedDatabase); + } + }); + return Optional.of(mysql); + } + return Optional.empty(); } } From c3f9d7769802ae5a62db83b077302d5ff8e6d429 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 08:36:14 +0300 Subject: [PATCH 02/18] Moved Bukkit tests to JUnit 5 --- .../com/djrapitops/plan/BukkitSystemTest.java | 37 ++++++-------- .../system/listeners/AFKListenerTest.java | 40 ++++++++++++--- .../mocks/BukkitMockComponent.java} | 49 ++++++++++--------- .../utilities/mocks/PlanBukkitMocker.java | 15 ++---- 4 files changed, 78 insertions(+), 63 deletions(-) rename Plan/bukkit/src/test/java/{rules/BukkitComponentMocker.java => utilities/mocks/BukkitMockComponent.java} (53%) diff --git a/Plan/bukkit/src/test/java/com/djrapitops/plan/BukkitSystemTest.java b/Plan/bukkit/src/test/java/com/djrapitops/plan/BukkitSystemTest.java index 65f0fabcc..9d9489f40 100644 --- a/Plan/bukkit/src/test/java/com/djrapitops/plan/BukkitSystemTest.java +++ b/Plan/bukkit/src/test/java/com/djrapitops/plan/BukkitSystemTest.java @@ -25,49 +25,42 @@ import com.djrapitops.plan.system.settings.ConfigSettingKeyTest; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.settings.paths.key.Setting; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +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.BukkitComponentMocker; -import rules.ComponentMocker; import utilities.OptionalAssert; import utilities.RandomData; +import utilities.mocks.BukkitMockComponent; +import java.nio.file.Path; import java.util.Collection; import java.util.Optional; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Test for Bukkit PlanSystem. * * @author Rsl1122 */ -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(JUnitPlatform.class) public class BukkitSystemTest { - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Rule - public ComponentMocker component = new BukkitComponentMocker(temporaryFolder); - private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); private PlanSystem system; - @Before - public void prepareSystem() { - system = component.getPlanSystem(); + @BeforeEach + void prepareSystem(@TempDir Path temp) throws Exception { + system = new BukkitMockComponent(temp).getPlanSystem(); system.getConfigSystem().getConfig() .set(WebserverSettings.PORT, TEST_PORT_NUMBER); } @Test - public void bukkitSystemEnables() throws EnableException { + void bukkitSystemEnables() throws EnableException { try { system.enable(); assertTrue(system.isEnabled()); @@ -77,7 +70,7 @@ public class BukkitSystemTest { } @Test - public void correctWebAddressInDatabaseAfterEnable() throws EnableException { + void correctWebAddressInDatabaseAfterEnable() throws EnableException { try { system.enable(); Database database = system.getDatabaseSystem().getDatabase(); @@ -92,7 +85,7 @@ public class BukkitSystemTest { } @Test - public void bukkitSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException { + void bukkitSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException { try { system.enable(); PlanConfig config = system.getConfigSystem().getConfig(); diff --git a/Plan/bukkit/src/test/java/com/djrapitops/plan/system/listeners/AFKListenerTest.java b/Plan/bukkit/src/test/java/com/djrapitops/plan/system/listeners/AFKListenerTest.java index a7e5270ca..006f79796 100644 --- a/Plan/bukkit/src/test/java/com/djrapitops/plan/system/listeners/AFKListenerTest.java +++ b/Plan/bukkit/src/test/java/com/djrapitops/plan/system/listeners/AFKListenerTest.java @@ -23,9 +23,13 @@ import com.djrapitops.plugin.logging.console.TestPluginLogger; import com.djrapitops.plugin.logging.error.ConsoleErrorLogger; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerMoveEvent; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import utilities.TestConstants; import java.util.concurrent.TimeUnit; @@ -37,20 +41,33 @@ import static org.mockito.Mockito.*; * * @author Rsl1122 */ +@RunWith(JUnitPlatform.class) +@ExtendWith(MockitoExtension.class) public class AFKListenerTest { - private AFKListener underTest; + private static AFKListener underTest; - @Before - public void setUp() { + @BeforeAll + static void setUp() { PlanConfig config = Mockito.mock(PlanConfig.class); when(config.get(TimeSettings.AFK_THRESHOLD)).thenReturn(TimeUnit.MINUTES.toMillis(3)); underTest = new AFKListener(config, new ConsoleErrorLogger(new TestPluginLogger())); } @Test - public void afkPermissionIsNotCalledMoreThanOnce() { - Player player = mockPlayer(); + void afkPermissionIsNotCalledMoreThanOnceWhenIgnored() { + Player player = mockPlayerWithPermissions(); + PlayerMoveEvent event = mockMoveEvent(player); + + underTest.onMove(event); + underTest.onMove(event); + + verify(player, times(1)).hasPermission(anyString()); + } + + @Test + void afkPermissionIsNotCalledMoreThanOnceWhenNotIgnored() { + Player player = mockPlayerWithoutPermissions(); PlayerMoveEvent event = mockMoveEvent(player); underTest.onMove(event); @@ -65,11 +82,18 @@ public class AFKListenerTest { return event; } - private Player mockPlayer() { + private Player mockPlayerWithPermissions() { Player player = Mockito.mock(Player.class); when(player.getUniqueId()).thenReturn(TestConstants.PLAYER_ONE_UUID); when(player.hasPermission(anyString())).thenReturn(true); return player; } + private Player mockPlayerWithoutPermissions() { + Player player = Mockito.mock(Player.class); + when(player.getUniqueId()).thenReturn(TestConstants.PLAYER_TWO_UUID); + when(player.hasPermission(anyString())).thenReturn(false); + return player; + } + } \ No newline at end of file diff --git a/Plan/bukkit/src/test/java/rules/BukkitComponentMocker.java b/Plan/bukkit/src/test/java/utilities/mocks/BukkitMockComponent.java similarity index 53% rename from Plan/bukkit/src/test/java/rules/BukkitComponentMocker.java rename to Plan/bukkit/src/test/java/utilities/mocks/BukkitMockComponent.java index 090dbde41..bf4419161 100644 --- a/Plan/bukkit/src/test/java/rules/BukkitComponentMocker.java +++ b/Plan/bukkit/src/test/java/utilities/mocks/BukkitMockComponent.java @@ -14,44 +14,47 @@ * 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.DaggerPlanBukkitComponent; import com.djrapitops.plan.Plan; import com.djrapitops.plan.PlanBukkitComponent; -import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; -import utilities.mocks.PlanBukkitMocker; -public class BukkitComponentMocker extends ExternalResource implements ComponentMocker { +import java.nio.file.Path; - private final TemporaryFolder testFolder; +/** + * Test utility for creating a dagger PlanComponent using a mocked Plan. + * + * @author Rsl1122 + */ +public class BukkitMockComponent { + + private final Path tempDir; private Plan planMock; private PlanBukkitComponent component; - public BukkitComponentMocker(TemporaryFolder testFolder) { - this.testFolder = testFolder; + public BukkitMockComponent(Path tempDir) { + this.tempDir = tempDir; } - @Override - protected void before() throws Throwable { - PlanBukkitMocker mocker = PlanBukkitMocker.setUp() - .withDataFolder(testFolder.newFolder()) - .withPluginDescription() - .withResourceFetchingFromJar() - .withServer(); - planMock = mocker.getPlanMock(); - component = DaggerPlanBukkitComponent.builder().plan(planMock).build(); - } - - public PlanPlugin getPlanMock() { + public Plan getPlanMock() throws Exception { + if (planMock == null) { + planMock = PlanBukkitMocker.setUp() + .withDataFolder(tempDir.toFile()) + .withPluginDescription() + .withResourceFetchingFromJar() + .withServer() + .getPlanMock(); + } return planMock; } - public PlanSystem getPlanSystem() { + public PlanSystem getPlanSystem() throws Exception { + if (component == null) { + component = DaggerPlanBukkitComponent.builder().plan(getPlanMock()).build(); + } return component.system(); } -} +} \ No newline at end of file diff --git a/Plan/bukkit/src/test/java/utilities/mocks/PlanBukkitMocker.java b/Plan/bukkit/src/test/java/utilities/mocks/PlanBukkitMocker.java index 0b3312349..a40faa1d2 100644 --- a/Plan/bukkit/src/test/java/utilities/mocks/PlanBukkitMocker.java +++ b/Plan/bukkit/src/test/java/utilities/mocks/PlanBukkitMocker.java @@ -84,17 +84,12 @@ public class PlanBukkitMocker extends Mocker { return this; } - public PlanBukkitMocker withDataFolder(File tempFolder) { + PlanBukkitMocker withDataFolder(File tempFolder) { doReturn(tempFolder).when(planMock).getDataFolder(); return this; } - @Deprecated - public PlanBukkitMocker withLogging() { - return this; - } - - public PlanBukkitMocker withPluginDescription() { + PlanBukkitMocker withPluginDescription() { try { File pluginYml = getFile("/plugin.yml"); PluginDescriptionFile description = new PluginDescriptionFile(new FileInputStream(pluginYml)); @@ -105,12 +100,12 @@ public class PlanBukkitMocker extends Mocker { return this; } - public PlanBukkitMocker withResourceFetchingFromJar() throws IOException { + PlanBukkitMocker withResourceFetchingFromJar() throws IOException { withPluginFiles(); return this; } - public PlanBukkitMocker withServer() { + PlanBukkitMocker withServer() { Server serverMock = Mockito.mock(Server.class); doReturn("").when(serverMock).getIp(); doReturn("Bukkit").when(serverMock).getName(); @@ -129,7 +124,7 @@ public class PlanBukkitMocker extends Mocker { return this; } - public Plan getPlanMock() { + Plan getPlanMock() { return planMock; } } From cc8d7b8e9fb934df9568ceb17af41abf659101f4 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 08:40:21 +0300 Subject: [PATCH 03/18] Moved Sponge tests to JUnit 5 --- .../com/djrapitops/plan/SpongeSystemTest.java | 35 ++++++-------- .../utilities/mocks/PlanSpongeMocker.java | 8 ++-- .../mocks/SpongeMockComponent.java} | 48 ++++++++++--------- 3 files changed, 43 insertions(+), 48 deletions(-) rename Plan/sponge/src/test/java/{rules/SpongeComponentMocker.java => utilities/mocks/SpongeMockComponent.java} (54%) diff --git a/Plan/sponge/src/test/java/com/djrapitops/plan/SpongeSystemTest.java b/Plan/sponge/src/test/java/com/djrapitops/plan/SpongeSystemTest.java index 2963184bd..dcbcf1d97 100644 --- a/Plan/sponge/src/test/java/com/djrapitops/plan/SpongeSystemTest.java +++ b/Plan/sponge/src/test/java/com/djrapitops/plan/SpongeSystemTest.java @@ -22,48 +22,41 @@ import com.djrapitops.plan.system.settings.ConfigSettingKeyTest; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.settings.paths.key.Setting; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +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.SpongeComponentMocker; import utilities.RandomData; +import utilities.mocks.SpongeMockComponent; +import java.nio.file.Path; import java.util.Collection; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Test for Sponge PlanSystem. * * @author Rsl1122 */ -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(JUnitPlatform.class) public class SpongeSystemTest { - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Rule - public ComponentMocker component = new SpongeComponentMocker(temporaryFolder); - private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); private PlanSystem system; - @Before - public void prepareSpongeSystem() { - system = component.getPlanSystem(); + @BeforeEach + void prepareSpongeSystem(@TempDir Path temp) throws Exception { + system = new SpongeMockComponent(temp).getPlanSystem(); system.getConfigSystem().getConfig() .set(WebserverSettings.PORT, TEST_PORT_NUMBER); } @Test - public void spongeSystemEnables() throws EnableException { + void spongeSystemEnables() throws EnableException { try { system.enable(); assertTrue(system.isEnabled()); @@ -73,7 +66,7 @@ public class SpongeSystemTest { } @Test - public void spongeSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException { + void spongeSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException { try { system.enable(); PlanConfig config = system.getConfigSystem().getConfig(); diff --git a/Plan/sponge/src/test/java/utilities/mocks/PlanSpongeMocker.java b/Plan/sponge/src/test/java/utilities/mocks/PlanSpongeMocker.java index c06920025..5963827f7 100644 --- a/Plan/sponge/src/test/java/utilities/mocks/PlanSpongeMocker.java +++ b/Plan/sponge/src/test/java/utilities/mocks/PlanSpongeMocker.java @@ -86,12 +86,12 @@ public class PlanSpongeMocker extends Mocker { return this; } - public PlanSpongeMocker withDataFolder(File tempFolder) { + PlanSpongeMocker withDataFolder(File tempFolder) { when(planMock.getDataFolder()).thenReturn(tempFolder); return this; } - public PlanSpongeMocker withGame() { + PlanSpongeMocker withGame() { Game game = Mockito.mock(Game.class); Platform platform = mockPlatform(); @@ -130,12 +130,12 @@ public class PlanSpongeMocker extends Mocker { return server; } - public PlanSpongeMocker withResourceFetchingFromJar() throws Exception { + PlanSpongeMocker withResourceFetchingFromJar() throws Exception { withPluginFiles(); return this; } - public PlanSponge getPlanMock() { + PlanSponge getPlanMock() { return planMock; } } diff --git a/Plan/sponge/src/test/java/rules/SpongeComponentMocker.java b/Plan/sponge/src/test/java/utilities/mocks/SpongeMockComponent.java similarity index 54% rename from Plan/sponge/src/test/java/rules/SpongeComponentMocker.java rename to Plan/sponge/src/test/java/utilities/mocks/SpongeMockComponent.java index 0d661cc59..0cc59e31e 100644 --- a/Plan/sponge/src/test/java/rules/SpongeComponentMocker.java +++ b/Plan/sponge/src/test/java/utilities/mocks/SpongeMockComponent.java @@ -14,44 +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.DaggerPlanSpongeComponent; -import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanSponge; import com.djrapitops.plan.PlanSpongeComponent; import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; -import utilities.mocks.PlanSpongeMocker; -public class SpongeComponentMocker extends ExternalResource implements ComponentMocker { +import java.nio.file.Path; - private final TemporaryFolder testFolder; +/** + * Test utility for creating a dagger PlanComponent using a mocked PlanSponge. + * + * @author Rsl1122 + */ +public class SpongeMockComponent { + + private final Path tempDir; private PlanSponge planMock; private PlanSpongeComponent component; - public SpongeComponentMocker(TemporaryFolder testFolder) { - this.testFolder = testFolder; + public SpongeMockComponent(Path tempDir) { + this.tempDir = tempDir; } - @Override - protected void before() throws Throwable { - PlanSpongeMocker mocker = PlanSpongeMocker.setUp() - .withDataFolder(testFolder.newFolder()) - .withResourceFetchingFromJar() - .withGame(); - planMock = mocker.getPlanMock(); - component = DaggerPlanSpongeComponent.builder().plan(planMock).build(); - } - - public PlanPlugin getPlanMock() { + public PlanSponge getPlanMock() throws Exception { + if (planMock == null) { + planMock = PlanSpongeMocker.setUp() + .withDataFolder(tempDir.toFile()) + .withResourceFetchingFromJar() + .withGame() + .getPlanMock(); + } return planMock; } - public PlanSystem getPlanSystem() { + public PlanSystem getPlanSystem() throws Exception { + if (component == null) { + component = DaggerPlanSpongeComponent.builder().plan(getPlanMock()).build(); + } return component.system(); } - -} +} \ No newline at end of file From b1a299a9b28a1860a1346ca155d816fbd3234eec Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 08:51:09 +0300 Subject: [PATCH 04/18] Moved Velocity tests to JUnit 5 --- .../djrapitops/plan/VelocitySystemTest.java | 26 +++++----- .../velocity/PingCountTimerVelocityTest.java | 17 ++++--- .../mocks/VelocityMockComponent.java} | 48 ++++++++++--------- 3 files changed, 47 insertions(+), 44 deletions(-) rename Plan/velocity/src/test/java/{rules/VelocityComponentMocker.java => utilities/mocks/VelocityMockComponent.java} (54%) 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 From 5dca308e1813be0edaf1a9f031a78a001fb16172 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 08:57:12 +0300 Subject: [PATCH 05/18] Replaced JUnit 4 imports --- .../plan/db/DBPatchRegressionTest.java | 4 ++-- .../transactions/events/PingMedianTest.java | 2 +- .../system/locale/LocaleFileWriterTest.java | 2 +- .../system/update/VersionInfoLoaderTest.java | 4 ++-- .../system/webserver/HttpsServerTest.java | 4 ++-- .../webserver/JSErrorRegressionTest.java | 19 +++++++++++-------- .../java/extension/SeleniumExtension.java | 6 +++--- .../test/java/utilities/TestResources.java | 10 ++-------- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchRegressionTest.java index d70ea7d46..2bf1ccf0a 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchRegressionTest.java @@ -24,7 +24,7 @@ import utilities.TestConstants; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; abstract class DBPatchRegressionTest { @@ -91,6 +91,6 @@ abstract class DBPatchRegressionTest { failed.add(patch.getClass().getSimpleName()); } } - assertTrue("Patches " + failed + " were not applied properly.", failed.isEmpty()); + assertTrue(failed.isEmpty(), "Patches " + failed + " were not applied properly."); } } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/access/transactions/events/PingMedianTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/access/transactions/events/PingMedianTest.java index 55ddebf17..cdedc1871 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/access/transactions/events/PingMedianTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/access/transactions/events/PingMedianTest.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test for {@link PingStoreTransaction#getMeanValue()}. diff --git a/Plan/common/src/test/java/com/djrapitops/plan/system/locale/LocaleFileWriterTest.java b/Plan/common/src/test/java/com/djrapitops/plan/system/locale/LocaleFileWriterTest.java index 166bfb66c..b853be51a 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/system/locale/LocaleFileWriterTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/system/locale/LocaleFileWriterTest.java @@ -26,7 +26,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test class for {@link LocaleFileWriter}. diff --git a/Plan/common/src/test/java/com/djrapitops/plan/system/update/VersionInfoLoaderTest.java b/Plan/common/src/test/java/com/djrapitops/plan/system/update/VersionInfoLoaderTest.java index dcdca3ca5..bf9cc72d9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/system/update/VersionInfoLoaderTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/system/update/VersionInfoLoaderTest.java @@ -24,8 +24,8 @@ import org.junit.runner.RunWith; import java.io.IOException; import java.util.List; -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; @RunWith(JUnitPlatform.class) class VersionInfoLoaderTest { diff --git a/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/HttpsServerTest.java b/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/HttpsServerTest.java index 0a23cd32a..b243d2834 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/HttpsServerTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/HttpsServerTest.java @@ -24,7 +24,7 @@ import utilities.HTTPConnector; import java.net.HttpURLConnection; import java.net.URL; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; interface HttpsServerTest { @@ -36,7 +36,7 @@ interface HttpsServerTest { @Test default void webServerIsRunningHTTPS() { - assertTrue("WebServer is not using https", getWebServer().isUsingHTTPS()); + assertTrue(getWebServer().isUsingHTTPS(), "WebServer is not using https"); } /** diff --git a/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/JSErrorRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/JSErrorRegressionTest.java index 2bb3ea068..b8154ae76 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/JSErrorRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/system/webserver/JSErrorRegressionTest.java @@ -23,7 +23,6 @@ import com.djrapitops.plan.db.access.transactions.events.SessionEndTransaction; import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.DBSystem; -import com.djrapitops.plan.system.locale.lang.ErrorPageLang; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.webserver.cache.PageId; @@ -47,7 +46,7 @@ import java.nio.file.Path; import java.util.UUID; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * This test class is for catching any JavaScript errors. @@ -108,14 +107,18 @@ class JSErrorRegressionTest { void playerPageDoesNotHaveJavascriptErrors(WebDriver driver) { System.out.println("Testing Player Page"); driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/TestPlayer"); - assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred")); + assertNo500Error(driver); + } + + private void assertNo500Error(WebDriver driver) { + assertFalse(driver.getPageSource().contains("500 Internal Error occurred"), driver.getPageSource()); } @Test void playerPageAccessibleViaUUID(WebDriver driver) { System.out.println("Testing Player Page via UUID"); driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants.PLAYER_ONE_UUID); - assertFalse(driver.getPageSource(), driver.getPageSource().contains(ErrorPageLang.NOT_PLAYED_404.getDefault())); + assertNo500Error(driver); } @Test @@ -123,7 +126,7 @@ class JSErrorRegressionTest { System.out.println("Testing Server Page"); // Open the page that has refreshing info driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server"); - assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred")); + assertNo500Error(driver); // Wait until Plan caches analysis results Awaitility.await() @@ -133,20 +136,20 @@ class JSErrorRegressionTest { // Open the page with analysis stuff SeleniumExtension.newTab(driver); driver.get("http://localhost:" + TEST_PORT_NUMBER + "/server"); - assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred")); + assertNo500Error(driver); } @Test void playersPageDoesNotHaveJavascriptErrors(WebDriver driver) { System.out.println("Testing Players Page"); driver.get("http://localhost:" + TEST_PORT_NUMBER + "/players"); - assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred")); + assertNo500Error(driver); } @Test void debugPageDoesNotHaveJavascriptErrors(WebDriver driver) { System.out.println("Testing Debug Page"); driver.get("http://localhost:" + TEST_PORT_NUMBER + "/debug"); - assertFalse(driver.getPageSource(), driver.getPageSource().contains("500 Internal Error occurred")); + assertNo500Error(driver); } } \ No newline at end of file diff --git a/Plan/common/src/test/java/extension/SeleniumExtension.java b/Plan/common/src/test/java/extension/SeleniumExtension.java index 2708f624a..359eb10af 100644 --- a/Plan/common/src/test/java/extension/SeleniumExtension.java +++ b/Plan/common/src/test/java/extension/SeleniumExtension.java @@ -17,7 +17,7 @@ package extension; import org.apache.commons.lang3.SystemUtils; -import org.junit.Assume; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.extension.*; import org.openqa.selenium.By; import org.openqa.selenium.Keys; @@ -60,8 +60,8 @@ public class SeleniumExtension implements ParameterResolver, BeforeAllCallback, @Override public void beforeAll(ExtensionContext context) { String driverLocation = getChromeDriverLocation(); - Assume.assumeNotNull("rules.SeleniumDriver: Chrome driver location not specified for this OS type", driverLocation); - Assume.assumeTrue("rules.SeleniumDriver: Chrome driver not found at " + driverLocation, new File(driverLocation).exists()); + Assumptions.assumeFalse(driverLocation == null, "rules.SeleniumDriver: Chrome driver location not specified for this OS type"); + Assumptions.assumeTrue(new File(driverLocation).exists(), "rules.SeleniumDriver: Chrome driver not found at " + driverLocation); System.setProperty("webdriver.chrome.driver", driverLocation); driver = getChromeWebDriver(); diff --git a/Plan/common/src/test/java/utilities/TestResources.java b/Plan/common/src/test/java/utilities/TestResources.java index 3ee084702..f1094123e 100644 --- a/Plan/common/src/test/java/utilities/TestResources.java +++ b/Plan/common/src/test/java/utilities/TestResources.java @@ -26,7 +26,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestResources { @@ -44,13 +44,7 @@ public class TestResources { public static void copyResourceIntoFile(File toFile, String resourcePath) { createEmptyFile(toFile); writeResourceToFile(toFile, resourcePath); - assertTrue("Failed to copy resource: '" + resourcePath + "'", toFile.exists()); - } - - public static void copyTestResourceIntoFile(File toFile, InputStream testResource) { - createEmptyFile(toFile); - copyResourceToFile(toFile, testResource); - assertTrue("Failed to copy resource: '" + toFile.getAbsolutePath() + "'", toFile.exists()); + assertTrue(toFile.exists(), () -> "Failed to copy resource: '" + resourcePath + "'"); } private static void copyResourceToFile(File toFile, InputStream testResource) { From 1ef4b61319436eae7f247c5c8801ebdafeb58bb6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 10 Aug 2019 09:19:15 +0300 Subject: [PATCH 06/18] Removed vintage engine (JUnit 4) dependency --- Plan/build.gradle | 1 - .../src/test/java/rules/ComponentMocker.java | 27 ---------- .../java/rules/PluginComponentMocker.java | 54 ------------------- .../test/java/utilities/HTTPConnector.java | 4 +- 4 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 Plan/common/src/test/java/rules/ComponentMocker.java delete mode 100644 Plan/common/src/test/java/rules/PluginComponentMocker.java diff --git a/Plan/build.gradle b/Plan/build.gradle index 14f3bb8b0..1f2aca3c9 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -116,7 +116,6 @@ subprojects { // Test Tooling Dependencies testCompile "org.junit.jupiter:junit-jupiter-engine:5.5.1" // JUnit 5 testCompile "org.junit.platform:junit-platform-runner:1.5.1" // JUnit 4 runner for JUnit 5 tests - testCompile "org.junit.vintage:junit-vintage-engine:5.5.1" // JUnit 4 compatibility for JUnit 5 testCompile "org.junit.jupiter:junit-jupiter-params:5.5.1" // JUnit 5, parameterized tests testCompile "org.mockito:mockito-core:3.0.0" // Mockito Core testCompile "org.mockito:mockito-junit-jupiter:3.0.0" // Mockito JUnit 5 Extension diff --git a/Plan/common/src/test/java/rules/ComponentMocker.java b/Plan/common/src/test/java/rules/ComponentMocker.java deleted file mode 100644 index 359adca5b..000000000 --- a/Plan/common/src/test/java/rules/ComponentMocker.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package rules; - -import com.djrapitops.plan.PlanPlugin; -import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.TestRule; - -public interface ComponentMocker extends TestRule { - PlanPlugin getPlanMock(); - - PlanSystem getPlanSystem(); -} diff --git a/Plan/common/src/test/java/rules/PluginComponentMocker.java b/Plan/common/src/test/java/rules/PluginComponentMocker.java deleted file mode 100644 index 8530e6b7a..000000000 --- a/Plan/common/src/test/java/rules/PluginComponentMocker.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package rules; - -import com.djrapitops.plan.PlanPlugin; -import com.djrapitops.plan.system.PlanSystem; -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; -import utilities.dagger.DaggerPlanPluginComponent; -import utilities.dagger.PlanPluginComponent; -import utilities.mocks.PlanPluginMocker; - -public class PluginComponentMocker extends ExternalResource implements ComponentMocker { - private final TemporaryFolder testFolder; - - private PlanPlugin planMock; - private PlanPluginComponent component; - - public PluginComponentMocker(TemporaryFolder testFolder) { - this.testFolder = testFolder; - } - - @Override - protected void before() throws Throwable { - PlanPluginMocker mocker = PlanPluginMocker.setUp() - .withDataFolder(testFolder.newFolder()) - .withResourceFetchingFromJar() - .withLogging(); - planMock = mocker.getPlanMock(); - component = DaggerPlanPluginComponent.builder().plan(planMock).build(); - } - - public PlanPlugin getPlanMock() { - return planMock; - } - - public PlanSystem getPlanSystem() { - return component.system(); - } -} diff --git a/Plan/common/src/test/java/utilities/HTTPConnector.java b/Plan/common/src/test/java/utilities/HTTPConnector.java index 8b60b67b3..8685fedbe 100644 --- a/Plan/common/src/test/java/utilities/HTTPConnector.java +++ b/Plan/common/src/test/java/utilities/HTTPConnector.java @@ -16,8 +16,6 @@ */ package utilities; -import org.junit.rules.ExternalResource; - import javax.net.ssl.*; import java.io.IOException; import java.net.HttpURLConnection; @@ -25,7 +23,7 @@ import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -public class HTTPConnector extends ExternalResource { +public class HTTPConnector { private static final TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { From 650e3998e4bc3c236b44941f38c8d9ec965c1402 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2019 06:02:06 +0000 Subject: [PATCH 07/18] Bump jacoco-maven-plugin from 0.8.3 to 0.8.4 in /PlanPluginBridge Bumps [jacoco-maven-plugin](https://github.com/jacoco/jacoco) from 0.8.3 to 0.8.4. - [Release notes](https://github.com/jacoco/jacoco/releases) - [Commits](https://github.com/jacoco/jacoco/compare/v0.8.3...v0.8.4) Signed-off-by: dependabot-preview[bot] --- PlanPluginBridge/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml index 06d77b842..3e8ef67e5 100644 --- a/PlanPluginBridge/pom.xml +++ b/PlanPluginBridge/pom.xml @@ -195,7 +195,7 @@ org.jacoco jacoco-maven-plugin - 0.8.3 + 0.8.4 From 6f32d4929c6ae960d8fe59a681af82017c6f6044 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2019 06:06:17 +0000 Subject: [PATCH 08/18] Bump slf4jVersion from 1.7.27 to 1.7.28 in /Plan Bumps `slf4jVersion` from 1.7.27 to 1.7.28. Updates `slf4j-nop` from 1.7.27 to 1.7.28 - [Release notes](https://github.com/qos-ch/slf4j/releases) - [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.27...v_1.7.28) Updates `slf4j-api` from 1.7.27 to 1.7.28 - [Release notes](https://github.com/qos-ch/slf4j/releases) - [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.27...v_1.7.28) Signed-off-by: dependabot-preview[bot] --- Plan/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/build.gradle b/Plan/build.gradle index 1f2aca3c9..14540013a 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -74,7 +74,7 @@ subprojects { ext.h2Version = "1.4.199" ext.mysqlVersion = "8.0.17" ext.hikariVersion = "3.3.1" - ext.slf4jVersion = "1.7.27" + ext.slf4jVersion = "1.7.28" ext.geoIpVersion = "2.12.0" ext.guavaVersion = "28.0-jre" ext.bstatsVersion = "1.4" From 3ab4d2b68a2dd56f5f58b08146185a46c8e9cfbe Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2019 06:06:43 +0000 Subject: [PATCH 09/18] Bump org.sonarqube from 2.7 to 2.7.1 in /Plan Bumps org.sonarqube from 2.7 to 2.7.1. Signed-off-by: dependabot-preview[bot] --- Plan/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/build.gradle b/Plan/build.gradle index 14540013a..e35fc564d 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -10,7 +10,7 @@ plugins { id "java" id "jacoco" id "checkstyle" - id "org.sonarqube" version "2.7" + id "org.sonarqube" version "2.7.1" id "net.ltgt.apt" version "0.21" id "net.ltgt.apt-idea" version "0.21" id "com.github.johnrengelman.shadow" version "5.1.0" From e66b63281dd2319656a3e2039dbae8ff9b1949d2 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 09:31:57 +0300 Subject: [PATCH 10/18] Made build in extension registration more resistant: - Attempt to reduce the amount of exceptions that might slip through and fail to start Plan Affects issues: - Close #1134 --- .../extractor/ExtensionExtractor.java | 16 ++++- .../data/plugin/PluginsConfigSection.java | 14 ++++ .../ExtensionServiceImplementation.java | 4 +- .../system/settings/config/ConfigNode.java | 4 ++ .../implementation/ExtensionRegister.java | 70 +++++++++++-------- 5 files changed, 75 insertions(+), 33 deletions(-) diff --git a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java index adb234010..4165f5ed3 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/extension/extractor/ExtensionExtractor.java @@ -68,8 +68,13 @@ public final class ExtensionExtractor { } } - private Optional getClassAnnotation(Class ofClass) { - return Optional.ofNullable(extension.getClass().getAnnotation(ofClass)); + private static Optional getClassAnnotation(Class from, Class ofClass) { + return Optional.ofNullable(from.getAnnotation(ofClass)); + } + + public static String getPluginName(Class extensionClass) { + return getClassAnnotation(extensionClass, PluginInfo.class).map(PluginInfo::name) + .orElseThrow(() -> new IllegalArgumentException("Given class had no PluginInfo annotation")); } private Method[] getMethods() { @@ -282,8 +287,13 @@ public final class ExtensionExtractor { } } + private Optional getClassAnnotation(Class ofClass) { + return getClassAnnotation(extension.getClass(), ofClass); + } + private void extractPluginInfo() { - pluginInfo = getClassAnnotation(PluginInfo.class).orElseThrow(() -> new IllegalArgumentException("Given class had no PluginInfo annotation")); + pluginInfo = getClassAnnotation(PluginInfo.class) + .orElseThrow(() -> new IllegalArgumentException("Given class had no PluginInfo annotation")); if (pluginInfo.name().length() > 50) { warnings.add(extensionName + " PluginInfo 'name' was over 50 characters."); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java b/Plan/common/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java index 9223fe375..85602e04c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java @@ -20,6 +20,8 @@ import com.djrapitops.plan.system.settings.config.ConfigNode; import com.djrapitops.plan.system.settings.config.PlanConfig; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; /** * Class responsible for generating and generating settings for PluginData @@ -74,4 +76,16 @@ public class PluginsConfigSection { ConfigNode section = getPluginsSection(); return section.getBoolean(pluginName + ".Enabled"); } + + public Set getDisabled() { + ConfigNode section = getPluginsSection(); + + Set disabledPlugins = new HashSet<>(); + for (ConfigNode plugin : section.getChildren()) { + if (!plugin.getBoolean("Enabled")) { + disabledPlugins.add(plugin.getKey(false)); + } + } + return disabledPlugins; + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java index 3f4fb56a5..f61955b15 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java @@ -83,11 +83,11 @@ public class ExtensionServiceImplementation implements ExtensionService { public void register() { try { - extensionRegister.registerBuiltInExtensions(); + extensionRegister.registerBuiltInExtensions(config.getPluginsConfigSection().getDisabled()); if (Check.isBukkitAvailable()) extensionRegister.registerBukkitExtensions(); if (Check.isBungeeAvailable()) extensionRegister.registerBungeeExtensions(); } catch (IllegalStateException failedToRegisterOne) { - logger.warn("One or more extensions failed to register:"); + logger.warn("One or more extensions failed to register, see suppressed exceptions."); errorHandler.log(L.WARN, this.getClass(), failedToRegisterOne); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java index 70ca37829..ea0c9ee4b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/config/ConfigNode.java @@ -349,6 +349,10 @@ public class ConfigNode { return nodeOrder; } + public Collection getChildren() { + return childNodes.values(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java index 43bcdde31..14fb136c9 100644 --- a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java +++ b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java @@ -19,10 +19,12 @@ package com.djrapitops.plan.extension.implementation; import com.djrapitops.extension.*; import com.djrapitops.plan.extension.DataExtension; import com.djrapitops.plan.extension.ExtensionService; +import com.djrapitops.plan.extension.extractor.ExtensionExtractor; import javax.inject.Inject; import javax.inject.Singleton; import java.util.Optional; +import java.util.Set; import java.util.function.Supplier; /** @@ -34,47 +36,49 @@ import java.util.function.Supplier; public class ExtensionRegister { private IllegalStateException registerException; - + private Set disabledExtensions; + @Inject public ExtensionRegister() { /* Required for dagger injection */ } - public void registerBuiltInExtensions() { + public void registerBuiltInExtensions(Set disabledExtensions) { + this.disabledExtensions = disabledExtensions; // No need to catch exceptions here, // registerBuiltInExtensions method will not be called unless Plan has enabled properly ExtensionService extensionService = ExtensionService.getInstance(); - register(new AACExtensionFactory()::createExtension); - register(new AdvancedAchievementsExtensionFactory()::createExtension); - register(new AdvancedBanExtensionFactory()::createExtension); - register(new ASkyBlockExtensionFactory()::createExtension); - register(new BanManagerExtensionFactory()::createExtension); - register(new CoreProtectExtensionFactory()::createExtension); - register(new DiscordSRVExtensionFactory()::createExtension); + register(new AACExtensionFactory()::createExtension, AACExtensionFactory.class); + register(new AdvancedAchievementsExtensionFactory()::createExtension, AdvancedAchievementsExtensionFactory.class); + register(new AdvancedBanExtensionFactory()::createExtension, AdvancedBanExtensionFactory.class); + register(new ASkyBlockExtensionFactory()::createExtension, ASkyBlockExtensionFactory.class); + register(new BanManagerExtensionFactory()::createExtension, BanManagerExtensionFactory.class); + register(new CoreProtectExtensionFactory()::createExtension, CoreProtectExtensionFactory.class); + register(new DiscordSRVExtensionFactory()::createExtension, DiscordSRVExtensionFactory.class); registerEssentialsExtension(extensionService); - register(new GriefPreventionExtensionFactory()::createExtension); - register(new GriefPreventionSpongeExtensionFactory()::createExtension); - register(new GriefPreventionPlusExtensionFactory()::createExtension); - register(new McMMOExtensionFactory()::createExtension); + register(new GriefPreventionExtensionFactory()::createExtension, GriefPreventionExtensionFactory.class); + register(new GriefPreventionSpongeExtensionFactory()::createExtension, GriefPreventionSpongeExtensionFactory.class); + register(new GriefPreventionPlusExtensionFactory()::createExtension, GriefPreventionPlusExtensionFactory.class); + register(new McMMOExtensionFactory()::createExtension, McMMOExtensionFactory.class); registerMinigameLibExtensions(extensionService); - register(new NucleusExtensionFactory()::createExtension); - register(new NuVotifierExtensionFactory()::createExtension); - register(new ProtocolSupportExtensionFactory()::createExtension); - register(new RedProtectExtensionFactory()::createExtension); - register(new SpongeEconomyExtensionFactory()::createExtension); - register(new SuperbVoteExtensionFactory()::createExtension); - register(new VaultExtensionFactory()::createExtension); + register(new NucleusExtensionFactory()::createExtension, NucleusExtensionFactory.class); + register(new NuVotifierExtensionFactory()::createExtension, NuVotifierExtensionFactory.class); + register(new ProtocolSupportExtensionFactory()::createExtension, ProtocolSupportExtensionFactory.class); + register(new RedProtectExtensionFactory()::createExtension, RedProtectExtensionFactory.class); + register(new SpongeEconomyExtensionFactory()::createExtension, SpongeEconomyExtensionFactory.class); + register(new SuperbVoteExtensionFactory()::createExtension, SuperbVoteExtensionFactory.class); + register(new VaultExtensionFactory()::createExtension, VaultExtensionFactory.class); if (registerException != null) throw registerException; } public void registerBukkitExtensions() { - register(new ViaVersionBukkitExtensionFactory()::createExtension); + register(new ViaVersionBukkitExtensionFactory()::createExtension, ViaVersionBukkitExtensionFactory.class); } public void registerBungeeExtensions() { - register(new ViaVersionBungeeExtensionFactory()::createExtension); + register(new ViaVersionBungeeExtensionFactory()::createExtension, ViaVersionBungeeExtensionFactory.class); } private void registerEssentialsExtension(ExtensionService extensionService) { @@ -90,16 +94,26 @@ public class ExtensionRegister { } } - private void register(Supplier> extension) { + private void register(Supplier> extension, Class factory) { ExtensionService extensionService = ExtensionService.getInstance(); try { - extension.get().ifPresent(extensionService::register); - } catch (IllegalStateException e) { + Optional optional = extension.get(); + if (!optional.isPresent()) return; + DataExtension dataExtension = optional.get(); + + String extensionName = ExtensionExtractor.getPluginName(dataExtension.getClass()); + if (disabledExtensions.contains(extensionName)) return; + + extensionService.register(dataExtension); + } catch (IllegalStateException | NoClassDefFoundError | IncompatibleClassChangeError e) { + // Places all exceptions to one exception with plugin information so that they can be reported. if (registerException == null) { - registerException = e; - } else { - registerException.addSuppressed(e); + registerException = new IllegalStateException("One or more extensions failed to register:"); + registerException.setStackTrace(new StackTraceElement[0]); } + IllegalStateException info = new IllegalStateException(factory.getSimpleName() + " ran into exception when creating Extension", e); + info.setStackTrace(new StackTraceElement[0]); + registerException.addSuppressed(info); } } } \ No newline at end of file From b87f71549210205b4a77782d8063a42fff86ac0b Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 10:15:40 +0300 Subject: [PATCH 11/18] Updated extensions with sql bug - Replaces REMOVE with DELETE in AAC, nuVotifier, ProtcolSupport & ViaVersion extensions - ViaVersion extension factory no longer split into many Affects issues: - Close #1137 --- .../plan/extension/ExtensionServiceImplementation.java | 3 --- Plan/extensions/build.gradle | 8 ++++---- .../plan/extension/implementation/ExtensionRegister.java | 9 +-------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java index f61955b15..a37c8ae77 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java @@ -27,7 +27,6 @@ import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.settings.config.PlanConfig; -import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -84,8 +83,6 @@ public class ExtensionServiceImplementation implements ExtensionService { public void register() { try { extensionRegister.registerBuiltInExtensions(config.getPluginsConfigSection().getDisabled()); - if (Check.isBukkitAvailable()) extensionRegister.registerBukkitExtensions(); - if (Check.isBungeeAvailable()) extensionRegister.registerBungeeExtensions(); } catch (IllegalStateException failedToRegisterOne) { logger.warn("One or more extensions failed to register, see suppressed exceptions."); errorHandler.log(L.WARN, this.getClass(), failedToRegisterOne); diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle index 41022180e..f0550bf0c 100644 --- a/Plan/extensions/build.gradle +++ b/Plan/extensions/build.gradle @@ -1,6 +1,6 @@ dependencies { compile project(path: ":api") - compile 'com.djrapitops:Extension-AAC:4.0.5-R0.3' + compile 'com.djrapitops:Extension-AAC:4.0.11-R0.1' compile 'com.djrapitops:Extension-AdvancedAchievements:1.1-R0.3' compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.6' compile 'com.djrapitops:Extension-ASkyBlock:3.0.9.4-R0.4' @@ -14,13 +14,13 @@ dependencies { compile 'com.djrapitops:Extension-McMMO:2.1.44-R0.2' compile 'com.djrapitops:Extension-MinigamesLib:1.14.17-R0.2' compile 'com.djrapitops:Extension-Nucleus:1.9.2-R0.2' - compile 'com.djrapitops:Extension-nuVotifier:2.3.4-R0.2' - compile 'com.djrapitops:Extension-ProtocolSupport:4.29-R0.2' + compile 'com.djrapitops:Extension-nuVotifier:2.3.4-R0.3' + compile 'com.djrapitops:Extension-ProtocolSupport:4.29-R0.3' compile 'com.djrapitops:Extension-RedProtect:7.5.6-R0.2' compile 'com.djrapitops:Extension-Sponge-Economy:7.1.0-R0.3' compile 'com.djrapitops:Extension-SuperbVote:0.5.4-R0.1' compile 'com.djrapitops:Extension-Vault:1.7-R0.2' - compile 'com.djrapitops:Extension-ViaVersion:2.1.3-R0.3' + compile 'com.djrapitops:Extension-ViaVersion:2.1.3-R1.0' } shadowJar { diff --git a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java index 14fb136c9..f301b43cd 100644 --- a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java +++ b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java @@ -69,18 +69,11 @@ public class ExtensionRegister { register(new SpongeEconomyExtensionFactory()::createExtension, SpongeEconomyExtensionFactory.class); register(new SuperbVoteExtensionFactory()::createExtension, SuperbVoteExtensionFactory.class); register(new VaultExtensionFactory()::createExtension, VaultExtensionFactory.class); + register(new ViaVersionExtensionFactory()::createExtension, ViaVersionExtensionFactory.class); if (registerException != null) throw registerException; } - public void registerBukkitExtensions() { - register(new ViaVersionBukkitExtensionFactory()::createExtension, ViaVersionBukkitExtensionFactory.class); - } - - public void registerBungeeExtensions() { - register(new ViaVersionBungeeExtensionFactory()::createExtension, ViaVersionBungeeExtensionFactory.class); - } - private void registerEssentialsExtension(ExtensionService extensionService) { EssentialsExtensionFactory essentials = new EssentialsExtensionFactory(); essentials.createExtension() From e100068e78577c355192247fd3a250740f60c4a2 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 11:04:03 +0300 Subject: [PATCH 12/18] Registered advanced ban listeners Affects issues: - Close #1135 --- Plan/extensions/build.gradle | 2 +- .../implementation/ExtensionRegister.java | 120 ++++++++++-------- 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle index f0550bf0c..d81591254 100644 --- a/Plan/extensions/build.gradle +++ b/Plan/extensions/build.gradle @@ -2,7 +2,7 @@ dependencies { compile project(path: ":api") compile 'com.djrapitops:Extension-AAC:4.0.11-R0.1' compile 'com.djrapitops:Extension-AdvancedAchievements:1.1-R0.3' - compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.6' + compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.7' compile 'com.djrapitops:Extension-ASkyBlock:3.0.9.4-R0.4' compile 'com.djrapitops:Extension-BanManager:5.15.0-R0.5' compile 'com.djrapitops:Extension-CoreProtect:2.16.0-R0.3' diff --git a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java index f301b43cd..9ca268b3f 100644 --- a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java +++ b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.extension.implementation; import com.djrapitops.extension.*; +import com.djrapitops.plan.extension.Caller; import com.djrapitops.plan.extension.DataExtension; import com.djrapitops.plan.extension.ExtensionService; import com.djrapitops.plan.extension.extractor.ExtensionExtractor; @@ -25,7 +26,8 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.util.Optional; import java.util.Set; -import java.util.function.Supplier; +import java.util.function.BiConsumer; +import java.util.function.Function; /** * In charge of registering built in {@link com.djrapitops.plan.extension.DataExtension} implementations. @@ -37,6 +39,7 @@ public class ExtensionRegister { private IllegalStateException registerException; private Set disabledExtensions; + private ExtensionService extensionService; @Inject public ExtensionRegister() { @@ -45,68 +48,83 @@ public class ExtensionRegister { public void registerBuiltInExtensions(Set disabledExtensions) { this.disabledExtensions = disabledExtensions; - // No need to catch exceptions here, - // registerBuiltInExtensions method will not be called unless Plan has enabled properly - ExtensionService extensionService = ExtensionService.getInstance(); + extensionService = ExtensionService.getInstance(); - register(new AACExtensionFactory()::createExtension, AACExtensionFactory.class); - register(new AdvancedAchievementsExtensionFactory()::createExtension, AdvancedAchievementsExtensionFactory.class); - register(new AdvancedBanExtensionFactory()::createExtension, AdvancedBanExtensionFactory.class); - register(new ASkyBlockExtensionFactory()::createExtension, ASkyBlockExtensionFactory.class); - register(new BanManagerExtensionFactory()::createExtension, BanManagerExtensionFactory.class); - register(new CoreProtectExtensionFactory()::createExtension, CoreProtectExtensionFactory.class); - register(new DiscordSRVExtensionFactory()::createExtension, DiscordSRVExtensionFactory.class); - registerEssentialsExtension(extensionService); - register(new GriefPreventionExtensionFactory()::createExtension, GriefPreventionExtensionFactory.class); - register(new GriefPreventionSpongeExtensionFactory()::createExtension, GriefPreventionSpongeExtensionFactory.class); - register(new GriefPreventionPlusExtensionFactory()::createExtension, GriefPreventionPlusExtensionFactory.class); - register(new McMMOExtensionFactory()::createExtension, McMMOExtensionFactory.class); - registerMinigameLibExtensions(extensionService); - register(new NucleusExtensionFactory()::createExtension, NucleusExtensionFactory.class); - register(new NuVotifierExtensionFactory()::createExtension, NuVotifierExtensionFactory.class); - register(new ProtocolSupportExtensionFactory()::createExtension, ProtocolSupportExtensionFactory.class); - register(new RedProtectExtensionFactory()::createExtension, RedProtectExtensionFactory.class); - register(new SpongeEconomyExtensionFactory()::createExtension, SpongeEconomyExtensionFactory.class); - register(new SuperbVoteExtensionFactory()::createExtension, SuperbVoteExtensionFactory.class); - register(new VaultExtensionFactory()::createExtension, VaultExtensionFactory.class); - register(new ViaVersionExtensionFactory()::createExtension, ViaVersionExtensionFactory.class); + register(new AACExtensionFactory(), AACExtensionFactory::createExtension); + register(new AdvancedAchievementsExtensionFactory(), AdvancedAchievementsExtensionFactory::createExtension); + register(new AdvancedBanExtensionFactory(), AdvancedBanExtensionFactory::createExtension, AdvancedBanExtensionFactory::registerListener); + register(new ASkyBlockExtensionFactory(), ASkyBlockExtensionFactory::createExtension); + register(new BanManagerExtensionFactory(), BanManagerExtensionFactory::createExtension); + register(new CoreProtectExtensionFactory(), CoreProtectExtensionFactory::createExtension); + register(new DiscordSRVExtensionFactory(), DiscordSRVExtensionFactory::createExtension); + register(new EssentialsExtensionFactory(), EssentialsExtensionFactory::createExtension, EssentialsExtensionFactory::registerUpdateListeners); + register(new GriefPreventionExtensionFactory(), GriefPreventionExtensionFactory::createExtension); + register(new GriefPreventionSpongeExtensionFactory(), GriefPreventionSpongeExtensionFactory::createExtension); + register(new GriefPreventionPlusExtensionFactory(), GriefPreventionPlusExtensionFactory::createExtension); + register(new McMMOExtensionFactory(), McMMOExtensionFactory::createExtension); + registerMinigameLibExtensions(); + register(new NucleusExtensionFactory(), NucleusExtensionFactory::createExtension); + register(new NuVotifierExtensionFactory(), NuVotifierExtensionFactory::createExtension); + register(new ProtocolSupportExtensionFactory(), ProtocolSupportExtensionFactory::createExtension); + register(new RedProtectExtensionFactory(), RedProtectExtensionFactory::createExtension); + register(new SpongeEconomyExtensionFactory(), SpongeEconomyExtensionFactory::createExtension); + register(new SuperbVoteExtensionFactory(), SuperbVoteExtensionFactory::createExtension); + register(new VaultExtensionFactory(), VaultExtensionFactory::createExtension); + register(new ViaVersionExtensionFactory(), ViaVersionExtensionFactory::createExtension); if (registerException != null) throw registerException; } - private void registerEssentialsExtension(ExtensionService extensionService) { - EssentialsExtensionFactory essentials = new EssentialsExtensionFactory(); - essentials.createExtension() - .flatMap(extensionService::register) // If the extension was registered this is present. - .ifPresent(essentials::registerUpdateListeners); - } - - private void registerMinigameLibExtensions(ExtensionService extensionService) { + private void registerMinigameLibExtensions() { for (DataExtension minigame : new MinigameLibExtensionFactory().createExtensions()) { - extensionService.register(minigame); + register(minigame); } } - private void register(Supplier> extension, Class factory) { - ExtensionService extensionService = ExtensionService.getInstance(); + private void suppressException(Class factory, Throwable e) { + // Places all exceptions to one exception with plugin information so that they can be reported. + if (registerException == null) { + registerException = new IllegalStateException("One or more extensions failed to register:"); + registerException.setStackTrace(new StackTraceElement[0]); + } + IllegalStateException info = new IllegalStateException(factory.getSimpleName() + " ran into exception when creating Extension", e); + info.setStackTrace(new StackTraceElement[0]); + registerException.addSuppressed(info); + } + + private void register( + T factory, + Function> createExtension + ) { try { - Optional optional = extension.get(); - if (!optional.isPresent()) return; - DataExtension dataExtension = optional.get(); - - String extensionName = ExtensionExtractor.getPluginName(dataExtension.getClass()); - if (disabledExtensions.contains(extensionName)) return; - - extensionService.register(dataExtension); + // Creates the extension with factory and registers it + createExtension.apply(factory).flatMap(this::register); } catch (IllegalStateException | NoClassDefFoundError | IncompatibleClassChangeError e) { // Places all exceptions to one exception with plugin information so that they can be reported. - if (registerException == null) { - registerException = new IllegalStateException("One or more extensions failed to register:"); - registerException.setStackTrace(new StackTraceElement[0]); - } - IllegalStateException info = new IllegalStateException(factory.getSimpleName() + " ran into exception when creating Extension", e); - info.setStackTrace(new StackTraceElement[0]); - registerException.addSuppressed(info); + suppressException(factory.getClass(), e); } } + + private void register( + T factory, + Function> createExtension, + BiConsumer registerListener + ) { + try { + // Creates the extension with factory and registers it, then registers listener + createExtension.apply(factory) + .flatMap(this::register) + .ifPresent(caller -> registerListener.accept(factory, caller)); + } catch (IllegalStateException | NoClassDefFoundError | IncompatibleClassChangeError e) { + // Places all exceptions to one exception with plugin information so that they can be reported. + suppressException(factory.getClass(), e); + } + } + + private Optional register(DataExtension dataExtension) { + String extensionName = ExtensionExtractor.getPluginName(dataExtension.getClass()); + if (disabledExtensions.contains(extensionName)) return Optional.empty(); + + return extensionService.register(dataExtension); + } } \ No newline at end of file From 63dcc6328738cd95941016f14e23bc31c6137f67 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 11:26:26 +0300 Subject: [PATCH 13/18] Fixed scope of platform dependencies on a dependency --- Plan/extensions/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle index d81591254..da46aacbb 100644 --- a/Plan/extensions/build.gradle +++ b/Plan/extensions/build.gradle @@ -2,7 +2,7 @@ dependencies { compile project(path: ":api") compile 'com.djrapitops:Extension-AAC:4.0.11-R0.1' compile 'com.djrapitops:Extension-AdvancedAchievements:1.1-R0.3' - compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.7' + compile 'com.djrapitops:Extension-AdvancedBan:2.1.5-R0.8' compile 'com.djrapitops:Extension-ASkyBlock:3.0.9.4-R0.4' compile 'com.djrapitops:Extension-BanManager:5.15.0-R0.5' compile 'com.djrapitops:Extension-CoreProtect:2.16.0-R0.3' From d2799a6151fe24afef183fce3ff2cf9dc86bba1c Mon Sep 17 00:00:00 2001 From: Risto Lahtela Date: Mon, 12 Aug 2019 14:33:49 +0300 Subject: [PATCH 14/18] Artifact archiving --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 5edee204e..5da2acb20 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,9 +6,11 @@ pipeline { steps { dir("Plan") { script { + sh 'rm -rf builds' sh './gradlew clean shadowJar --parallel' } } + archiveArtifacts artifacts: 'Plan/builds/*.jar', fingerprint: false } } stage('Tests') { @@ -50,6 +52,7 @@ pipeline { dir("Plan") { script { sh './gradlew clean --parallel' + sh 'rm -rf builds' } } } From 8bc47db6662d44f3b94d8bd5e2aa4849273c3d24 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 15:11:09 +0300 Subject: [PATCH 15/18] Fixed ViaVersion extension on bungee --- Plan/extensions/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle index da46aacbb..98ba58de1 100644 --- a/Plan/extensions/build.gradle +++ b/Plan/extensions/build.gradle @@ -20,7 +20,7 @@ dependencies { compile 'com.djrapitops:Extension-Sponge-Economy:7.1.0-R0.3' compile 'com.djrapitops:Extension-SuperbVote:0.5.4-R0.1' compile 'com.djrapitops:Extension-Vault:1.7-R0.2' - compile 'com.djrapitops:Extension-ViaVersion:2.1.3-R1.0' + compile 'com.djrapitops:Extension-ViaVersion:2.1.3-R1.1' } shadowJar { From aca1f90dfe5f5a09786f15842d9ef3e0bb9f9794 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 15:22:04 +0300 Subject: [PATCH 16/18] Isolated QueryAPI subscribers from one another - Exceptions no longer block rest from execution. --- .../query/QueryServiceImplementation.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/query/QueryServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/query/QueryServiceImplementation.java index ba45cebe5..746c371d1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/query/QueryServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/query/QueryServiceImplementation.java @@ -16,6 +16,7 @@ */ package com.djrapitops.plan.query; +import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.access.QueryAPIExecutable; import com.djrapitops.plan.db.access.QueryAPIQuery; @@ -23,6 +24,9 @@ import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import javax.inject.Inject; import javax.inject.Singleton; @@ -39,6 +43,8 @@ public class QueryServiceImplementation implements QueryService { private DBSystem dbSystem; private ServerInfo serverInfo; + private final PluginLogger logger; + private final ErrorHandler errorHandler; private Set> playerRemoveSubscribers; private Set clearSubscribers; @@ -46,10 +52,14 @@ public class QueryServiceImplementation implements QueryService { @Inject public QueryServiceImplementation( DBSystem dbSystem, - ServerInfo serverInfo + ServerInfo serverInfo, + PluginLogger logger, + ErrorHandler errorHandler ) { this.dbSystem = dbSystem; this.serverInfo = serverInfo; + this.logger = logger; + this.errorHandler = errorHandler; playerRemoveSubscribers = new HashSet<>(); clearSubscribers = new HashSet<>(); @@ -94,11 +104,25 @@ public class QueryServiceImplementation implements QueryService { } public void playerRemoved(UUID playerUUID) { - playerRemoveSubscribers.forEach(subscriber -> subscriber.accept(playerUUID)); + playerRemoveSubscribers.forEach(subscriber -> { + try { + subscriber.accept(playerUUID); + } catch (DBOpException e) { + logger.warn("User of Query API (" + subscriber.getClass().getName() + ") ran into exception, failed safely:"); + errorHandler.log(L.WARN, QueryService.class, e); + } + }); } public void dataCleared() { - clearSubscribers.forEach(VoidFunction::apply); + clearSubscribers.forEach(function -> { + try { + function.apply(); + } catch (DBOpException e) { + logger.warn("User of Query API (" + function.getClass().getName() + ") ran into exception, failed safely:"); + errorHandler.log(L.WARN, QueryService.class, e); + } + }); } @Override From 1f1a2960f9cfc77162ef09f506d0f3fb6bd040e5 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 15:25:01 +0300 Subject: [PATCH 17/18] Bump version to 4.9.3 --- Plan/build.gradle | 2 +- Plan/common/src/main/resources/bungee.yml | 2 +- Plan/common/src/main/resources/plugin.yml | 2 +- Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java | 2 +- .../src/main/java/com/djrapitops/plan/PlanVelocity.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plan/build.gradle b/Plan/build.gradle index e35fc564d..19f920e8c 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -22,7 +22,7 @@ allprojects { wrapper.gradleVersion = "5.5.1" group "com.djrapitops" - version "4.9.2" + version "4.9.3" test { useJUnitPlatform() diff --git a/Plan/common/src/main/resources/bungee.yml b/Plan/common/src/main/resources/bungee.yml index d3ae579a5..2dbd9dc24 100644 --- a/Plan/common/src/main/resources/bungee.yml +++ b/Plan/common/src/main/resources/bungee.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.PlanBungee -version: 4.9.2 +version: 4.9.3 softdepend: - AdvancedBan - LiteBans diff --git a/Plan/common/src/main/resources/plugin.yml b/Plan/common/src/main/resources/plugin.yml index 90c662265..bf1c364ed 100644 --- a/Plan/common/src/main/resources/plugin.yml +++ b/Plan/common/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.Plan -version: 4.9.2 +version: 4.9.3 api-version: 1.13 softdepend: - ASkyBlock diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java index 4836062c6..e97fc88c6 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -42,7 +42,7 @@ import java.io.InputStream; @Plugin( id = "plan", name = "Plan", - version = "4.9.2", + version = "4.9.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}, dependencies = { diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java index 88ce84043..854c2a428 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java @@ -46,7 +46,7 @@ import java.nio.file.Path; @Plugin( id = "plan", name = "Plan", - version = "4.9.2", + version = "4.9.3", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"} ) From b5b08491f83afd3a70c70b4c2e3253a66bb5e5cf Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 12 Aug 2019 15:45:52 +0300 Subject: [PATCH 18/18] Fix compile error in test --- .../test/java/com/djrapitops/plan/db/DatabaseTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java index fca4e77fe..0f0d70cc5 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DatabaseTest.java @@ -591,14 +591,16 @@ public interface DatabaseTest { session.endSession(sessionStart + 22345L); execute(DataStoreQueries.storeSession(session)); + TestPluginLogger logger = new TestPluginLogger(); + ConsoleErrorLogger errorHandler = new ConsoleErrorLogger(logger); new DBCleanTask( system().getConfigSystem().getConfig(), new Locale(), system().getDatabaseSystem(), - new QueryServiceImplementation(system().getDatabaseSystem(), system().getServerInfo()), + new QueryServiceImplementation(system().getDatabaseSystem(), system().getServerInfo(), logger, errorHandler), system().getServerInfo(), - new TestPluginLogger(), - new ConsoleErrorLogger(new TestPluginLogger()) + logger, + errorHandler ).cleanOldPlayers(db()); Collection found = db().query(BaseUserQueries.fetchServerBaseUsers(serverUUID()));