Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c150871

Browse files
charlesfinleyohbus
andauthored
Update to JUnit5 across all modules (iluwatar#1668)
* 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 * Migrating to JUnit5 and updating some Mockito patterns * Migrating to JUnit5 * Migrating to JUnit5 * Migrating to JUnit 5 * Formatting cleanup * Added missing scope for junit * Fixed tests that were not running previously. Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
1 parent e9d0b3e commit c150871

File tree

53 files changed

+333
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+333
-412
lines changed

arrange-act-assert/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<artifactId>arrange-act-assert</artifactId>
3737
<dependencies>
3838
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-engine</artifactId>
4141
<scope>test</scope>
4242
</dependency>
4343
</dependencies>

arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAAATest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
package com.iluwatar.arrangeactassert;
2525

26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertFalse;
28-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2929

30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131

3232
/**
3333
* Arrange/Act/Assert (AAA) is a pattern for organizing unit tests. It is a way to structure your
@@ -51,10 +51,11 @@
5151
* change and one reason to fail. In a large and complicated code base, tests that honor the single
5252
* responsibility principle are much easier to troubleshoot.
5353
*/
54-
public class CashAAATest {
54+
55+
class CashAAATest {
5556

5657
@Test
57-
public void testPlus() {
58+
void testPlus() {
5859
//Arrange
5960
var cash = new Cash(3);
6061
//Act
@@ -64,7 +65,7 @@ public void testPlus() {
6465
}
6566

6667
@Test
67-
public void testMinus() {
68+
void testMinus() {
6869
//Arrange
6970
var cash = new Cash(8);
7071
//Act
@@ -75,7 +76,7 @@ public void testMinus() {
7576
}
7677

7778
@Test
78-
public void testInsufficientMinus() {
79+
void testInsufficientMinus() {
7980
//Arrange
8081
var cash = new Cash(1);
8182
//Act
@@ -86,7 +87,7 @@ public void testInsufficientMinus() {
8687
}
8788

8889
@Test
89-
public void testUpdate() {
90+
void testUpdate() {
9091
//Arrange
9192
var cash = new Cash(5);
9293
//Act

arrange-act-assert/src/test/java/com/iluwatar/arrangeactassert/CashAntiAAATest.java

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

2424
package com.iluwatar.arrangeactassert;
2525

26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertFalse;
28-
import static org.junit.Assert.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2929

30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131

3232
/**
3333
* ({@link CashAAATest}) is an anti-example of AAA pattern. This test is functionally correct, but
34-
* with the addition of new feature, it needs refactoring. There are an awful lot of steps in that
34+
* with the addition of a new feature, it needs refactoring. There are an awful lot of steps in that
3535
* test method, but it verifies the class' important behavior in just eleven lines. It violates the
3636
* single responsibility principle. If this test method failed after a small code change, it might
3737
* take some digging to discover why.
3838
*/
39-
public class CashAntiAAATest {
39+
40+
class CashAntiAAATest {
4041

4142
@Test
42-
public void testCash() {
43+
void testCash() {
4344
//initialize
4445
var cash = new Cash(3);
4546
//test plus

async-method-invocation/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
<artifactId>mockito-core</artifactId>
4646
<scope>test</scope>
4747
</dependency>
48-
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
51-
<scope>test</scope>
52-
</dependency>
5348
</dependencies>
5449
<build>
5550
<plugins>

combinator/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434

3535
<artifactId>combinator</artifactId>
3636
<dependencies>
37-
<dependency>
38-
<groupId>junit</groupId>
39-
<artifactId>junit</artifactId>
40-
<scope>test</scope>
41-
</dependency>
42-
4337
<dependency>
4438
<groupId>org.junit.jupiter</groupId>
4539
<artifactId>junit-jupiter-engine</artifactId>

combinator/src/test/java/com/iluwatar/combinator/CombinatorAppTest.java

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

2424
package com.iluwatar.combinator;
2525

26-
import org.junit.Test;
27-
2826
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2927

30-
public class CombinatorAppTest {
28+
import org.junit.jupiter.api.Test;
29+
30+
class CombinatorAppTest {
3131

3232
/**
3333
* Issue: Add at least one assertion to this test case.
@@ -37,7 +37,7 @@ public class CombinatorAppTest {
3737
*/
3838

3939
@Test
40-
public void shouldExecuteApplicationWithoutException() {
40+
void shouldExecuteApplicationWithoutException() {
4141
assertDoesNotThrow(() -> CombinatorApp.main(new String[]{}));
4242
}
43-
}
43+
}

combinator/src/test/java/com/iluwatar/combinator/FinderTest.java

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

2424
package com.iluwatar.combinator;
2525

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

29-
import java.util.List;
28+
import org.junit.jupiter.api.Test;
3029

31-
import static org.junit.Assert.*;
32-
33-
public class FinderTest {
30+
class FinderTest {
3431

3532
@Test
36-
public void contains() {
33+
void contains() {
3734
var example = "the first one \nthe second one \n";
3835

3936
var result = Finder.contains("second").find(example);
40-
Assert.assertEquals(result.size(),1);
41-
Assert.assertEquals(result.get(0),"the second one ");
37+
assertEquals(1, result.size());
38+
assertEquals("the second one ", result.get(0));
4239
}
4340

44-
}
41+
}

combinator/src/test/java/com/iluwatar/combinator/FindersTest.java

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

2424
package com.iluwatar.combinator;
2525

26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import static com.iluwatar.combinator.Finders.advancedFinder;
27+
import static com.iluwatar.combinator.Finders.expandedFinder;
28+
import static com.iluwatar.combinator.Finders.filteredFinder;
29+
import static com.iluwatar.combinator.Finders.specializedFinder;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
2831

29-
import java.util.List;
32+
import org.junit.jupiter.api.Test;
3033

31-
import static com.iluwatar.combinator.Finders.*;
32-
import static org.junit.Assert.*;
33-
34-
public class FindersTest {
34+
class FindersTest {
3535

3636
@Test
37-
public void advancedFinderTest() {
37+
void advancedFinderTest() {
3838
var res = advancedFinder("it was","kingdom","sea").find(text());
39-
Assert.assertEquals(res.size(),1);
40-
Assert.assertEquals(res.get(0),"It was many and many a year ago,");
39+
assertEquals(1, res.size());
40+
assertEquals("It was many and many a year ago,", res.get(0));
4141
}
4242

4343
@Test
44-
public void filteredFinderTest() {
44+
void filteredFinderTest() {
4545
var res = filteredFinder(" was ", "many", "child").find(text());
46-
Assert.assertEquals(res.size(),1);
47-
Assert.assertEquals(res.get(0),"But we loved with a love that was more than love-");
46+
assertEquals(1, res.size());
47+
assertEquals("But we loved with a love that was more than love-", res.get(0));
4848
}
4949

5050
@Test
51-
public void specializedFinderTest() {
51+
void specializedFinderTest() {
5252
var res = specializedFinder("love","heaven").find(text());
53-
Assert.assertEquals(res.size(),1);
54-
Assert.assertEquals(res.get(0),"With a love that the winged seraphs of heaven");
53+
assertEquals(1, res.size());
54+
assertEquals("With a love that the winged seraphs of heaven", res.get(0));
5555
}
5656

5757
@Test
58-
public void expandedFinderTest() {
58+
void expandedFinderTest() {
5959
var res = expandedFinder("It was","kingdom").find(text());
60-
Assert.assertEquals(res.size(),3);
61-
Assert.assertEquals(res.get(0),"It was many and many a year ago,");
62-
Assert.assertEquals(res.get(1),"In a kingdom by the sea,");
63-
Assert.assertEquals(res.get(2),"In this kingdom by the sea;");
60+
assertEquals(3, res.size());
61+
assertEquals("It was many and many a year ago,", res.get(0));
62+
assertEquals("In a kingdom by the sea,", res.get(1));
63+
assertEquals("In this kingdom by the sea;", res.get(2));
6464
}
6565

6666

@@ -80,4 +80,4 @@ private String text(){
8080
+ "Coveted her and me.";
8181
}
8282

83-
}
83+
}

double-buffer/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
<artifactId>double-buffer</artifactId>
3737

3838
<dependencies>
39-
<dependency>
40-
<groupId>junit</groupId>
41-
<artifactId>junit</artifactId>
42-
</dependency>
4339
<dependency>
4440
<groupId>org.apache.commons</groupId>
4541
<artifactId>commons-lang3</artifactId>

double-buffer/src/test/java/com/iluwatar/doublebuffer/AppTest.java

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

2424
package com.iluwatar.doublebuffer;
2525

26-
import org.junit.Test;
27-
2826
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2927

28+
import org.junit.jupiter.api.Test;
29+
3030
/**
3131
* App unit test.
3232
*/
33-
public class AppTest {
33+
class AppTest {
3434

3535
/**
3636
* Issue: Add at least one assertion to this test case.
@@ -40,7 +40,7 @@ public class AppTest {
4040
*/
4141

4242
@Test
43-
public void shouldExecuteApplicationWithoutException() {
43+
void shouldExecuteApplicationWithoutException() {
4444
assertDoesNotThrow(() -> App.main(new String[]{}));
4545
}
4646

double-buffer/src/test/java/com/iluwatar/doublebuffer/FrameBufferTest.java

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

2424
package com.iluwatar.doublebuffer;
2525

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.fail;
28+
2629
import java.util.Arrays;
27-
import org.junit.Assert;
28-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
2931

3032
/**
3133
* FrameBuffer unit test.
3234
*/
33-
public class FrameBufferTest {
35+
class FrameBufferTest {
3436

3537
@Test
36-
public void testClearAll() {
38+
void testClearAll() {
3739
try {
3840
var field = FrameBuffer.class.getDeclaredField("pixels");
3941
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
@@ -43,14 +45,14 @@ public void testClearAll() {
4345
field.setAccessible(true);
4446
field.set(frameBuffer, pixels);
4547
frameBuffer.clearAll();
46-
Assert.assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
48+
assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
4749
} catch (NoSuchFieldException | IllegalAccessException e) {
48-
Assert.fail("Fail to modify field access.");
50+
fail("Fail to modify field access.");
4951
}
5052
}
5153

5254
@Test
53-
public void testClear() {
55+
void testClear() {
5456
try {
5557
var field = FrameBuffer.class.getDeclaredField("pixels");
5658
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
@@ -60,21 +62,21 @@ public void testClear() {
6062
field.setAccessible(true);
6163
field.set(frameBuffer, pixels);
6264
frameBuffer.clear(0, 0);
63-
Assert.assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
65+
assertEquals(Pixel.WHITE, frameBuffer.getPixels()[0]);
6466
} catch (NoSuchFieldException | IllegalAccessException e) {
65-
Assert.fail("Fail to modify field access.");
67+
fail("Fail to modify field access.");
6668
}
6769
}
6870

6971
@Test
70-
public void testDraw() {
72+
void testDraw() {
7173
var frameBuffer = new FrameBuffer();
7274
frameBuffer.draw(0, 0);
73-
Assert.assertEquals(Pixel.BLACK, frameBuffer.getPixels()[0]);
75+
assertEquals(Pixel.BLACK, frameBuffer.getPixels()[0]);
7476
}
7577

7678
@Test
77-
public void testGetPixels() {
79+
void testGetPixels() {
7880
try {
7981
var field = FrameBuffer.class.getDeclaredField("pixels");
8082
var pixels = new Pixel[FrameBuffer.HEIGHT * FrameBuffer.WIDTH];
@@ -83,9 +85,9 @@ public void testGetPixels() {
8385
var frameBuffer = new FrameBuffer();
8486
field.setAccessible(true);
8587
field.set(frameBuffer, pixels);
86-
Assert.assertEquals(pixels, frameBuffer.getPixels());
88+
assertEquals(pixels, frameBuffer.getPixels());
8789
} catch (NoSuchFieldException | IllegalAccessException e) {
88-
Assert.fail("Fail to modify field access.");
90+
fail("Fail to modify field access.");
8991
}
9092
}
9193

0 commit comments

Comments
 (0)