From: David ‘Bombe’ Roden Date: Wed, 5 Oct 2016 19:14:06 +0000 (+0200) Subject: Don’t allow null for the post of a PostPart X-Git-Tag: 0.9.6^2~39 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=15f4c53dd87e07b452a04ec2d0e022197e09bd92 Don’t allow null for the post of a PostPart --- diff --git a/src/main/java/net/pterodactylus/sone/text/PostPart.java b/src/main/java/net/pterodactylus/sone/text/PostPart.java index 68075a5..e70448f 100644 --- a/src/main/java/net/pterodactylus/sone/text/PostPart.java +++ b/src/main/java/net/pterodactylus/sone/text/PostPart.java @@ -17,6 +17,10 @@ package net.pterodactylus.sone.text; +import java.util.Objects; + +import javax.annotation.Nonnull; + import net.pterodactylus.sone.data.Post; /** @@ -26,39 +30,17 @@ import net.pterodactylus.sone.data.Post; */ public class PostPart implements Part { - /** The post this part refers to. */ private final Post post; - /** - * Creates a new post part. - * - * @param post - * The referenced post - */ - public PostPart(Post post) { - this.post = post; + public PostPart(@Nonnull Post post) { + this.post = Objects.requireNonNull(post); } - // - // ACCESSORS - // - - /** - * Returns the post referenced by this part. - * - * @return The post referenced by this part - */ + @Nonnull public Post getPost() { return post; } - // - // PART METHODS - // - - /** - * {@inheritDoc} - */ @Override public String getText() { return post.getText(); diff --git a/src/test/java/net/pterodactylus/sone/text/PostPartTest.java b/src/test/java/net/pterodactylus/sone/text/PostPartTest.java index 6666d61..7b4ea19 100644 --- a/src/test/java/net/pterodactylus/sone/text/PostPartTest.java +++ b/src/test/java/net/pterodactylus/sone/text/PostPartTest.java @@ -30,4 +30,9 @@ public class PostPartTest { assertThat(part.getText(), is("text")); } + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForPost() { + new PostPart(null); + } + }