|
1 | 1 | package io.github.malczuuu.problem4j.core; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.assertNull; |
4 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 3 | +import static java.util.stream.Collectors.toList; |
| 4 | +import static org.assertj.core.api.Assertions.assertThat; |
5 | 5 |
|
| 6 | +import java.util.List; |
6 | 7 | import java.util.Optional; |
| 8 | +import java.util.stream.Stream; |
7 | 9 | import org.junit.jupiter.params.ParameterizedTest; |
8 | 10 | import org.junit.jupiter.params.provider.ValueSource; |
9 | 11 |
|
10 | 12 | class ProblemStatusTests { |
11 | 13 |
|
12 | 14 | @ParameterizedTest |
13 | | - @ValueSource(ints = {103, 413, 414}) |
| 15 | + @ValueSource(ints = {103, 413, 414, 416, 422}) |
14 | 16 | void givenAmbiguousStatusCode_shouldPrioritizeNonDeprecatedOne(int value) |
15 | 17 | throws NoSuchFieldException { |
16 | 18 |
|
17 | 19 | Optional<ProblemStatus> optionalStatus = ProblemStatus.findValue(value); |
18 | 20 |
|
19 | | - assertTrue(optionalStatus.isPresent()); |
| 21 | + assertThat(optionalStatus.isPresent()).isTrue(); |
20 | 22 | ProblemStatus status = optionalStatus.get(); |
21 | 23 | Deprecated deprecationNotice = |
22 | 24 | status.getClass().getField(status.name()).getAnnotation(Deprecated.class); |
23 | | - assertNull(deprecationNotice); |
| 25 | + assertThat(deprecationNotice).isNull(); |
| 26 | + |
| 27 | + List<ProblemStatus> candidates = |
| 28 | + Stream.of(ProblemStatus.values()).filter(v -> v.getStatus() == value).collect(toList()); |
| 29 | + assertThat(candidates.size()) |
| 30 | + .withFailMessage("there was exactly 1 candidate for " + value) |
| 31 | + .isGreaterThan(1); |
| 32 | + } |
| 33 | + |
| 34 | + @ParameterizedTest |
| 35 | + @ValueSource(ints = {305}) |
| 36 | + void givenSingleDeprecatedStatusCode_shouldKeepIt(int value) throws NoSuchFieldException { |
| 37 | + Optional<ProblemStatus> optionalStatus = ProblemStatus.findValue(value); |
| 38 | + |
| 39 | + assertThat(optionalStatus.isPresent()).isTrue(); |
| 40 | + ProblemStatus status = optionalStatus.get(); |
| 41 | + Deprecated deprecationNotice = |
| 42 | + status.getClass().getField(status.name()).getAnnotation(Deprecated.class); |
| 43 | + assertThat(deprecationNotice).isNotNull(); |
| 44 | + |
| 45 | + List<ProblemStatus> candidates = |
| 46 | + Stream.of(ProblemStatus.values()).filter(v -> v.getStatus() == value).collect(toList()); |
| 47 | + assertThat(candidates.size()) |
| 48 | + .withFailMessage("there were more than 1 candidates for " + value) |
| 49 | + .isEqualTo(1); |
24 | 50 | } |
25 | 51 | } |
0 commit comments