From 03f81f9079897f8e80a5271ec845bd4a07eba3fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 5 Oct 2016 21:09:56 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20allow=20null=20for=20the=20text?= =?utf8?q?=20attribute=20of=20PlainTextPart?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/text/PlainTextPart.java | 25 ++++++---------------- .../pterodactylus/sone/text/PlainTextPartTest.java | 5 +++++ 2 files changed, 12 insertions(+), 18 deletions(-) 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); + } + } -- 2.7.4