From e730b0d8f8c4f682dfac2fd720d2e4aa3ad999e7 Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Tue, 7 Aug 2018 18:50:33 +0200 Subject: [PATCH] BAEL 1861 (#4913) * BAEL-1861 Replaced real tests with demo test "placeholders" * BAEL-1861 Moved code from new module into existing ones * BAEL-1861 Renamed main() classes to not violate PMD rules --- .../baeldung/runfromjava/FirstUnitTest.java | 24 +++++++++ .../runfromjava/RunJUnit5TestsFromJava.java} | 8 +-- .../baeldung/runfromjava/SecondUnitTest.java | 18 +++++++ testing-modules/runjunitfromjava/pom.xml | 54 ------------------- .../junit/runfromjava/listnode/ListNode.java | 41 -------------- .../runfromjava/listnode/MergeLists.java | 22 -------- .../listnode/RemovedNthElement.java | 26 --------- .../runfromjava/listnode/RotateList.java | 30 ----------- .../junit/runfromjava/listnode/SwapNodes.java | 33 ------------ .../baeldung/runfromjava/FirstUnitTest.java | 24 +++++++++ .../baeldung}/runfromjava/MyTestSuite.java | 2 +- .../runfromjava/RunJUnit4TestsFromJava.java} | 4 +- .../baeldung/runfromjava/SecondUnitTest.java | 18 +++++++ 13 files changed, 91 insertions(+), 213 deletions(-) create mode 100644 testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java rename testing-modules/{runjunitfromjava/src/test/java/com/baeldung/junit5/runfromjava/RunJUnit5Tests.java => junit-5/src/test/java/com/baeldung/runfromjava/RunJUnit5TestsFromJava.java} (90%) create mode 100644 testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java delete mode 100644 testing-modules/runjunitfromjava/pom.xml delete mode 100644 testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/ListNode.java delete mode 100644 testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/MergeLists.java delete mode 100644 testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RemovedNthElement.java delete mode 100644 testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RotateList.java delete mode 100644 testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/SwapNodes.java create mode 100644 testing-modules/testing/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java rename testing-modules/{runjunitfromjava/src/test/java/com/baeldung/junit4 => testing/src/test/java/com/baeldung}/runfromjava/MyTestSuite.java (81%) rename testing-modules/{runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/RunJUnit4Tests.java => testing/src/test/java/com/baeldung/runfromjava/RunJUnit4TestsFromJava.java} (97%) create mode 100644 testing-modules/testing/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java new file mode 100644 index 0000000000..835132240e --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.runfromjava; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class FirstUnitTest { + + @Test + void whenThis_thenThat() { + assertTrue(true); + } + + @Test + void whenSomething_thenSomething() { + assertTrue(true); + } + + @Test + void whenSomethingElse_thenSomethingElse() { + assertTrue(true); + } + +} diff --git a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit5/runfromjava/RunJUnit5Tests.java b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/RunJUnit5TestsFromJava.java similarity index 90% rename from testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit5/runfromjava/RunJUnit5Tests.java rename to testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/RunJUnit5TestsFromJava.java index 8a8f3aae17..309c1bc8c9 100644 --- a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit5/runfromjava/RunJUnit5Tests.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/RunJUnit5TestsFromJava.java @@ -1,4 +1,4 @@ -package com.baeldung.junit5.runfromjava; +package com.baeldung.runfromjava; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; @@ -14,7 +14,7 @@ import static org.junit.platform.engine.discovery.ClassNameFilter.includeClassNa import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage; -public class RunJUnit5Tests { +public class RunJUnit5TestsFromJava { SummaryGeneratingListener listener = new SummaryGeneratingListener(); public void runOne() { @@ -32,7 +32,7 @@ public class RunJUnit5Tests { public void runAll() { LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder .request() - .selectors(selectPackage("com.baeldung.junit5.runfromjava")) + .selectors(selectPackage("com.baeldung.runfromjava")) .filters(includeClassNamePatterns(".*Test")) .build(); Launcher launcher = LauncherFactory.create(); @@ -45,7 +45,7 @@ public class RunJUnit5Tests { } public static void main(String[] args) { - RunJUnit5Tests runner = new RunJUnit5Tests(); + RunJUnit5TestsFromJava runner = new RunJUnit5TestsFromJava(); runner.runAll(); TestExecutionSummary summary = runner.listener.getSummary(); diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java new file mode 100644 index 0000000000..b6a387d852 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.runfromjava; + +import org.junit.jupiter.api.RepeatedTest; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SecondUnitTest { + + @RepeatedTest(10) + void whenSomething_thenSomething() { + assertTrue(true); + } + + @RepeatedTest(5) + void whenSomethingElse_thenSomethingElse() { + assertTrue(true); + } +} diff --git a/testing-modules/runjunitfromjava/pom.xml b/testing-modules/runjunitfromjava/pom.xml deleted file mode 100644 index 8ad3e7ed00..0000000000 --- a/testing-modules/runjunitfromjava/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - 4.0.0 - - com.baeldung.junit - applicationtesting - 0.0.1-SNAPSHOT - jar - - applicationtesting - http://maven.apache.org - - - UTF-8 - 1.8 - 5.2.0 - 1.2.0 - 4.12 - 3.7.0 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - - - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - - - org.junit.platform - junit-platform-launcher - ${junit-launcher.version} - - - junit - junit - ${junit4.version} - - - - diff --git a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/ListNode.java b/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/ListNode.java deleted file mode 100644 index 31cbda15d3..0000000000 --- a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/ListNode.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.junit.runfromjava.listnode; - -public class ListNode { - private int value; - private ListNode next; - - public ListNode(int v) { - value = v; - } - - public ListNode(int v, ListNode next) { - value = v; - this.next = next; - } - - public int getValue() { - return value; - } - - public ListNode getNext() { - return next; - } - - public void setNext(ListNode next) { - this.next = next; - } - - public String toString() { - String result = ""; - ListNode tmp = this; - - while (tmp.next != null) { - result += tmp.value + "->"; - tmp = tmp.next; - } - - result += tmp.value; - - return result.toString(); - } -} diff --git a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/MergeLists.java b/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/MergeLists.java deleted file mode 100644 index f2a24487c8..0000000000 --- a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/MergeLists.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.junit.runfromjava.listnode; - -public class MergeLists { - - public ListNode merge(ListNode list1, ListNode list2) { - - if (list1 == null) { - return list2; - } - if (list2 == null) { - return list1; - } - - if (list1.getValue() <= list2.getValue()) { - list1.setNext(merge(list1.getNext(), list2)); - return list1; - } else { - list2.setNext(merge(list2.getNext(), list1)); - return list2; - } - } -} \ No newline at end of file diff --git a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RemovedNthElement.java b/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RemovedNthElement.java deleted file mode 100644 index 22357aaeee..0000000000 --- a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RemovedNthElement.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.junit.runfromjava.listnode; - -public class RemovedNthElement { - public ListNode removeNthFromEnd(ListNode head, int n) { - - ListNode start = new ListNode(0); - start.setNext(head); - - ListNode fast = start; - ListNode slow = start; - - for (int i = 0; i < n + 1 && fast != null; i++) { - fast = fast.getNext(); - } - - while (fast != null) { - fast = fast.getNext(); - slow = slow.getNext(); - } - - slow.setNext(slow.getNext() - .getNext()); - - return start.getNext(); - } -} diff --git a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RotateList.java b/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RotateList.java deleted file mode 100644 index 52167cbacc..0000000000 --- a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/RotateList.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.junit.runfromjava.listnode; - -public class RotateList { - public ListNode rotateRight(ListNode list, int n) { - - if (list == null || list.getNext() == null) { - return list; - } - - ListNode tmpList = new ListNode(0); - tmpList.setNext(list); - ListNode fast = tmpList; - ListNode slow = tmpList; - - int listLength; - for (listLength = 0; fast.getNext() != null; listLength++) { - fast = fast.getNext(); - } - - for (int j = listLength - n % listLength; j > 0; j--) { - slow = slow.getNext(); - } - - fast.setNext(tmpList.getNext()); - tmpList.setNext(slow.getNext()); - slow.setNext(null); - - return tmpList.getNext(); - } -} diff --git a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/SwapNodes.java b/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/SwapNodes.java deleted file mode 100644 index 076fed0d5e..0000000000 --- a/testing-modules/runjunitfromjava/src/main/java/com/baeldung/junit/runfromjava/listnode/SwapNodes.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.junit.runfromjava.listnode; - -public class SwapNodes { - public ListNode swapPairs(ListNode listHead) { - - ListNode result = new ListNode(0); - result.setNext(listHead); - - ListNode current = result; - - while (current.getNext() != null && current - .getNext() - .getNext() != null) { - - ListNode first = current.getNext(); - ListNode second = current - .getNext() - .getNext(); - - first.setNext(second.getNext()); - current.setNext(second); - current - .getNext() - .setNext(first); - - current = current - .getNext() - .getNext(); - } - - return result.getNext(); - } -} diff --git a/testing-modules/testing/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java new file mode 100644 index 0000000000..0e08c43021 --- /dev/null +++ b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/FirstUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.runfromjava; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class FirstUnitTest { + + @Test + public void whenThis_thenThat() { + assertTrue(true); + } + + @Test + public void whenSomething_thenSomething() { + assertTrue(true); + } + + @Test + public void whenSomethingElse_thenSomethingElse() { + assertTrue(true); + } + +} diff --git a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/MyTestSuite.java b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/MyTestSuite.java similarity index 81% rename from testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/MyTestSuite.java rename to testing-modules/testing/src/test/java/com/baeldung/runfromjava/MyTestSuite.java index 4739b47b88..2413fb1ddf 100644 --- a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/MyTestSuite.java +++ b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/MyTestSuite.java @@ -1,4 +1,4 @@ -package com.baeldung.junit4.runfromjava; +package com.baeldung.runfromjava; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/RunJUnit4Tests.java b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/RunJUnit4TestsFromJava.java similarity index 97% rename from testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/RunJUnit4Tests.java rename to testing-modules/testing/src/test/java/com/baeldung/runfromjava/RunJUnit4TestsFromJava.java index 69b821032a..b44b66440a 100644 --- a/testing-modules/runjunitfromjava/src/test/java/com/baeldung/junit4/runfromjava/RunJUnit4Tests.java +++ b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/RunJUnit4TestsFromJava.java @@ -1,4 +1,4 @@ -package com.baeldung.junit4.runfromjava; +package com.baeldung.runfromjava; import junit.extensions.ActiveTestSuite; import junit.extensions.RepeatedTest; @@ -10,7 +10,7 @@ import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; -public class RunJUnit4Tests { +public class RunJUnit4TestsFromJava { public static void runOne() { JUnitCore junit = new JUnitCore(); diff --git a/testing-modules/testing/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java new file mode 100644 index 0000000000..aa5883562e --- /dev/null +++ b/testing-modules/testing/src/test/java/com/baeldung/runfromjava/SecondUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.runfromjava; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class SecondUnitTest { + + @Test + public void whenSomething_thenSomething() { + assertTrue(true); + } + + @Test + public void whensomethingElse_thenSomethingElse() { + assertTrue(true); + } +}