From c5715384489bab302e209de0313aeb962d774c2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 5 Oct 2016 19:30:04 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20allow=20null=20for=20any=20attri?= =?utf8?q?bute=20of=20a=20LinkPart?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/text/LinkPart.java | 63 +++++----------------- .../net/pterodactylus/sone/text/LinkPartTest.java | 25 +++++++++ 2 files changed, 37 insertions(+), 51 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/LinkPart.java b/src/main/java/net/pterodactylus/sone/text/LinkPart.java index 6764328..9f889ef 100644 --- a/src/main/java/net/pterodactylus/sone/text/LinkPart.java +++ b/src/main/java/net/pterodactylus/sone/text/LinkPart.java @@ -17,6 +17,10 @@ package net.pterodactylus.sone.text; +import java.util.Objects; + +import javax.annotation.Nonnull; + /** * {@link Part} implementation that can hold a link. A link contains of three * attributes: the link itself, the text that is shown instead of the link, and @@ -26,75 +30,32 @@ package net.pterodactylus.sone.text; */ public class LinkPart implements Part { - /** The link of this part. */ private final String link; - - /** The text of this part. */ private final String text; - - /** The title of this part. */ private final String title; - /** - * Creates a new link part. - * - * @param link - * The link of the link part - * @param text - * The text of the link part - */ - public LinkPart(String link, String text) { + public LinkPart(@Nonnull String link, @Nonnull String text) { this(link, text, text); } - /** - * Creates a new link part. - * - * @param link - * The link of the link part - * @param text - * The text of the link part - * @param title - * The title of the link part - */ - public LinkPart(String link, String text, String title) { - this.link = link; - this.text = text; - this.title = title; + public LinkPart(@Nonnull String link, @Nonnull String text, @Nonnull String title) { + this.link = Objects.requireNonNull(link); + this.text = Objects.requireNonNull(text); + this.title = Objects.requireNonNull(title); } - // - // ACCESSORS - // - - /** - * Returns the link of this part. - * - * @return The link of this part - */ + @Nonnull public String getLink() { return link; } - /** - * Returns the title of this part. - * - * @return The title of this part - */ + @Nonnull public String getTitle() { return title; } - // - // 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/LinkPartTest.java b/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java index 0059b09..431dfa6 100644 --- a/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java +++ b/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java @@ -34,4 +34,29 @@ public class LinkPartTest { assertThat(new LinkPart("link", "text").getTitle(), is("text")); } + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForLink() { + new LinkPart(null, "text", "title"); + } + + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForText() { + new LinkPart("link", null, "title"); + } + + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForLinkInSecondaryConstructor() { + new LinkPart(null, "text"); + } + + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForTextInSecondaryConstructor() { + new LinkPart("link", null); + } + + @Test(expected = NullPointerException.class) + public void nullIsNotAllowedForTitle() { + new LinkPart("link", "text", null); + } + } -- 2.7.4