Skip to content

Commit a2717d4

Browse files
committed
Update ProblemStatusTests
1 parent 8f410a3 commit a2717d4

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/test/java/io/github/malczuuu/problem4j/core/ProblemStatusTests.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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

@@ -16,10 +18,34 @@ void givenAmbiguousStatusCode_shouldPrioritizeNonDeprecatedOne(int value)
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)