diff --git a/spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java b/spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java index d33d7929c28..b9f48251e95 100644 --- a/spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java @@ -17,36 +17,46 @@ package org.springframework.core.convert.support; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import org.springframework.core.convert.converter.Converter; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; /** + * Unit tests for {@link IntegerToEnumConverterFactory}. + * * @author Adilson Antunes + * @author Sam Brannen */ class IntegerToEnumConverterFactoryTests { + private final Converter converter = new IntegerToEnumConverterFactory().getConverter(Color.class); - enum Colors { + + @ParameterizedTest + @CsvSource({ + "0, RED", + "1, BLUE", + "2, GREEN" + }) + void convertsIntegerToEnum(int index, Color color) { + assertThat(converter.convert(index)).isEqualTo(color); + } + + @Test + void throwsArrayIndexOutOfBoundsExceptionIfInvalidEnumInteger() { + assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) + .isThrownBy(() -> converter.convert(999)); + } + + + enum Color { RED, BLUE, GREEN } - @Test - void convertIntegerToEnum() { - final IntegerToEnumConverterFactory enumConverterFactory = new IntegerToEnumConverterFactory(); - assertThat(enumConverterFactory.getConverter(Colors.class).convert(0)).isEqualTo(Colors.RED); - assertThat(enumConverterFactory.getConverter(Colors.class).convert(1)).isEqualTo(Colors.BLUE); - assertThat(enumConverterFactory.getConverter(Colors.class).convert(2)).isEqualTo(Colors.GREEN); - } - - @Test - void throwsArrayIndexOutOfBoundsExceptionIfInvalidEnumInteger() { - final IntegerToEnumConverterFactory enumConverterFactory = new IntegerToEnumConverterFactory(); - assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) - .isThrownBy(() -> enumConverterFactory.getConverter(Colors.class).convert(999)); - } - - }