Skip to content

Commit

Permalink
api: add missing null check TextDecoration#withState states
Browse files Browse the repository at this point in the history
  • Loading branch information
astei committed Oct 31, 2021
1 parent 5228cce commit edb0a67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static java.util.Objects.requireNonNull;

final class TextDecorationAndStateImpl implements TextDecorationAndState {
private final TextDecoration decoration;
private final TextDecoration.State state;

TextDecorationAndStateImpl(final TextDecoration decoration, final TextDecoration.State state) {
// no null check is required on the decoration since this constructor is always invoked in such a way that
// decoration is always non-null
this.decoration = decoration;
this.state = state;
this.state = requireNonNull(state, "state");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class TextDecorationTest {
@Test
Expand All @@ -34,4 +35,10 @@ void testByBoolean() {
assertEquals(TextDecoration.State.FALSE, TextDecoration.State.byBoolean(false));
assertEquals(TextDecoration.State.TRUE, TextDecoration.State.byBoolean(true));
}

@Test
void withStateOrAsThrowsOnNull() {
assertThrows(NullPointerException.class, () -> TextDecoration.BOLD.as(null));
assertThrows(NullPointerException.class, () -> TextDecoration.BOLD.withState(null));
}
}

0 comments on commit edb0a67

Please sign in to comment.