Skip to content

Commit b733474

Browse files
committed
Polish contribution
See gh-25292
1 parent 53df8ca commit b733474

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

spring-web/src/test/java/org/springframework/core/convert/support/IntegerToEnumConverterFactoryTests.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,46 @@
1717
package org.springframework.core.convert.support;
1818

1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.params.ParameterizedTest;
21+
import org.junit.jupiter.params.provider.CsvSource;
22+
23+
import org.springframework.core.convert.converter.Converter;
2024

2125
import static org.assertj.core.api.Assertions.assertThat;
2226
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
2327

2428
/**
29+
* Unit tests for {@link IntegerToEnumConverterFactory}.
30+
*
2531
* @author Adilson Antunes
32+
* @author Sam Brannen
2633
*/
2734
class IntegerToEnumConverterFactoryTests {
2835

36+
private final Converter<Integer, Color> converter = new IntegerToEnumConverterFactory().getConverter(Color.class);
2937

30-
enum Colors {
31-
RED,
32-
BLUE,
33-
GREEN
34-
}
3538

36-
@Test
37-
void convertIntegerToEnum() {
38-
final IntegerToEnumConverterFactory enumConverterFactory = new IntegerToEnumConverterFactory();
39-
assertThat(enumConverterFactory.getConverter(Colors.class).convert(0)).isEqualTo(Colors.RED);
40-
assertThat(enumConverterFactory.getConverter(Colors.class).convert(1)).isEqualTo(Colors.BLUE);
41-
assertThat(enumConverterFactory.getConverter(Colors.class).convert(2)).isEqualTo(Colors.GREEN);
39+
@ParameterizedTest
40+
@CsvSource({
41+
"0, RED",
42+
"1, BLUE",
43+
"2, GREEN"
44+
})
45+
void convertsIntegerToEnum(int index, Color color) {
46+
assertThat(converter.convert(index)).isEqualTo(color);
4247
}
4348

4449
@Test
4550
void throwsArrayIndexOutOfBoundsExceptionIfInvalidEnumInteger() {
46-
final IntegerToEnumConverterFactory enumConverterFactory = new IntegerToEnumConverterFactory();
4751
assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class)
48-
.isThrownBy(() -> enumConverterFactory.getConverter(Colors.class).convert(999));
52+
.isThrownBy(() -> converter.convert(999));
4953
}
5054

5155

56+
enum Color {
57+
RED,
58+
BLUE,
59+
GREEN
60+
}
61+
5262
}

0 commit comments

Comments
 (0)