From 16d5fa92c41c0173e6686fb100e4f5796030fb24 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:19:34 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20allow=20null=20for=20Sone=20in?= =?utf8?q?=20SonePart?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/text/SonePart.java | 32 +++++----------------- .../net/pterodactylus/sone/text/SonePartTest.java | 5 ++++ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/SonePart.java b/src/main/java/net/pterodactylus/sone/text/SonePart.java index cbafc61..576eb7b 100644 --- a/src/main/java/net/pterodactylus/sone/text/SonePart.java +++ b/src/main/java/net/pterodactylus/sone/text/SonePart.java @@ -17,6 +17,10 @@ package net.pterodactylus.sone.text; +import java.util.Objects; + +import javax.annotation.Nonnull; + import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; @@ -27,39 +31,17 @@ import net.pterodactylus.sone.template.SoneAccessor; */ public class SonePart implements Part { - /** The referenced {@link Sone}. */ private final Sone sone; - /** - * Creates a new Sone part. - * - * @param sone - * The referenced Sone - */ - public SonePart(Sone sone) { - this.sone = sone; + public SonePart(@Nonnull Sone sone) { + this.sone = Objects.requireNonNull(sone); } - // - // ACCESSORS - // - - /** - * Returns the referenced Sone. - * - * @return The referenced Sone - */ + @Nonnull public Sone getSone() { return sone; } - // - // PART METHODS - // - - /** - * {@inheritDoc} - */ @Override public String getText() { return SoneAccessor.getNiceName(sone); diff --git a/src/test/java/net/pterodactylus/sone/text/SonePartTest.java b/src/test/java/net/pterodactylus/sone/text/SonePartTest.java index 6ca2858..589acf7 100644 --- a/src/test/java/net/pterodactylus/sone/text/SonePartTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SonePartTest.java @@ -34,4 +34,9 @@ public class SonePartTest { assertThat(part.getText(), is("sone")); } + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForSone() { + new SonePart(null); + } + } -- 2.7.4