Skip to content

Commit

Permalink
style[OrgApiWrapperTest]: add javadocs and other formatting changes t…
Browse files Browse the repository at this point in the history
…o the test class
  • Loading branch information
Lucy Ciara Herud-Thomassen authored and Lucy Ciara Herud-Thomassen committed Mar 4, 2026
1 parent e569363 commit 57f1fe4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
11 changes: 2 additions & 9 deletions src/main/java/edu/group5/app/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.group5.app;

import java.sql.Wrapper;
import java.util.HashMap;

import edu.group5.app.control.OrgAPIWrapper;
Expand All @@ -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<String, Object> map = objectMapper.convertValue(imports[0], new TypeReference<HashMap<String, Object>>() {
});
System.out.println(map.get("org_number"));
Wrapper wrap = new Wrapper();
}
}
31 changes: 26 additions & 5 deletions src/test/java/edu/group5/app/control/OrgApiWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand All @@ -55,6 +70,9 @@ public void faultyUrlThrowsException() {
// });
// }

/**
* Checks if import actually imports something.
*/
@Test
public void importsNonEmptyData() {
assertDoesNotThrow(() -> {
Expand All @@ -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());
});
}

Expand Down

0 comments on commit 57f1fe4

Please sign in to comment.