BAEL-1861 Replaced real tests with demo test "placeholders" (#4887)

This commit is contained in:
Predrag Maric 2018-08-03 11:13:45 +02:00 committed by GitHub
parent f4de016e29
commit cc3b35566d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 333 deletions

View File

@ -0,0 +1,25 @@
package com.baeldung.junit4.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);
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.junit4.runfromjava;
import org.junit.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import static org.junit.Assert.*;
public class ListNodeUnitTest {
@Test
public void whenListHasOneElement_thenGetExpectedValue() {
ListNode listNode = new ListNode(42);
assertEquals(listNode.getValue(), 42);
}
@Test
public void whenInitSimpleList_thenGettersGiveExpectedValues() {
ListNode listNode = new ListNode(42, new ListNode(666, null));
assertEquals(listNode.getValue(), 42);
assertEquals(listNode.getNext()
.getValue(), 666);
}
@Test
public void whenConvertingListToString_thenGetExpectedValue() {
ListNode listNode = new ListNode(42, new ListNode(666, new ListNode(15, null)));
assertEquals(listNode.toString(), "42->666->15");
}
}

View File

@ -1,36 +0,0 @@
package com.baeldung.junit4.runfromjava;
import org.junit.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.MergeLists;
import static org.junit.Assert.*;
import org.junit.Before;
public class MergeListsUnitTest {
private ListNode listNode1;
private ListNode listNode2;
private MergeLists mergeLists;
@Before
public void setUp() throws Exception {
mergeLists = new MergeLists();
listNode1 = new ListNode(2, new ListNode(4, new ListNode(6, new ListNode(8, null))));
listNode2 = new ListNode(1, new ListNode(3, new ListNode(5, new ListNode(7, null))));
}
@Test
public void whenMergingNormalLists_thenGetExpectedString() {
assertEquals(mergeLists.merge(listNode1, listNode2)
.toString(), "1->2->3->4->5->6->7->8");
}
@Test
public void whenMergingNullLists_thenGetNull() {
listNode1 = null;
listNode2 = null;
assertNull(mergeLists.merge(listNode1, listNode2));
}
}

View File

@ -4,7 +4,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ ListNodeUnitTest.class, MergeListsUnitTest.class })
@Suite.SuiteClasses({ FirstUnitTest.class, SecondUnitTest.class })
public class MyTestSuite {
}

View File

@ -1,33 +0,0 @@
package com.baeldung.junit4.runfromjava;
import org.junit.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.RemovedNthElement;
import static org.junit.Assert.*;
import org.junit.Before;
public class RemovedNthElementUnitTest {
private ListNode listNode;
private RemovedNthElement removedNthElement;
@Before
public void setUp() throws Exception {
removedNthElement = new RemovedNthElement();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
public void whenRemovingSecondElement_thenReturnExpectedList() {
assertEquals(removedNthElement.removeNthFromEnd(listNode, 2)
.toString(), "42->666->3");
}
@Test
public void whenRemovingThirdElement_thenReturnExpectedList() {
assertEquals(removedNthElement.removeNthFromEnd(listNode, 3)
.toString(), "42->15->3");
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.junit4.runfromjava;
import org.junit.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.RotateList;
import static org.junit.Assert.*;
import org.junit.Before;
public class RotateListUnitTest {
private RotateList rotateList;
private ListNode listNode;
@Before
public void setUp() throws Exception {
rotateList = new RotateList();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
public void whenRotatingListTwice_thenReturnExpectedList() {
assertEquals(rotateList.rotateRight(listNode, 2)
.toString(), "15->3->42->666");
}
@Test
public void whenRotatingListThreeTimes_thenReturnExpectedList() {
assertEquals(rotateList.rotateRight(listNode, 3)
.toString(), "666->15->3->42");
}
}

View File

@ -15,14 +15,14 @@ public class RunJUnit4Tests {
public static void runOne() {
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
junit.run(MergeListsUnitTest.class);
junit.run(FirstUnitTest.class);
}
public static void runAllClasses() {
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
Result result = junit.run(ListNodeUnitTest.class, MergeListsUnitTest.class, RemovedNthElementUnitTest.class, RotateListUnitTest.class, SwapNodesUnitTest.class);
Result result = junit.run(FirstUnitTest.class, SecondUnitTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
@ -44,7 +44,7 @@ public class RunJUnit4Tests {
}
public static void runRepeated() {
Test test = new JUnit4TestAdapter(MergeListsUnitTest.class);
Test test = new JUnit4TestAdapter(SecondUnitTest.class);
RepeatedTest repeatedTest = new RepeatedTest(test, 5);
JUnitCore junit = new JUnitCore();
@ -59,8 +59,8 @@ public class RunJUnit4Tests {
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(MergeListsUnitTest.class), 5));
mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(RemovedNthElementUnitTest.class), 3));
mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(FirstUnitTest.class), 5));
mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(SecondUnitTest.class), 3));
junit.run(mySuite);
}

