From 15587946e6612ff6e9bd3a81ce91166170b00143 Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Thu, 17 Aug 2017 14:29:18 +0200 Subject: [PATCH 1/3] Fix HastebinTest (Thread wasn't started...) --- ..._com_djrapitops_PlanPluginBridge_3_6_0.xml | 13 ----------- .../com/djrapitops/plan/database/sql/Sql.java | 2 +- .../plan/utilities/dump/HastebinTest.java | 23 +++++++++---------- 3 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 .idea/libraries/Maven__com_djrapitops_PlanPluginBridge_3_6_0.xml diff --git a/.idea/libraries/Maven__com_djrapitops_PlanPluginBridge_3_6_0.xml b/.idea/libraries/Maven__com_djrapitops_PlanPluginBridge_3_6_0.xml deleted file mode 100644 index 6cdeb37a2b..0000000000 --- a/.idea/libraries/Maven__com_djrapitops_PlanPluginBridge_3_6_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java b/Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java index 87d5637707..ae6dbe215a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java @@ -11,6 +11,6 @@ private Sql() { } public static String varchar(int length) { - return "varchar("+length+")"; + return "varchar(" + length + ")"; } } diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java index 6889e07041..5930488a71 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java @@ -15,7 +15,7 @@ import test.java.utils.TestInit; import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNotNull; @@ -28,7 +28,7 @@ @PrepareForTest(JavaPlugin.class) public class HastebinTest { - private AtomicBoolean hastebinAvailable = new AtomicBoolean(); + private AtomicReference testLink = new AtomicReference<>(null); @Before public void checkAvailability() throws Exception { @@ -40,27 +40,25 @@ public void checkAvailability() throws Exception { link = Hastebin.upload(RandomData.randomString(10)); } catch (IOException e) { if (e.getMessage().contains("503")) { - hastebinAvailable.set(false); return; } } catch (ParseException e) { /* Ignored */ } - if (link == null) { - hastebinAvailable.set(false); - } - - Log.info("Availability Test Link: " + link); + Log.info(link); + testLink.set(link); }); + thread.start(); + try { - thread.join(5000); + thread.join(); } catch (InterruptedException e) { - hastebinAvailable.set(false); + Log.info("InterruptedException: " + e.getMessage()); } - Log.info("Hastebin Available: " + hastebinAvailable.get()); + Log.info("Hastebin Availability Test Link: " + testLink.get()); } @Test @@ -75,7 +73,8 @@ public void testSplitting() { @Test public void testUpload() throws Exception { - if (!hastebinAvailable.get()) { + if (testLink.get() == null) { + Log.info("Hastebin not available, skipping testUpload()"); return; } From 47d97252a6ad2b7f29403c5ecfe55580a14b485d Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Thu, 17 Aug 2017 14:40:53 +0200 Subject: [PATCH 2/3] Add Tests for DumpLog --- .../plan/utilities/file/dump/DumpLog.java | 14 +++---- .../plan/utilities/dump/DumpLogTest.java | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java index dd10989875..ff9f924030 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java @@ -17,7 +17,7 @@ public class DumpLog { * * @param header The name of the header */ - void addHeader(String header) { + public void addHeader(String header) { addLine(""); addLine("--- " + header + " ---"); } @@ -28,7 +28,7 @@ void addHeader(String header) { * @param key The key * @param value The value */ - void add(String key, String value) { + public void add(String key, String value) { addLine(key + ": " + value); } @@ -38,7 +38,7 @@ void add(String key, String value) { * @param key The key * @param value The value */ - void add(String key, boolean value) { + public void add(String key, boolean value) { addLine(key + ": " + value); } @@ -49,7 +49,7 @@ void add(String key, boolean value) { * @param key The key * @param value The CharSequences stored in an Iterable */ - void add(String key, Iterable value) { + public void add(String key, Iterable value) { addLine(key + ": " + String.join(", ", value)); } @@ -58,7 +58,7 @@ void add(String key, Iterable value) { * * @param lines The CharSequences stored in an Iterable */ - void addLines(Iterable lines) { + public void addLines(Iterable lines) { lines.forEach(this::addLine); } @@ -67,7 +67,7 @@ void addLines(Iterable lines) { * * @param lines The lines */ - void addLines(CharSequence... lines) { + public void addLines(CharSequence... lines) { Arrays.stream(lines).forEach(this::addLine); } @@ -76,7 +76,7 @@ void addLines(CharSequence... lines) { * * @param line The content of the line */ - private void addLine(CharSequence line) { + public void addLine(CharSequence line) { lines.add(line == null ? "\n" : line.toString()); } diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java new file mode 100644 index 0000000000..97d339e9a7 --- /dev/null +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java @@ -0,0 +1,40 @@ +package test.java.main.java.com.djrapitops.plan.utilities.dump; + +import main.java.com.djrapitops.plan.utilities.file.dump.DumpLog; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +/** + * @author Fuzzlemann + */ +public class DumpLogTest { + + @Test + public void testDumpLogCreation() { + DumpLog testLog = new DumpLog(); + + testLog.addHeader("Test Header"); + testLog.add("StringValue", "Test"); + testLog.add("BooleanValue", true); + testLog.add("IterableValue", Arrays.asList("Iterable 1", "Iterable 2")); + + testLog.addLine(new StringBuilder("CharSequence Test")); + testLog.addLines(new StringBuilder("CharSequences Test"), new StringBuilder("CharSequences Test")); + testLog.addLines(Arrays.asList("Iterable 1", "Iterable 2")); + + String expResult = "\n--- Test Header ---\n" + + "StringValue: Test\n" + + "BooleanValue: true\n" + + "IterableValue: Iterable 1, Iterable 2\n" + + "CharSequence Test\n" + + "CharSequences Test\n" + + "CharSequences Test\n" + + "Iterable 1\n" + + "Iterable 2"; + String result = testLog.toString(); + + Assert.assertEquals(expResult, result); + } +} From 5eecaf0b129204253968ba9b1fff0c23b450d500 Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Thu, 17 Aug 2017 14:43:07 +0200 Subject: [PATCH 3/3] Change some HastebinTest methods --- .../java/com/djrapitops/plan/utilities/dump/DumpLogTest.java | 5 +++-- .../com/djrapitops/plan/utilities/dump/HastebinTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java index 97d339e9a7..d708f7d757 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/DumpLogTest.java @@ -1,11 +1,12 @@ package test.java.main.java.com.djrapitops.plan.utilities.dump; import main.java.com.djrapitops.plan.utilities.file.dump.DumpLog; -import org.junit.Assert; import org.junit.Test; import java.util.Arrays; +import static junit.framework.TestCase.assertEquals; + /** * @author Fuzzlemann */ @@ -35,6 +36,6 @@ public void testDumpLogCreation() { "Iterable 2"; String result = testLog.toString(); - Assert.assertEquals(expResult, result); + assertEquals(expResult, result); } } diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java index 5930488a71..be4618503c 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/utilities/dump/HastebinTest.java @@ -53,9 +53,9 @@ public void checkAvailability() throws Exception { thread.start(); try { - thread.join(); + thread.join(5000); } catch (InterruptedException e) { - Log.info("InterruptedException: " + e.getMessage()); + Log.info("Hastebin timed out"); } Log.info("Hastebin Availability Test Link: " + testLink.get());