From 15f4c53dd87e07b452a04ec2d0e022197e09bd92 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:14:06 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20allow=20null=20for=20the=20post?= =?utf8?q?=20of=20a=20PostPart?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/text/PostPart.java | 32 +++++----------------- .../net/pterodactylus/sone/text/PostPartTest.java | 5 ++++ 2 files changed, 12 insertions(+), 25 deletions(-) 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); + } + } -- 2.7.4