Skip to content

Commit

Permalink
test[OrgAPIWrapper]: add tests for OrgAPIWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucy Ciara Herud-Thomassen authored and Lucy Ciara Herud-Thomassen committed Mar 3, 2026
1 parent fecaec9 commit 59be68d
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.IllegalArgumentException;

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";
}

@Test
public void nullURLThrowsException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> 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());
}

@Test
public void faultyURLThrowsException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new OrgAPIWrapper(this.wrongURL));
assertEquals("url has to be valid", exception.getMessage());
}

// @Test
// public void noConnectionReturnsFalseImport() {
// assertDoesNotThrow(() -> {
// OrgAPIWrapper api = new OrgAPIWrapper(this.testURL);
// assertFalse(api.importData());
// });
// }

@Test
public void importsNonEmptyData() {
assertDoesNotThrow(() -> {
OrgAPIWrapper api = new OrgAPIWrapper(testURL);
assertTrue(api.importData());
assertFalse(api.getData().length == 0);
});
}

@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());
});
}

}

0 comments on commit 59be68d

Please sign in to comment.