From 57f1fe46c24c4ee55da0a0803cd7c587646c841d Mon Sep 17 00:00:00 2001 From: Lucy Ciara Herud-Thomassen <86323303+LucyCiara@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:53:11 +0100 Subject: [PATCH] style[OrgApiWrapperTest]: add javadocs and other formatting changes to the test class --- src/main/java/edu/group5/app/App.java | 11 ++----- .../group5/app/control/OrgApiWrapperTest.java | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/group5/app/App.java b/src/main/java/edu/group5/app/App.java index 5886cd4..dc19a9f 100644 --- a/src/main/java/edu/group5/app/App.java +++ b/src/main/java/edu/group5/app/App.java @@ -1,5 +1,6 @@ package edu.group5.app; +import java.sql.Wrapper; import java.util.HashMap; import edu.group5.app.control.OrgAPIWrapper; @@ -11,14 +12,6 @@ */ public class App { public static void main(String[] args) throws InterruptedException { - OrgAPIWrapper orgWrap = new OrgAPIWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all"); - System.out.println(); - System.out.println(); - orgWrap.importData(); - Object[] imports = orgWrap.getData(); - ObjectMapper objectMapper = new ObjectMapper(); - HashMap map = objectMapper.convertValue(imports[0], new TypeReference>() { - }); - System.out.println(map.get("org_number")); + Wrapper wrap = new Wrapper(); } } diff --git a/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java b/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java index 955e966..53f08d7 100644 --- a/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java +++ b/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java @@ -19,34 +19,49 @@ public class OrgApiWrapperTest { String wrongUrl; String wrongUrl2; + /** + * Initiates the urlStrings used for testing. + */ @BeforeEach void init() { this.testUrl = "https://app.innsamlingskontrollen.no/api/public/v1/all"; - this.wrongUrl = "This is not a Url"; + this.wrongUrl = "This is not a URL"; this.wrongUrl2 = "https://www.google.com"; } + /** + * Checks if inputting null as the urlString throws the expected exception during construction. + */ @Test public void nullUrlThrowsException() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new OrgApiWrapper(null)); - assertEquals("Url can't be null", exception.getMessage()); + assertEquals("url can't be null", exception.getMessage()); } + /** + * Checks if inputting an empty urlString throws the expected exception during construction. + */ @Test public void emptyUrlThrowsException() { IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> new OrgApiWrapper("")); - assertEquals("Url can't be blank", exception.getMessage()); + assertEquals("url can't be blank", exception.getMessage()); } + /** + * Checks if an invalid urlString throws the expected exception during construction. + */ @Test public void faultyUrlThrowsException() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new OrgApiWrapper(this.wrongUrl)); - assertEquals("Url has to be valid", exception.getMessage()); + assertEquals("url has to be valid", exception.getMessage()); } + // /** + // * Checks if import returns False when there's no internet connection. + // */ // @Test // public void noConnectionReturnsFalseImport() { // assertDoesNotThrow(() -> { @@ -55,6 +70,9 @@ public void faultyUrlThrowsException() { // }); // } + /** + * Checks if import actually imports something. + */ @Test public void importsNonEmptyData() { assertDoesNotThrow(() -> { @@ -64,13 +82,16 @@ public void importsNonEmptyData() { }); } + /** + * Checks if an unparseable website throws the expected exception. + */ @Test public void nonParseableSiteThrowsExceptionWhenImporting() { assertDoesNotThrow(() -> { OrgApiWrapper api = new OrgApiWrapper(this.wrongUrl2); StreamReadException exception = assertThrows( StreamReadException.class, () -> api.importData()); - assertEquals("The Url leads to a website that can't be parsed", exception.getMessage()); + assertEquals("The URL leads to a website that can't be parsed", exception.getMessage()); }); }