Skip to content

Commit af0ccdc

Browse files
eas5ohbus
andauthored
refactoring: Added parameterization to enumeration test (iluwatar#1698)
Signed-off-by: Elvys Soares <eas5@cin.ufpe.br> Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
1 parent 323dd63 commit af0ccdc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

multiton/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
<artifactId>junit-jupiter-engine</artifactId>
3939
<scope>test</scope>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter-params</artifactId>
44+
<scope>test</scope>
45+
</dependency>
4146
</dependencies>
4247
<build>
4348
<plugins>

multiton/src/test/java/com/iluwatar/multiton/NazgulEnumTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
import static org.junit.jupiter.api.Assertions.assertSame;
2727

28-
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.EnumSource;
2930

3031
/**
3132
* @author anthony
@@ -37,15 +38,14 @@ class NazgulEnumTest {
3738
* Check that multiple calls to any one of the instances in the multiton returns
3839
* only that one particular instance, and do that for all instances in multiton
3940
*/
40-
@Test
41-
void testTheSameObjectIsReturnedWithMultipleCalls() {
42-
for (var i = 0; i < NazgulEnum.values().length; i++) {
43-
var instance1 = NazgulEnum.values()[i];
44-
var instance2 = NazgulEnum.values()[i];
45-
var instance3 = NazgulEnum.values()[i];
46-
assertSame(instance1, instance2);
47-
assertSame(instance1, instance3);
48-
assertSame(instance2, instance3);
49-
}
41+
@ParameterizedTest
42+
@EnumSource
43+
void testTheSameObjectIsReturnedWithMultipleCalls(NazgulEnum nazgulEnum) {
44+
var instance1 = nazgulEnum;
45+
var instance2 = nazgulEnum;
46+
var instance3 = nazgulEnum;
47+
assertSame(instance1, instance2);
48+
assertSame(instance1, instance3);
49+
assertSame(instance2, instance3);
5050
}
5151
}

0 commit comments

Comments
 (0)