Skip to content

Commit 9034532

Browse files
charlesfinleyohbus
andauthored
Updated update-method module to JUnit 5 (iluwatar#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>
1 parent c3c90e2 commit 9034532

File tree

13 files changed

+99
-101
lines changed

13 files changed

+99
-101
lines changed

pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<spring-data.version>2.0.14.RELEASE</spring-data.version>
4242
<h2.version>1.4.190</h2.version>
4343
<junit.version>4.12</junit.version>
44-
<junit-jupiter.version>5.5.2</junit-jupiter.version>
45-
<junit-vintage.version>${junit.version}.2</junit-vintage.version>
44+
<junit-jupiter.version>5.7.1</junit-jupiter.version>
45+
<junit-vintage.version>${junit-jupiter.version}</junit-vintage.version>
4646
<sping-test-junit5.version>1.0.2</sping-test-junit5.version>
4747
<compiler.version>3.8.1</compiler.version>
4848
<jacoco.version>0.8.6</jacoco.version>
@@ -274,12 +274,6 @@
274274
<artifactId>camel-stream</artifactId>
275275
<version>${camel.version}</version>
276276
</dependency>
277-
<dependency>
278-
<groupId>junit</groupId>
279-
<artifactId>junit</artifactId>
280-
<version>${junit.version}</version>
281-
<scope>test</scope>
282-
</dependency>
283277
<dependency>
284278
<groupId>org.junit.jupiter</groupId>
285279
<artifactId>junit-jupiter-api</artifactId>

saga/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535

3636
<artifactId>saga</artifactId>
3737
<dependencies>
38-
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
<scope>test</scope>
42-
</dependency>
4338
<dependency>
4439
<groupId>org.junit.jupiter</groupId>
4540
<artifactId>junit-jupiter-engine</artifactId>

saga/src/test/java/com/iluwatar/saga/choreography/SagaApplicationTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@
2323

2424
package com.iluwatar.saga.choreography;
2525

26-
import com.iluwatar.saga.orchestration.SagaApplication;
27-
import org.junit.Test;
28-
2926
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3027

28+
import com.iluwatar.saga.orchestration.SagaApplication;
29+
import org.junit.jupiter.api.Test;
30+
3131

3232
/***
3333
* empty test
3434
*/
35-
public class SagaApplicationTest {
35+
class SagaApplicationTest {
36+
3637
@Test
37-
public void shouldExecuteWithoutException() {
38+
void shouldExecuteWithoutException() {
3839
assertDoesNotThrow(() -> SagaApplication.main(new String[]{}));
3940
}
40-
}
41+
}

saga/src/test/java/com/iluwatar/saga/choreography/SagaChoreographyTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@
2323

2424
package com.iluwatar.saga.choreography;
2525

26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2829

2930
/**
3031
* test to check choreography saga
3132
*/
32-
public class SagaChoreographyTest {
33+
class SagaChoreographyTest {
3334

3435

3536
@Test
36-
public void executeTest() {
37+
void executeTest() {
3738
var sd = serviceDiscovery();
3839
var service = sd.findAny();
3940
var badOrderSaga = service.execute(newSaga("bad_order"));
4041
var goodOrderSaga = service.execute(newSaga("good_order"));
4142

42-
Assert.assertEquals(badOrderSaga.getResult(), Saga.SagaResult.ROLLBACKED);
43-
Assert.assertEquals(goodOrderSaga.getResult(), Saga.SagaResult.FINISHED);
43+
assertEquals(Saga.SagaResult.ROLLBACKED, badOrderSaga.getResult());
44+
assertEquals(Saga.SagaResult.FINISHED, goodOrderSaga.getResult());
4445
}
4546

4647
private static Saga newSaga(Object value) {

saga/src/test/java/com/iluwatar/saga/orchestration/SagaApplicationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
package com.iluwatar.saga.orchestration;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* empty test
3030
*/
31-
public class SagaApplicationTest {
31+
class SagaApplicationTest {
3232

3333
@Test
34-
public void mainTest() {
34+
void mainTest() {
3535
SagaApplication.main(new String[]{});
3636
}
37-
}
37+
}

saga/src/test/java/com/iluwatar/saga/orchestration/SagaOrchestratorInternallyTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@
2323

2424
package com.iluwatar.saga.orchestration;
2525

26+
import org.junit.jupiter.api.Test;
27+
2628
import static com.iluwatar.saga.orchestration.Saga.Result;
29+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
2731

2832
import java.util.ArrayList;
2933
import java.util.List;
30-
import org.junit.Assert;
31-
import org.junit.Test;
3234

3335
/**
3436
* test to test orchestration logic
3537
*/
36-
public class SagaOrchestratorInternallyTest {
38+
class SagaOrchestratorInternallyTest {
3739

3840
private final List<String> records = new ArrayList<>();
3941

4042
@Test
41-
public void executeTest() {
43+
void executeTest() {
4244
var sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
4345
var result = sagaOrchestrator.execute(1);
44-
Assert.assertEquals(result, Result.ROLLBACK);
45-
Assert.assertArrayEquals(
46-
records.toArray(new String[]{}),
47-
new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"});
46+
assertEquals(Result.ROLLBACK, result);
47+
assertArrayEquals(
48+
new String[]{"+1", "+2", "+3", "+4", "-4", "-3", "-2", "-1"},
49+
records.toArray(new String[]{}));
4850
}
4951

5052
private static Saga newSaga() {

saga/src/test/java/com/iluwatar/saga/orchestration/SagaOrchestratorTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323

2424
package com.iluwatar.saga.orchestration;
2525

26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2829

2930
/**
3031
* test to check general logic
3132
*/
32-
public class SagaOrchestratorTest {
33+
class SagaOrchestratorTest {
3334

3435
@Test
35-
public void execute() {
36+
void execute() {
3637
SagaOrchestrator sagaOrchestrator = new SagaOrchestrator(newSaga(), serviceDiscovery());
3738
Saga.Result badOrder = sagaOrchestrator.execute("bad_order");
3839
Saga.Result crashedOrder = sagaOrchestrator.execute("crashed_order");
3940

40-
Assert.assertEquals(badOrder, Saga.Result.ROLLBACK);
41-
Assert.assertEquals(crashedOrder, Saga.Result.CRASHED);
41+
assertEquals(Saga.Result.ROLLBACK, badOrder);
42+
assertEquals(Saga.Result.CRASHED, crashedOrder);
4243
}
4344

4445
private static Saga newSaga() {

trampoline/src/main/java/com/iluwatar/trampoline/Trampoline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public T get() {
9898
return trampoline(this);
9999
}
100100

101-
private T trampoline(final Trampoline<T> trampoline) {
101+
T trampoline(final Trampoline<T> trampoline) {
102102
return Stream.iterate(trampoline, Trampoline::jump)
103103
.filter(Trampoline::complete)
104104
.findFirst()

update-method/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535

3636
<artifactId>update-method</artifactId>
3737
<dependencies>
38-
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
</dependency>
4238
<dependency>
4339
<groupId>org.junit.jupiter</groupId>
4440
<artifactId>junit-jupiter-engine</artifactId>

update-method/src/test/java/com/iluwatar/updatemethod/AppTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
package com.iluwatar.updatemethod;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2929

30-
public class AppTest {
30+
class AppTest {
3131

3232
@Test
33-
public void shouldExecuteApplicationWithoutException() {
33+
void shouldExecuteApplicationWithoutException() {
3434
assertDoesNotThrow(() -> App.main(new String[]{}));
3535
}
3636
}

update-method/src/test/java/com/iluwatar/updatemethod/SkeletonTest.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,60 @@
2323

2424
package com.iluwatar.updatemethod;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.Test;
3029

31-
public class SkeletonTest {
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
31+
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
3233

33-
private Skeleton skeleton;
3434

35-
@Before
36-
public void setup() {
35+
class SkeletonTest {
36+
37+
private static Skeleton skeleton;
38+
39+
@BeforeAll
40+
public static void setup() {
3741
skeleton = new Skeleton(1);
3842
}
3943

40-
@After
41-
public void tearDown() {
44+
@AfterAll
45+
public static void tearDown() {
4246
skeleton = null;
4347
}
4448

4549
@Test
46-
public void testUpdateForPatrollingLeft() {
50+
void testUpdateForPatrollingLeft() {
4751
skeleton.patrollingLeft = true;
4852
skeleton.setPosition(50);
4953
skeleton.update();
50-
Assert.assertEquals(49, skeleton.getPosition());
54+
assertEquals(49, skeleton.getPosition());
5155
}
5256

5357
@Test
54-
public void testUpdateForPatrollingRight() {
58+
void testUpdateForPatrollingRight() {
5559
skeleton.patrollingLeft = false;
5660
skeleton.setPosition(50);
5761
skeleton.update();
58-
Assert.assertEquals(51, skeleton.getPosition());
62+
assertEquals(51, skeleton.getPosition());
5963
}
6064

6165
@Test
62-
public void testUpdateForReverseDirectionFromLeftToRight() {
66+
void testUpdateForReverseDirectionFromLeftToRight() {
6367
skeleton.patrollingLeft = true;
6468
skeleton.setPosition(1);
6569
skeleton.update();
66-
Assert.assertEquals(0, skeleton.getPosition());
67-
Assert.assertEquals(false, skeleton.patrollingLeft);
70+
assertEquals(0, skeleton.getPosition());
71+
assertFalse(skeleton.patrollingLeft);
6872
}
6973

7074
@Test
71-
public void testUpdateForReverseDirectionFromRightToLeft() {
75+
void testUpdateForReverseDirectionFromRightToLeft() {
7276
skeleton.patrollingLeft = false;
7377
skeleton.setPosition(99);
7478
skeleton.update();
75-
Assert.assertEquals(100, skeleton.getPosition());
76-
Assert.assertEquals(true, skeleton.patrollingLeft);
79+
assertEquals(100, skeleton.getPosition());
80+
assertTrue(skeleton.patrollingLeft);
7781
}
7882
}

update-method/src/test/java/com/iluwatar/updatemethod/StatueTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,37 @@
2323

2424
package com.iluwatar.updatemethod;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.Test;
3029

31-
public class StatueTest {
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
3231

33-
private Statue statue;
32+
class StatueTest {
3433

35-
@Before
36-
public void setup() {
34+
private static Statue statue;
35+
36+
@BeforeAll
37+
public static void setup() {
3738
statue = new Statue(1, 20);
3839
}
3940

40-
@After
41-
public void tearDown() {
41+
@AfterAll
42+
public static void tearDown() {
4243
statue = null;
4344
}
4445

4546
@Test
46-
public void testUpdateForPendingShoot() {
47+
void testUpdateForPendingShoot() {
4748
statue.frames = 10;
4849
statue.update();
49-
Assert.assertEquals(11, statue.frames);
50+
assertEquals(11, statue.frames);
5051
}
5152

5253
@Test
53-
public void testUpdateForShooting() {
54+
void testUpdateForShooting() {
5455
statue.frames = 19;
5556
statue.update();
56-
Assert.assertEquals(0, statue.frames);
57+
assertEquals(0, statue.frames);
5758
}
5859
}

0 commit comments

Comments
 (0)