Updated update-method module to JUnit 5 (#1542)

* Updated saga to JUnit 5

* Update fix for CI job in trampoline module

* Updated update-method module to JUnit 5

* Upgraded to latest JUnit Jupiter
JUnit 4 is not needed when using JUnit-Vintage

* Reverted change to access modifier on Trampoline

* Cleanup to resolve code smells

* Formatting

* Formatting

Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
CF
2021-03-04 00:19:31 -05:00
committed by GitHub
parent c3c90e2bd4
commit 903453229c
13 changed files with 99 additions and 101 deletions

10
pom.xml
View File

@ -41,8 +41,8 @@
<spring-data.version>2.0.14.RELEASE</spring-data.version> <spring-data.version>2.0.14.RELEASE</spring-data.version>
<h2.version>1.4.190</h2.version> <h2.version>1.4.190</h2.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version> <junit-jupiter.version>5.7.1</junit-jupiter.version>
<junit-vintage.version>${junit.version}.2</junit-vintage.version> <junit-vintage.version>${junit-jupiter.version}</junit-vintage.version>
<sping-test-junit5.version>1.0.2</sping-test-junit5.version> <sping-test-junit5.version>1.0.2</sping-test-junit5.version>
<compiler.version>3.8.1</compiler.version> <compiler.version>3.8.1</compiler.version>
<jacoco.version>0.8.6</jacoco.version> <jacoco.version>0.8.6</jacoco.version>
@ -274,12 +274,6 @@
<artifactId>camel-stream</artifactId> <artifactId>camel-stream</artifactId>
<version>${camel.version}</version> <version>${camel.version}</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>

View File

@ -35,11 +35,6 @@
<artifactId>saga</artifactId> <artifactId>saga</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>

View File

@ -23,18 +23,19 @@
package com.iluwatar.saga.choreography; package com.iluwatar.saga.choreography;
import com.iluwatar.saga.orchestration.SagaApplication;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import com.iluwatar.saga.orchestration.SagaApplication;
import org.junit.jupiter.api.Test;
/*** /***
* empty test * empty test
*/ */
public class SagaApplicationTest { class SagaApplicationTest {
@Test @Test
public void shouldExecuteWithoutException() { void shouldExecuteWithoutException() {
assertDoesNotThrow(() -> SagaApplication.main(new String[]{})); assertDoesNotThrow(() -> SagaApplication.main(new String[]{}));
} }
} }

View File

@ -23,24 +23,25 @@
package com.iluwatar.saga.choreography; package com.iluwatar.saga.choreography;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* test to check choreography saga * test to check choreography saga
*/ */
public class SagaChoreographyTest { class SagaChoreographyTest {
@Test @Test
public void executeTest() { void executeTest() {
var sd = serviceDiscovery(); var sd = serviceDiscovery();
var service = sd.findAny(); var service = sd.findAny();
var badOrderSaga = service.execute(newSaga("bad_order")); var badOrderSaga = service.execute(newSaga("bad_order"));
var goodOrderSaga = service.execute(newSaga("good_order")); var goodOrderSaga = service.execute(newSaga("good_order"));
Assert.assertEquals(badOrderSaga.getResult(), Saga.SagaResult.ROLLBACKED); assertEquals(Saga.SagaResult.ROLLBACKED, badOrderSaga.getResult());
Assert.assertEquals(goodOrderSaga.getResult(), Saga.SagaResult.FINISHED); assertEquals(Saga.SagaResult.FINISHED, goodOrderSaga.getResult());
} }
private static Saga newSaga(Object value) { private static Saga newSaga(Object value) {

View File

@ -23,15 +23,15 @@
package com.iluwatar.saga.orchestration; package com.iluwatar.saga.orchestration;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* empty test * empty test
*/ */
public class SagaApplicationTest { class SagaApplicationTest {
@Test @Test
public void mainTest() { void mainTest() {
SagaApplication.main(new String[]{}); SagaApplication.main(new String[]{});
} }
} }

View File

@ -23,28 +23,30 @@
package com.iluwatar.saga.orchestration; package com.iluwatar.saga.orchestration;
import org.junit.jupiter.api.Test;
import static com.iluwatar.saga.orchestration.Saga.Result; import static com.iluwatar.saga.orchestration.Saga.Result;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.junit.Test;
/** /**
* test to test orchestration logic * test to test orchestration logic
*/ */
public class SagaOrchestratorInternallyTest { class SagaOrchestratorInternallyTest {
private final List<String> records = new ArrayList<>(); private final List<String> records = new ArrayList<>();
@Test @Test
public void executeTest() { void executeTest() {
var sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery()); var sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
var result = sagaOrchestrator.execute(1); var result = sagaOrchestrator.execute(1);
Assert.assertEquals(result, Result.ROLLBACK); assertEquals(Result.ROLLBACK, result);
Assert.assertArrayEquals( assertArrayEquals(
records.toArray(new String[]{}), new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"},
new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"}); records.toArray(new String[]{}));
} }
private static Saga newSaga() { private static Saga newSaga() {

View File

@ -23,22 +23,23 @@
package com.iluwatar.saga.orchestration; package com.iluwatar.saga.orchestration;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* test to check general logic * test to check general logic
*/ */
public class SagaOrchestratorTest { class SagaOrchestratorTest {
@Test @Test
public void execute() { void execute() {
SagaOrchestrator sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery()); SagaOrchestrator sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
Saga.Result badOrder = sagaOrchestrator.execute("bad_order"); Saga.Result badOrder = sagaOrchestrator.execute("bad_order");
Saga.Result crashedOrder = sagaOrchestrator.execute("crashed_order"); Saga.Result crashedOrder = sagaOrchestrator.execute("crashed_order");
Assert.assertEquals(badOrder, Saga.Result.ROLLBACK); assertEquals(Saga.Result.ROLLBACK, badOrder);
Assert.assertEquals(crashedOrder, Saga.Result.CRASHED); assertEquals(Saga.Result.CRASHED, crashedOrder);
} }
private static Saga newSaga() { private static Saga newSaga() {

View File

@ -98,7 +98,7 @@ public interface Trampoline<T> {
return trampoline(this); return trampoline(this);
} }
private T trampoline(final Trampoline<T> trampoline) { T trampoline(final Trampoline<T> trampoline) {
return Stream.iterate(trampoline, Trampoline::jump) return Stream.iterate(trampoline, Trampoline::jump)
.filter(Trampoline::complete) .filter(Trampoline::complete)
.findFirst() .findFirst()

View File

@ -35,10 +35,6 @@
<artifactId>update-method</artifactId> <artifactId>update-method</artifactId>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>

View File

@ -23,14 +23,14 @@
package com.iluwatar.updatemethod; package com.iluwatar.updatemethod;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
public class AppTest { class AppTest {
@Test @Test
public void shouldExecuteApplicationWithoutException() { void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{})); assertDoesNotThrow(() -> App.main(new String[]{}));
} }
} }

View File

@ -23,56 +23,60 @@
package com.iluwatar.updatemethod; package com.iluwatar.updatemethod;
import org.junit.After; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class SkeletonTest { import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
private Skeleton skeleton;
@Before class SkeletonTest {
public void setup() {
private static Skeleton skeleton;
@BeforeAll
public static void setup() {
skeleton = new Skeleton(1); skeleton = new Skeleton(1);
} }
@After @AfterAll
public void tearDown() { public static void tearDown() {
skeleton = null; skeleton = null;
} }
@Test @Test
public void testUpdateForPatrollingLeft() { void testUpdateForPatrollingLeft() {
skeleton.patrollingLeft = true; skeleton.patrollingLeft = true;
skeleton.setPosition(50); skeleton.setPosition(50);
skeleton.update(); skeleton.update();
Assert.assertEquals(49, skeleton.getPosition()); assertEquals(49, skeleton.getPosition());
} }
@Test @Test
public void testUpdateForPatrollingRight() { void testUpdateForPatrollingRight() {
skeleton.patrollingLeft = false; skeleton.patrollingLeft = false;
skeleton.setPosition(50); skeleton.setPosition(50);
skeleton.update(); skeleton.update();
Assert.assertEquals(51, skeleton.getPosition()); assertEquals(51, skeleton.getPosition());
} }
@Test @Test
public void testUpdateForReverseDirectionFromLeftToRight() { void testUpdateForReverseDirectionFromLeftToRight() {
skeleton.patrollingLeft = true; skeleton.patrollingLeft = true;
skeleton.setPosition(1); skeleton.setPosition(1);
skeleton.update(); skeleton.update();
Assert.assertEquals(0, skeleton.getPosition()); assertEquals(0, skeleton.getPosition());
Assert.assertEquals(false, skeleton.patrollingLeft); assertFalse(skeleton.patrollingLeft);
} }
@Test @Test
public void testUpdateForReverseDirectionFromRightToLeft() { void testUpdateForReverseDirectionFromRightToLeft() {
skeleton.patrollingLeft = false; skeleton.patrollingLeft = false;
skeleton.setPosition(99); skeleton.setPosition(99);
skeleton.update(); skeleton.update();
Assert.assertEquals(100, skeleton.getPosition()); assertEquals(100, skeleton.getPosition());
Assert.assertEquals(true, skeleton.patrollingLeft); assertTrue(skeleton.patrollingLeft);
} }
} }

View File

@ -23,36 +23,37 @@
package com.iluwatar.updatemethod; package com.iluwatar.updatemethod;
import org.junit.After; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class StatueTest { import static org.junit.jupiter.api.Assertions.assertEquals;
private Statue statue; class StatueTest {
@Before private static Statue statue;
public void setup() {
@BeforeAll
public static void setup() {
statue = new Statue(1, 20); statue = new Statue(1, 20);
} }
@After @AfterAll
public void tearDown() { public static void tearDown() {
statue = null; statue = null;
} }
@Test @Test
public void testUpdateForPendingShoot() { void testUpdateForPendingShoot() {
statue.frames = 10; statue.frames = 10;
statue.update(); statue.update();
Assert.assertEquals(11, statue.frames); assertEquals(11, statue.frames);
} }
@Test @Test
public void testUpdateForShooting() { void testUpdateForShooting() {
statue.frames = 19; statue.frames = 19;
statue.update(); statue.update();
Assert.assertEquals(0, statue.frames); assertEquals(0, statue.frames);
} }
} }

View File

@ -23,41 +23,44 @@
package com.iluwatar.updatemethod; package com.iluwatar.updatemethod;
import org.junit.After; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
public class WorldTest { import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
private World world; class WorldTest {
@Before private static World world;
public void setup() {
@BeforeAll
public static void setup() {
world = new World(); world = new World();
} }
@After @AfterAll
public void tearDown() { public static void tearDown() {
world = null; world = null;
} }
@Test @Test
public void testRun() { void testRun() {
world.run(); world.run();
Assert.assertEquals(true, world.isRunning); assertTrue(world.isRunning);
} }
@Test @Test
public void testStop() { void testStop() {
world.stop(); world.stop();
Assert.assertEquals(false, world.isRunning); assertFalse(world.isRunning);
} }
@Test @Test
public void testAddEntity() { void testAddEntity() {
var entity = new Skeleton(1); var entity = new Skeleton(1);
world.addEntity(entity); world.addEntity(entity);
Assert.assertEquals(entity, world.entities.get(0)); assertEquals(entity, world.entities.get(0));
} }
} }