File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/io/github/malczuuu/problem4j/core
test/java/io/github/malczuuu/problem4j/core Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,15 @@ static ProblemBuilder builder() {
4242 /**
4343 * Creates a named extension for use in a {@link Problem}.
4444 *
45- * @param key the extension key
45+ * @param key the extension key, must not be {@code null}
4646 * @param value the extension value
4747 * @return a new {@link Extension} instance
48+ * @throws IllegalArgumentException if the {@code key} is {@code null}
4849 */
4950 static Extension extension (String key , Object value ) {
51+ if (key == null ) {
52+ throw new IllegalArgumentException ("key cannot be null" );
53+ }
5054 return new ProblemImpl .ExtensionImpl (key , value );
5155 }
5256
Original file line number Diff line number Diff line change 11package io .github .malczuuu .problem4j .core ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
45
56import java .net .URI ;
67import java .util .Arrays ;
@@ -48,4 +49,19 @@ void givenProblem_whenToBuilder_shouldBeAbleToRecreateOriginal() {
4849 assertThat (problem ).isNotSameAs (copy );
4950 assertThat (problem ).isEqualTo (copy );
5051 }
52+
53+ @ Test
54+ void givenProblemExtensionWithNullKey_shouldThrowIllegalArgumentException () {
55+ assertThatThrownBy (() -> Problem .extension (null , "v" ))
56+ .isInstanceOf (IllegalArgumentException .class )
57+ .hasMessage ("key cannot be null" );
58+ }
59+
60+ @ Test
61+ void givenProblemExtensionWithKey_shouldCreateExtension () {
62+ Problem .Extension ext = Problem .extension ("code" , 123 );
63+
64+ assertThat (ext .getKey ()).isEqualTo ("code" );
65+ assertThat (ext .getValue ()).isEqualTo (123 );
66+ }
5167}
You can’t perform that action at this time.
0 commit comments