From e5c3f17361a6a8b9714584d9dacf5fb71685a555 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 10 Feb 2023 09:32:42 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20=E2=80=9CARK?= =?utf8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/test/java/net/pterodactylus/fcp/ARKTest.java | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/ARKTest.java diff --git a/src/test/java/net/pterodactylus/fcp/ARKTest.java b/src/test/java/net/pterodactylus/fcp/ARKTest.java new file mode 100644 index 0000000..1584c55 --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/ARKTest.java @@ -0,0 +1,72 @@ +package net.pterodactylus.fcp; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThrows; + +/** + * Unit test for {@link ARK}. + */ +public class ARKTest { + + @Test + public void twoArgumentConstructorThrowsNPEIfFirstArgumentIsNull() { + assertThrows(NullPointerException.class, () -> new ARK(null, "")); + } + + @Test + public void twoArgumentConstructorThrowsNPEIfSecondArgumentIsNull() { + assertThrows(NullPointerException.class, () -> new ARK("", null)); + } + + @Test + public void twoArgumentConstructorThrowsIAEIfSecondArgumentIsNotNumeric() { + assertThrows(IllegalArgumentException.class, () -> new ARK("", "not-a-number")); + } + + @Test + public void twoArgumentConstructorRetainsPublicUriAndNumber() { + ARK ark = new ARK("public-uri", "123"); + assertThat(ark.getPublicURI(), equalTo("public-uri")); + assertThat(ark.getNumber(), equalTo(123)); + } + + @Test + public void twoArgumentConstructorUsesNullAsPrivateUri() { + ARK ark = new ARK("public-uri", "123"); + assertThat(ark.getPrivateURI(), nullValue()); + } + + @Test + public void threeArgumentConstructorThrowsNPEIfFirstArgumentIsNull() { + assertThrows(NullPointerException.class, () -> new ARK(null, "", "")); + } + + @Test + public void threeArgumentConstructorThrowsNPEIfThirdArgumentIsNull() { + assertThrows(NullPointerException.class, () -> new ARK("", "", null)); + } + + @Test + public void threeArgumentConstructorThrowsIAEIfThirdArgumentIsNotNumeric() { + assertThrows(IllegalArgumentException.class, () -> new ARK("", "", "not-a-number")); + } + + @Test + public void threeArgumentConstructorRetainsPublicUriPrivateUriAndNumber() { + ARK ark = new ARK("public-uri", "private-uri", "123"); + assertThat(ark.getPublicURI(), equalTo("public-uri")); + assertThat(ark.getPrivateURI(), equalTo("private-uri")); + assertThat(ark.getNumber(), equalTo(123)); + } + + @Test + public void threeArgumentConstructorRetainsNullForPrivateUri() { + ARK ark = new ARK("public-uri", null, "123"); + assertThat(ark.getPrivateURI(), nullValue()); + } + +} -- 2.7.4