Skip to content

Commit c45f3e2

Browse files
committed
Update tests for ProblemStatus deprecations
1 parent 90347c6 commit c45f3e2

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
11
package io.github.malczuuu.problem4j.core;
22

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;
55

6+
import java.util.List;
67
import java.util.Optional;
8+
import java.util.stream.Stream;
79
import org.junit.jupiter.params.ParameterizedTest;
810
import org.junit.jupiter.params.provider.ValueSource;
911

1012
class ProblemStatusTests {
1113

1214
@ParameterizedTest
13-
@ValueSource(ints = {103, 413, 414})
15+
@ValueSource(ints = {103, 413, 414, 416, 422})
1416
void givenAmbiguousStatusCode_shouldPrioritizeNonDeprecatedOne(int value)
1517
throws NoSuchFieldException {
1618

1719
Optional<ProblemStatus> optionalStatus = ProblemStatus.findValue(value);
1820

19-
assertTrue(optionalStatus.isPresent());
21+
assertThat(optionalStatus.isPresent()).isTrue();
2022
ProblemStatus status = optionalStatus.get();
2123
Deprecated deprecationNotice =
2224
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);
2450
}
2551
}

0 commit comments

Comments
 (0)