From: David ‘Bombe’ Roden Date: Wed, 5 Oct 2016 19:19:34 +0000 (+0200) Subject: Don’t allow null for Sone in SonePart X-Git-Tag: 0.9.6^2~37 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=16d5fa92c41c0173e6686fb100e4f5796030fb24;p=Sone.git Don’t allow null for Sone in SonePart --- 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); + } + }