refactoring: Added parameterization to enumeration test (#1698)

Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>

Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
Elvys Soares 2021-04-22 03:17:45 -03:00 committed by GitHub
parent 323dd63e66
commit af0ccdc6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -38,6 +38,11 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -25,7 +25,8 @@ package com.iluwatar.multiton;
import static org.junit.jupiter.api.Assertions.assertSame; 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 * @author anthony
@ -37,15 +38,14 @@ class NazgulEnumTest {
* Check that multiple calls to any one of the instances in the multiton returns * 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 * only that one particular instance, and do that for all instances in multiton
*/ */
@Test @ParameterizedTest
void testTheSameObjectIsReturnedWithMultipleCalls() { @EnumSource
for (var i = 0; i < NazgulEnum.values().length; i++) { void testTheSameObjectIsReturnedWithMultipleCalls(NazgulEnum nazgulEnum) {
var instance1 = NazgulEnum.values()[i]; var instance1 = nazgulEnum;
var instance2 = NazgulEnum.values()[i]; var instance2 = nazgulEnum;
var instance3 = NazgulEnum.values()[i]; var instance3 = nazgulEnum;
assertSame(instance1, instance2); assertSame(instance1, instance2);
assertSame(instance1, instance3); assertSame(instance1, instance3);
assertSame(instance2, instance3); assertSame(instance2, instance3);
}
} }
} }