Skip to content

Commit 53df8ca

Browse files
Undefinedsbrannen
authored andcommitted
Introduce unit tests for IntegerToEnumConverterFactory
Closes gh-25292
1 parent bf50332 commit 53df8ca

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.core.convert.support;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
23+
24+
/**
25+
* @author Adilson Antunes
26+
*/
27+
class IntegerToEnumConverterFactoryTests {
28+
29+
30+
enum Colors {
31+
RED,
32+
BLUE,
33+
GREEN
34+
}
35+
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);
42+
}
43+
44+
@Test
45+
void throwsArrayIndexOutOfBoundsExceptionIfInvalidEnumInteger() {
46+
final IntegerToEnumConverterFactory enumConverterFactory = new IntegerToEnumConverterFactory();
47+
assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class)
48+
.isThrownBy(() -> enumConverterFactory.getConverter(Colors.class).convert(999));
49+
}
50+
51+
52+
}

0 commit comments

Comments
 (0)