11package 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 ;
67import java .util .Optional ;
8+ import java .util .stream .Stream ;
79import org .junit .jupiter .params .ParameterizedTest ;
810import 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