From: David ‘Bombe’ Roden Date: Wed, 5 Oct 2016 19:09:56 +0000 (+0200) Subject: Don’t allow null for the text attribute of PlainTextPart X-Git-Tag: 0.9.6^2~41 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=03f81f9079897f8e80a5271ec845bd4a07eba3fb Don’t allow null for the text attribute of PlainTextPart --- diff --git a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java b/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java index 4f15a73..7bdbee9 100644 --- a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java +++ b/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java @@ -17,6 +17,10 @@ package net.pterodactylus.sone.text; +import java.util.Objects; + +import javax.annotation.Nonnull; + /** * {@link Part} implementation that holds a single piece of text. * @@ -24,29 +28,14 @@ package net.pterodactylus.sone.text; */ public class PlainTextPart implements Part { - /** The text of the part. */ private final String text; - /** - * Creates a new plain-text part. - * - * @param text - * The text of the part - */ - public PlainTextPart(String text) { - this.text = text; + public PlainTextPart(@Nonnull String text) { + this.text = Objects.requireNonNull(text); } - // - // PART METHODS - // - - /** - * Returns the text of this part. - * - * @return The text of this part - */ @Override + @Nonnull public String getText() { return text; } diff --git a/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java b/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java index 8e6f33a..72161ab 100644 --- a/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java +++ b/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java @@ -19,4 +19,9 @@ public class PlainTextPartTest { assertThat(part.getText(), is("text")); } + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForText() { + new PlainTextPart(null); + } + }