View File

@ -0,0 +1,18 @@
package com.baeldung.junit4.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);
}
}

View File

@ -1,27 +0,0 @@
package com.baeldung.junit4.runfromjava;
import org.junit.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.SwapNodes;
import static org.junit.Assert.*;
import org.junit.Before;
public class SwapNodesUnitTest {
private SwapNodes swapNodes;
private ListNode listNode;
@Before
public void setUp() throws Exception {
swapNodes = new SwapNodes();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
public void whenSwappingPairs_thenReturnExpectedList() {
assertEquals(swapNodes.swapPairs(listNode)
.toString(), "666->42->3->15");
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.junit5.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);
}
}

View File

@ -1,30 +0,0 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
class ListNodeUnitTest {
@Test
void whenListHasOneElement_thenGetExpectedValue() {
ListNode listNode = new ListNode(42);
assertEquals(listNode.getValue(), 42);
}
@Test
void whenInitSimpleList_thenGettersGiveExpectedValues() {
ListNode listNode = new ListNode(42, new ListNode(666, null));
assertEquals(listNode.getValue(), 42);
assertEquals(listNode.getNext()
.getValue(), 666);
}
@Test
void whenConvertingListToString_thenGetExpectedValue() {
ListNode listNode = new ListNode(42, new ListNode(666, new ListNode(15, null)));
assertEquals(listNode.toString(), "42->666->15");
}
}

View File

@ -1,38 +0,0 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.MergeLists;
class MergeListsUnitTest {
private ListNode listNode1;
private ListNode listNode2;
private MergeLists mergeLists;
@BeforeEach
void setUp() throws Exception {
mergeLists = new MergeLists();
listNode1 = new ListNode(2, new ListNode(4, new ListNode(6, new ListNode(8, null))));
listNode2 = new ListNode(1, new ListNode(3, new ListNode(5, new ListNode(7, null))));
}
@RepeatedTest(10)
void whenMergingNormalLists_thenGetExpectedString() {
assertEquals(mergeLists
.merge(listNode1, listNode2)
.toString(), "1->2->3->4->5->6->7->8");
}
@RepeatedTest(5)
void whenMergingNullLists_thenGetNull() {
listNode1 = null;
listNode2 = null;
assertNull(mergeLists.merge(listNode1, listNode2));
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.RemovedNthElement;
class RemovedNthElementUnitTest {
private ListNode listNode;
private RemovedNthElement removedNthElement;
@BeforeEach
void setUp() throws Exception {
removedNthElement = new RemovedNthElement();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
void whenRemovingSecondElement_thenReturnExpectedList() {
assertEquals(removedNthElement.removeNthFromEnd(listNode, 2)
.toString(), "42->666->3");
}
@Test
void whenRemovingThirdElement_thenReturnExpectedList() {
assertEquals(removedNthElement.removeNthFromEnd(listNode, 3)
.toString(), "42->15->3");
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.RotateList;
class RotateListUnitTest {
private RotateList rotateList;
private ListNode listNode;
@BeforeEach
void setUp() throws Exception {
rotateList = new RotateList();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
void whenRotatingListTwice_thenReturnExpectedList() {
assertEquals(rotateList.rotateRight(listNode, 2)
.toString(), "15->3->42->666");
}
@Test
void whenRotatingListThreeTimes_thenReturnExpectedList() {
assertEquals(rotateList.rotateRight(listNode, 3)
.toString(), "666->15->3->42");
}
}

View File

@ -1,11 +1,5 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.platform.engine.discovery.ClassNameFilter.includeClassNamePatterns;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
import java.io.PrintWriter;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestPlan;
@ -14,13 +8,19 @@ import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import java.io.PrintWriter;
import static org.junit.platform.engine.discovery.ClassNameFilter.includeClassNamePatterns;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
public class RunJUnit5Tests {
SummaryGeneratingListener listener = new SummaryGeneratingListener();
public void runOne() {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(selectClass(RotateListUnitTest.class))
.selectors(selectClass(FirstUnitTest.class))
.build();
Launcher launcher = LauncherFactory.create();
TestPlan testPlan = launcher.discover(request);

View File

@ -0,0 +1,18 @@
package com.baeldung.junit5.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);
}
}

View File

@ -1,27 +0,0 @@
package com.baeldung.junit5.runfromjava;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.baeldung.junit.runfromjava.listnode.ListNode;
import com.baeldung.junit.runfromjava.listnode.SwapNodes;
class SwapNodesUnitTest {
private SwapNodes swapNodes;
private ListNode listNode;
@BeforeEach
void setUp() throws Exception {
swapNodes = new SwapNodes();
listNode = new ListNode(42, new ListNode(666, new ListNode(15, new ListNode(3, null))));
}
@Test
void whenSwappingPairs_thenReturnExpectedList() {
assertEquals(swapNodes.swapPairs(listNode)
.toString(), "666->42->3->15");
}
}