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:
10
pom.xml
10
pom.xml
@ -41,8 +41,8 @@
|
||||
<spring-data.version>2.0.14.RELEASE</spring-data.version>
|
||||
<h2.version>1.4.190</h2.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<junit-jupiter.version>5.5.2</junit-jupiter.version>
|
||||
<junit-vintage.version>${junit.version}.2</junit-vintage.version>
|
||||
<junit-jupiter.version>5.7.1</junit-jupiter.version>
|
||||
<junit-vintage.version>${junit-jupiter.version}</junit-vintage.version>
|
||||
<sping-test-junit5.version>1.0.2</sping-test-junit5.version>
|
||||
<compiler.version>3.8.1</compiler.version>
|
||||
<jacoco.version>0.8.6</jacoco.version>
|
||||
@ -274,12 +274,6 @@
|
||||
<artifactId>camel-stream</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
|
@ -35,11 +35,6 @@
|
||||
|
||||
<artifactId>saga</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
|
@ -23,18 +23,19 @@
|
||||
|
||||
package com.iluwatar.saga.choreography;
|
||||
|
||||
import com.iluwatar.saga.orchestration.SagaApplication;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import com.iluwatar.saga.orchestration.SagaApplication;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/***
|
||||
* empty test
|
||||
*/
|
||||
public class SagaApplicationTest {
|
||||
class SagaApplicationTest {
|
||||
|
||||
@Test
|
||||
public void shouldExecuteWithoutException() {
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> SagaApplication.main(new String[]{}));
|
||||
}
|
||||
}
|
@ -23,24 +23,25 @@
|
||||
|
||||
package com.iluwatar.saga.choreography;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* test to check choreography saga
|
||||
*/
|
||||
public class SagaChoreographyTest {
|
||||
class SagaChoreographyTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void executeTest() {
|
||||
void executeTest() {
|
||||
var sd = serviceDiscovery();
|
||||
var service = sd.findAny();
|
||||
var badOrderSaga = service.execute(newSaga("bad_order"));
|
||||
var goodOrderSaga = service.execute(newSaga("good_order"));
|
||||
|
||||
Assert.assertEquals(badOrderSaga.getResult(), Saga.SagaResult.ROLLBACKED);
|
||||
Assert.assertEquals(goodOrderSaga.getResult(), Saga.SagaResult.FINISHED);
|
||||
assertEquals(Saga.SagaResult.ROLLBACKED, badOrderSaga.getResult());
|
||||
assertEquals(Saga.SagaResult.FINISHED, goodOrderSaga.getResult());
|
||||
}
|
||||
|
||||
private static Saga newSaga(Object value) {
|
||||
|
@ -23,15 +23,15 @@
|
||||
|
||||
package com.iluwatar.saga.orchestration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* empty test
|
||||
*/
|
||||
public class SagaApplicationTest {
|
||||
class SagaApplicationTest {
|
||||
|
||||
@Test
|
||||
public void mainTest() {
|
||||
void mainTest() {
|
||||
SagaApplication.main(new String[]{});
|
||||
}
|
||||
}
|
@ -23,28 +23,30 @@
|
||||
|
||||
package com.iluwatar.saga.orchestration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* test to test orchestration logic
|
||||
*/
|
||||
public class SagaOrchestratorInternallyTest {
|
||||
class SagaOrchestratorInternallyTest {
|
||||
|
||||
private final List<String> records = new ArrayList<>();
|
||||
|
||||
@Test
|
||||
public void executeTest() {
|
||||
void executeTest() {
|
||||
var sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
|
||||
var result = sagaOrchestrator.execute(1);
|
||||
Assert.assertEquals(result, Result.ROLLBACK);
|
||||
Assert.assertArrayEquals(
|
||||
records.toArray(new String[]{}),
|
||||
new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"});
|
||||
assertEquals(Result.ROLLBACK, result);
|
||||
assertArrayEquals(
|
||||
new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"},
|
||||
records.toArray(new String[]{}));
|
||||
}
|
||||
|
||||
private static Saga newSaga() {
|
||||
|
@ -23,22 +23,23 @@
|
||||
|
||||
package com.iluwatar.saga.orchestration;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* test to check general logic
|
||||
*/
|
||||
public class SagaOrchestratorTest {
|
||||
class SagaOrchestratorTest {
|
||||
|
||||
@Test
|
||||
public void execute() {
|
||||
void execute() {
|
||||
SagaOrchestrator sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
|
||||
Saga.Result badOrder = sagaOrchestrator.execute("bad_order");
|
||||
Saga.Result crashedOrder = sagaOrchestrator.execute("crashed_order");
|
||||
|
||||
Assert.assertEquals(badOrder, Saga.Result.ROLLBACK);
|
||||
Assert.assertEquals(crashedOrder, Saga.Result.CRASHED);
|
||||
assertEquals(Saga.Result.ROLLBACK, badOrder);
|
||||
assertEquals(Saga.Result.CRASHED, crashedOrder);
|
||||
}
|
||||
|
||||
private static Saga newSaga() {
|
||||
|
@ -98,7 +98,7 @@ public interface Trampoline<T> {
|
||||
return trampoline(this);
|
||||
}
|
||||
|
||||
private T trampoline(final Trampoline<T> trampoline) {
|
||||
T trampoline(final Trampoline<T> trampoline) {
|
||||
return Stream.iterate(trampoline, Trampoline::jump)
|
||||
.filter(Trampoline::complete)
|
||||
.findFirst()
|
||||
|
@ -35,10 +35,6 @@
|
||||
|
||||
<artifactId>update-method</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
|
@ -23,14 +23,14 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
public class AppTest {
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
public void shouldExecuteApplicationWithoutException() {
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
}
|
||||
}
|
||||
|
@ -23,56 +23,60 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.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
|
||||
public void setup() {
|
||||
class SkeletonTest {
|
||||
|
||||
private static Skeleton skeleton;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
skeleton = new Skeleton(1);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
skeleton = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForPatrollingLeft() {
|
||||
void testUpdateForPatrollingLeft() {
|
||||
skeleton.patrollingLeft = true;
|
||||
skeleton.setPosition(50);
|
||||
skeleton.update();
|
||||
Assert.assertEquals(49, skeleton.getPosition());
|
||||
assertEquals(49, skeleton.getPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForPatrollingRight() {
|
||||
void testUpdateForPatrollingRight() {
|
||||
skeleton.patrollingLeft = false;
|
||||
skeleton.setPosition(50);
|
||||
skeleton.update();
|
||||
Assert.assertEquals(51, skeleton.getPosition());
|
||||
assertEquals(51, skeleton.getPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForReverseDirectionFromLeftToRight() {
|
||||
void testUpdateForReverseDirectionFromLeftToRight() {
|
||||
skeleton.patrollingLeft = true;
|
||||
skeleton.setPosition(1);
|
||||
skeleton.update();
|
||||
Assert.assertEquals(0, skeleton.getPosition());
|
||||
Assert.assertEquals(false, skeleton.patrollingLeft);
|
||||
assertEquals(0, skeleton.getPosition());
|
||||
assertFalse(skeleton.patrollingLeft);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForReverseDirectionFromRightToLeft() {
|
||||
void testUpdateForReverseDirectionFromRightToLeft() {
|
||||
skeleton.patrollingLeft = false;
|
||||
skeleton.setPosition(99);
|
||||
skeleton.update();
|
||||
Assert.assertEquals(100, skeleton.getPosition());
|
||||
Assert.assertEquals(true, skeleton.patrollingLeft);
|
||||
assertEquals(100, skeleton.getPosition());
|
||||
assertTrue(skeleton.patrollingLeft);
|
||||
}
|
||||
}
|
||||
|
@ -23,36 +23,37 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StatueTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
private Statue statue;
|
||||
class StatueTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
private static Statue statue;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
statue = new Statue(1, 20);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
statue = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForPendingShoot() {
|
||||
void testUpdateForPendingShoot() {
|
||||
statue.frames = 10;
|
||||
statue.update();
|
||||
Assert.assertEquals(11, statue.frames);
|
||||
assertEquals(11, statue.frames);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateForShooting() {
|
||||
void testUpdateForShooting() {
|
||||
statue.frames = 19;
|
||||
statue.update();
|
||||
Assert.assertEquals(0, statue.frames);
|
||||
assertEquals(0, statue.frames);
|
||||
}
|
||||
}
|
||||
|
@ -23,41 +23,44 @@
|
||||
|
||||
package com.iluwatar.updatemethod;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.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
|
||||
public void setup() {
|
||||
private static World world;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
world = new World();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
world = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
void testRun() {
|
||||
world.run();
|
||||
Assert.assertEquals(true, world.isRunning);
|
||||
assertTrue(world.isRunning);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStop() {
|
||||
void testStop() {
|
||||
world.stop();
|
||||
Assert.assertEquals(false, world.isRunning);
|
||||
assertFalse(world.isRunning);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddEntity() {
|
||||
void testAddEntity() {
|
||||
var entity = new Skeleton(1);
|
||||
world.addEntity(entity);
|
||||
Assert.assertEquals(entity, world.entities.get(0));
|
||||
assertEquals(entity, world.entities.get(0));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user