From e5693634f8b84466e7fdead12a0356f5eafbfd3e Mon Sep 17 00:00:00 2001
From: Lucy Ciara Herud-Thomassen <86323303+LucyCiara@users.noreply.github.com>
Date: Wed, 4 Mar 2026 14:50:30 +0100
Subject: [PATCH 1/2] style[Wrapper]: add javadocs and change formatting to
conform to google_checks in Wrapper classes and test class
---
google_checks.xml | 482 ++++++++++++++++++
...{OrgAPIWrapper.java => OrgApiWrapper.java} | 28 +-
.../java/edu/group5/app/control/Wrapper.java | 17 +
.../app/model/organization/Organization.java | 20 +-
...rapperTest.java => OrgApiWrapperTest.java} | 55 +-
5 files changed, 563 insertions(+), 39 deletions(-)
create mode 100644 google_checks.xml
rename src/main/java/edu/group5/app/control/{OrgAPIWrapper.java => OrgApiWrapper.java} (62%)
rename src/test/java/edu/group5/app/control/{OrgAPIWrapperTest.java => OrgApiWrapperTest.java} (51%)
diff --git a/google_checks.xml b/google_checks.xml
new file mode 100644
index 0000000..2434e8d
--- /dev/null
+++ b/google_checks.xml
@@ -0,0 +1,482 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/edu/group5/app/control/OrgAPIWrapper.java b/src/main/java/edu/group5/app/control/OrgApiWrapper.java
similarity index 62%
rename from src/main/java/edu/group5/app/control/OrgAPIWrapper.java
rename to src/main/java/edu/group5/app/control/OrgApiWrapper.java
index f8bc7ab..24c82ee 100644
--- a/src/main/java/edu/group5/app/control/OrgAPIWrapper.java
+++ b/src/main/java/edu/group5/app/control/OrgApiWrapper.java
@@ -5,16 +5,24 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
-
import tools.jackson.core.exc.StreamReadException;
import tools.jackson.databind.ObjectMapper;
-public class OrgAPIWrapper extends Wrapper {
+/**
+ * A Class for Wrapping an API.
+ */
+public class OrgApiWrapper extends Wrapper {
private Object[] data;
private HttpClient client;
private HttpRequest request;
- public OrgAPIWrapper(String urlString) {
+ /**
+ * The constructor, which takes a url String and constructs a URI and HttpRequest object from it.
+ * If the url is invalid, it will throw a fitting exception.
+ *
+ * @param urlString A string of the URL that's being connected to.
+ */
+ public OrgApiWrapper(String urlString) {
if (urlString == null) {
throw new IllegalArgumentException("url can't be null");
} else if (urlString.isBlank()) {
@@ -33,6 +41,15 @@ public OrgAPIWrapper(String urlString) {
}
+ /**
+ * A method for importing data from the wrapped API.
+ *
+ * @return Returns a boolean, which indicates if the import was successful. Will be False if, for
+ * example, there is no internet connection.
+ *
+ * @throws InterruptedException This exception is thrown whenever the program is interrupted, like
+ * by ctrl + c.
+ */
@Override
public boolean importData() throws InterruptedException {
try {
@@ -47,6 +64,11 @@ public boolean importData() throws InterruptedException {
}
}
+ /**
+ * A method for accessing the imported data.
+ *
+ * @return Returns an array with HashMaps, which is how data is structured in the API.
+ */
@Override
public Object[] getData() {
return this.data;
diff --git a/src/main/java/edu/group5/app/control/Wrapper.java b/src/main/java/edu/group5/app/control/Wrapper.java
index 012ea2c..ea55179 100644
--- a/src/main/java/edu/group5/app/control/Wrapper.java
+++ b/src/main/java/edu/group5/app/control/Wrapper.java
@@ -1,11 +1,28 @@
package edu.group5.app.control;
+/**
+ * An abstract class for all Wrappers of datasets.
+ */
abstract class Wrapper {
protected Wrapper() {
}
+ /**
+ * An abstract method for importing data from the dataset that child methods wrap.
+ *
+ * @return Returns a boolean, which indicates if the import was successful. Will be False if, for
+ * example, there is no internet connection.
+ *
+ * @throws InterruptedException This exception is thrown whenever the program is interrupted, like
+ * by ctrl + c.
+ */
public abstract boolean importData() throws InterruptedException;
+ /**
+ * An abstract method to access the imported data.
+ *
+ * @return Returns a fitting parsed Object directly from the dataset.
+ */
public abstract Object getData();
}
diff --git a/src/main/java/edu/group5/app/model/organization/Organization.java b/src/main/java/edu/group5/app/model/organization/Organization.java
index be0e810..42844e1 100644
--- a/src/main/java/edu/group5/app/model/organization/Organization.java
+++ b/src/main/java/edu/group5/app/model/organization/Organization.java
@@ -7,13 +7,13 @@
*
*
* An organization is identified by an organization number, a name,
- * trust status, website URL, pre-approval status, and a textual description.
+ * trust status, website Url, pre-approval status, and a textual description.
*
*
* Instances are validated on creation:
*
* - orgNumber must be non-negative
- * - name and websiteURL must not be null or blank
+ * - name and websiteUrl must not be null or blank
* - description must not be null
*
*/
@@ -21,7 +21,7 @@ public record Organization(
int orgNumber,
String name,
boolean trusted,
- String websiteURL,
+ String websiteUrl,
boolean isPreApproved,
String description) {
/**
@@ -30,16 +30,16 @@ public record Organization(
* @param orgNumber the organization number; must be non-negative
* @param name the organization name; must not be null or blank
* @param trusted whether the organization is trusted
- * @param websiteURL the organization's website URL; must not be null or
+ * @param websiteUrl the organization's website Url; must not be null or
* blank
* @param isPreApproved whether the organization is pre-approved
* @param description a textual description of the organization; must not be
* null
- * @throws NullPointerException if name, websiteURL or description is null
+ * @throws NullPointerException if name, websiteUrl or description is null
* @throws IllegalArgumentException if orgNumber is negative, or if name or
- * websiteURL is blank
+ * websiteUrl is blank
*/
- public Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved,
+ public Organization(int orgNumber, String name, boolean trusted, String websiteUrl, boolean isPreApproved,
String description) {
if (orgNumber < 0) {
throw new IllegalArgumentException("orgNumber cannot be negative");
@@ -47,15 +47,15 @@ public Organization(int orgNumber, String name, boolean trusted, String websiteU
this.orgNumber = orgNumber;
this.name = Objects.requireNonNull(name, "name cannot be null");
this.trusted = trusted;
- this.websiteURL = Objects.requireNonNull(websiteURL, "websiteURL cannot be null");
+ this.websiteUrl = Objects.requireNonNull(websiteUrl, "websiteUrl cannot be null");
this.isPreApproved = isPreApproved;
this.description = Objects.requireNonNull(description, "description cannot be null");
if (name.isBlank()) {
throw new IllegalArgumentException("name cannot be blank");
}
- if (websiteURL.isBlank()) {
- throw new IllegalArgumentException("websiteURL cannot be blank");
+ if (websiteUrl.isBlank()) {
+ throw new IllegalArgumentException("websiteUrl cannot be blank");
}
}
}
diff --git a/src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java b/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java
similarity index 51%
rename from src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java
rename to src/test/java/edu/group5/app/control/OrgApiWrapperTest.java
index 6f22c85..955e966 100644
--- a/src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java
+++ b/src/test/java/edu/group5/app/control/OrgApiWrapperTest.java
@@ -1,10 +1,5 @@
package edu.group5.app.control;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import tools.jackson.core.exc.StreamReadException;
-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -12,43 +7,50 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.IllegalArgumentException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import tools.jackson.core.exc.StreamReadException;
-public class OrgAPIWrapperTest {
- String testURL;
- String wrongURL;
- String wrongURL2;
+/**
+ * A test class for the OrgApiWrapper class.
+ */
+public class OrgApiWrapperTest {
+ String testUrl;
+ String wrongUrl;
+ String wrongUrl2;
@BeforeEach
void init() {
- this.testURL = "https://app.innsamlingskontrollen.no/api/public/v1/all";
- this.wrongURL = "This is not a URL";
- this.wrongURL2 = "https://www.google.com";
+ this.testUrl = "https://app.innsamlingskontrollen.no/api/public/v1/all";
+ this.wrongUrl = "This is not a Url";
+ this.wrongUrl2 = "https://www.google.com";
}
@Test
- public void nullURLThrowsException() {
+ public void nullUrlThrowsException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
- () -> new OrgAPIWrapper(null));
- assertEquals("url can't be null", exception.getMessage());
+ () -> new OrgApiWrapper(null));
+ assertEquals("Url can't be null", exception.getMessage());
}
@Test
- public void emptyURLThrowsException() {
- IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new OrgAPIWrapper(""));
- assertEquals("url can't be blank", exception.getMessage());
+ public void emptyUrlThrowsException() {
+ IllegalArgumentException exception = assertThrows(
+ IllegalArgumentException.class, () -> new OrgApiWrapper(""));
+ assertEquals("Url can't be blank", exception.getMessage());
}
@Test
- public void faultyURLThrowsException() {
+ public void faultyUrlThrowsException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
- () -> new OrgAPIWrapper(this.wrongURL));
- assertEquals("url has to be valid", exception.getMessage());
+ () -> new OrgApiWrapper(this.wrongUrl));
+ assertEquals("Url has to be valid", exception.getMessage());
}
// @Test
// public void noConnectionReturnsFalseImport() {
// assertDoesNotThrow(() -> {
- // OrgAPIWrapper api = new OrgAPIWrapper(this.testURL);
+ // OrgAPIWrapper api = new OrgAPIWrapper(this.testUrl);
// assertFalse(api.importData());
// });
// }
@@ -56,7 +58,7 @@ public void faultyURLThrowsException() {
@Test
public void importsNonEmptyData() {
assertDoesNotThrow(() -> {
- OrgAPIWrapper api = new OrgAPIWrapper(testURL);
+ OrgApiWrapper api = new OrgApiWrapper(testUrl);
assertTrue(api.importData());
assertFalse(api.getData().length == 0);
});
@@ -65,9 +67,10 @@ public void importsNonEmptyData() {
@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());
+ 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());
});
}
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 2/2] 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());
});
}