From 2211a8fb249ec913b824eb228e72303765a4958d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sun, 9 Nov 2014 12:45:45 +1100 Subject: [PATCH] fixes (some test cases don't pass) --- .../intellectualcrafters/plot/PlotMain.java | 11 +- .../plot/commands/Claim.java | 3 + PlotSquared/src/test/java/Test1.java | 266 ++++++++++++++++-- 3 files changed, 263 insertions(+), 17 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index f03bd732c..c9cf54eea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -600,7 +600,10 @@ public class PlotMain extends JavaPlugin { // Use mysql? if (Settings.DB.USE_MYSQL) { - DBFunc.dbManager = new SQLManager(); + + if (DBFunc.dbManager == null) { + DBFunc.dbManager = new SQLManager(); + } try { mySQL = new MySQL(this, Settings.DB.HOST_NAME, Settings.DB.PORT, Settings.DB.DATABASE, Settings.DB.USER, Settings.DB.PASSWORD); connection = mySQL.openConnection(); @@ -620,6 +623,12 @@ public class PlotMain extends JavaPlugin { if (!res.next()) { DBFunc.createTables("mysql", false); } + else { + res = meta.getTables(null, null, Settings.DB.PREFIX + "plot_comments", null); + if (!res.next()) { + DBFunc.createTables("mysql", false); + } + } } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 7124bf4f9..100b45b8d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -116,6 +116,9 @@ public class Claim extends SubCommand { final DefaultPlotWorld pW = (DefaultPlotWorld) world; if (pW.CLAIMED_WALL_BLOCK != pW.WALL_BLOCK) { PlotMain.getPlotManager(plot.getWorld()).setWall(plot.getWorld(), world, plot.getId(), pW.CLAIMED_WALL_BLOCK); + if (PlotHelper.canSetFast) { + SetBlockFast.update(player); + } } } } diff --git a/PlotSquared/src/test/java/Test1.java b/PlotSquared/src/test/java/Test1.java index bdec27c3c..db4cd9871 100644 --- a/PlotSquared/src/test/java/Test1.java +++ b/PlotSquared/src/test/java/Test1.java @@ -1,29 +1,256 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Biome; +import org.bukkit.plugin.java.JavaPlugin; import org.junit.Assert; import org.junit.Test; +import com.intellectualcrafters.plot.Flag; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotComment; import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotHomePosition; +import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotManager; import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.SchematicHandler; +import com.intellectualcrafters.plot.SetBlockFast; +import com.intellectualcrafters.plot.Settings; +import com.intellectualcrafters.plot.commands.Schematic; +import com.intellectualcrafters.plot.database.AbstractDB; +import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.generator.DefaultPlotManager; import com.intellectualcrafters.plot.generator.DefaultPlotWorld; +import com.sk89q.worldguard.bukkit.BukkitBlacklist; public class Test1 { + Integer count; + // I have no idea what I should actually test :p + + + public boolean nextTest() { + PlotMain.counter++; + switch (PlotMain.counter) { + case 1: + return test1_Square(); + case 2: + return test2_InitMain(); // fails + case 3: + return test3_InitPlotId(); + case 4: + return test4_InitPlot(); + case 5: + return test5_InitDBFunc(); + case 6: + return test6_Plots(); // fails + case 7: + return test7_OnEnable(); // fails + case 8: + return test8_AddPlotWorld(); // fails + case 9: + return test9_CanSetFast(); // fails + } + return false; + } + + @Test public void t1() {Assert.assertTrue(nextTest());} + @Test public void t2() {Assert.assertTrue(nextTest());} + @Test public void t3() {Assert.assertTrue(nextTest());} + @Test public void t4() {Assert.assertTrue(nextTest());} + @Test public void t5() {Assert.assertTrue(nextTest());} + @Test public void t6() {Assert.assertTrue(nextTest());} + @Test public void t7() {Assert.assertTrue(nextTest());} + @Test public void t8() {Assert.assertTrue(nextTest());} + @Test public void t9() {Assert.assertTrue(nextTest());} - @Test - public void testSquare() { - Assert.assertEquals(PlotHelper.square(5), 25); + public boolean test1_Square() { + return PlotHelper.square(5) == 25; + } + + public boolean test2_InitMain() { + boolean passed = false; + try { + PlotMain plugin = PlotMain.getMain(); + passed = plugin != null; + } + catch (Throwable e) { + + } + return passed; + } + + public boolean test3_InitPlotId() { + boolean passed = false; + try { + Object id = new PlotId(0,0); + passed = id != null; + } + catch (Throwable e) { + + } + return passed; + } + + public boolean test4_InitPlot() { + boolean passed = false; + try { + Object plot = new Plot(new PlotId(0,0), DBFunc.everyone, Biome.FOREST, new ArrayList(), new ArrayList(), new ArrayList(), null, PlotHomePosition.DEFAULT, null, "testworld", new boolean[] {false, false, false, false} ); + passed = plot != null; + } + catch (Throwable e) { + + } + return passed; + } + + public boolean test5_InitDBFunc() { + + Settings.DB.USE_MONGO = true; + Settings.DB.USE_MYSQL = false; + Settings.DB.USE_SQLITE = false; + + boolean passed = false; + try { + DBFunc.dbManager = new AbstractDB() { + + @Override + public void setTrusted(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void setPosition(String world, Plot plot, String position) { + } + @Override + public void setOwner(Plot plot, UUID uuid) { + } + @Override + public void setMerged(String world, Plot plot, boolean[] merged) { + } + @Override + public void setHelper(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void setFlags(String world, Plot plot, Flag[] flags) { + } + @Override + public void setDenied(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void setComment(String world, Plot plot, PlotComment comment) { + } + @Override + public void setAlias(String world, Plot plot, String alias) { + } + @Override + public void removeTrusted(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void removeHelper(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void removeDenied(String world, Plot plot, OfflinePlayer player) { + } + @Override + public void removeComment(String world, Plot plot, PlotComment comment) { + } + @Override + public void purge(String world) { + } + @Override + public void purge(String world, PlotId id) { + } + @Override + public HashMap getSettings(int id) { + return null; + } + @Override + public double getRatings(Plot plot) { + return 0; + } + @Override + public LinkedHashMap> getPlots() { + LinkedHashMap> plots = new LinkedHashMap>(); + + plots.put("testworld", new HashMap()); + + PlotId id = new PlotId(0,0); + + plots.get("testworld").put(id, + new Plot(id, + DBFunc.everyone, + Biome.FOREST, + new ArrayList(), + new ArrayList(), + new ArrayList(), + null, + PlotHomePosition.DEFAULT, + null, + "testworld", + new boolean[] {false, false, false, false})); + + return plots; + } + + @Override + public int getId(String world, PlotId id2) { + return 0; + } + @Override + public ArrayList getComments(String world, Plot plot, int tier) { + return null; + } + @Override + public void delete(String world, Plot plot) { + } + @Override + public void createTables(String database, boolean add_constraint) throws Exception { + } + @Override + public void createPlots(ArrayList plots) { + } + @Override + public void createPlotSettings(int id, Plot plot) { + } + @Override + public void createPlot(Plot plot) { + } + @Override + public void createAllSettingsAndHelpers(ArrayList plots) { + } + }; + passed = true; + } + catch (Throwable e) { + + } + return passed; } - @Test - public void testPlots() { - Assert.assertNotNull(PlotMain.getAllPlotsRaw()); + + public boolean test6_Plots() { + return PlotMain.getAllPlotsRaw() != null; } - - @Test - public void testAddPlotWorld() { + + public boolean test7_OnEnable() { + boolean passed = false; + try { + PlotMain.getMain().onEnable(); + passed = true; + } + catch (Throwable e) { + + } + return passed; + } + + public boolean test8_AddPlotWorld() { boolean passed = false; try { final PlotWorld plotworld = new DefaultPlotWorld("poop"); @@ -34,14 +261,21 @@ public class Test1 { catch (final Throwable e) { } - finally { - Assert.assertTrue(passed); + return passed; + } + + + public boolean test9_CanSetFast() { + boolean passed = false; + try { + new SetBlockFast(); + passed = true; } + catch (Throwable e) { + + } + return passed; } - @Test - public void testCanSetFast() { - Assert.assertTrue(PlotHelper.canSetFast); - } - + }