Skip to content

Commit

Permalink
refactoring: Added parameterization to enumeration test (#1698)
Browse files Browse the repository at this point in the history
Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>

Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
  • Loading branch information
eas5 and ohbus committed Apr 22, 2021
1 parent 323dd63 commit af0ccdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions multiton/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
22 changes: 11 additions & 11 deletions multiton/src/test/java/com/iluwatar/multiton/NazgulEnumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

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

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

/**
* @author anthony
Expand All @@ -37,15 +38,14 @@ class NazgulEnumTest {
* Check that multiple calls to any one of the instances in the multiton returns
* only that one particular instance, and do that for all instances in multiton
*/
@Test
void testTheSameObjectIsReturnedWithMultipleCalls() {
for (var i = 0; i < NazgulEnum.values().length; i++) {
var instance1 = NazgulEnum.values()[i];
var instance2 = NazgulEnum.values()[i];
var instance3 = NazgulEnum.values()[i];
assertSame(instance1, instance2);
assertSame(instance1, instance3);
assertSame(instance2, instance3);
}
@ParameterizedTest
@EnumSource
void testTheSameObjectIsReturnedWithMultipleCalls(NazgulEnum nazgulEnum) {
var instance1 = nazgulEnum;
var instance2 = nazgulEnum;
var instance3 = nazgulEnum;
assertSame(instance1, instance2);
assertSame(instance1, instance3);
assertSame(instance2, instance3);
}
}

0 comments on commit af0ccdc

Please sign in to comment.