-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from Group-5/feat/wrapper
Feat/wrapper
- Loading branch information
Showing
7 changed files
with
634 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
src/test/java/edu/group5/app/control/OrgApiWrapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package edu.group5.app.control; | ||
|
|
||
| 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; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import tools.jackson.core.exc.StreamReadException; | ||
|
|
||
| /** | ||
| * A test class for the OrgApiWrapper class. | ||
| */ | ||
| public class OrgApiWrapperTest { | ||
| String testUrl; | ||
| 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.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()); | ||
| } | ||
|
|
||
| /** | ||
| * 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()); | ||
| } | ||
|
|
||
| /** | ||
| * 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()); | ||
| } | ||
|
|
||
| // /** | ||
| // * Checks if import returns False when there's no internet connection. | ||
| // */ | ||
| // @Test | ||
| // public void noConnectionReturnsFalseImport() { | ||
| // assertDoesNotThrow(() -> { | ||
| // OrgAPIWrapper api = new OrgAPIWrapper(this.testUrl); | ||
| // assertFalse(api.importData()); | ||
| // }); | ||
| // } | ||
|
|
||
| /** | ||
| * Checks if import actually imports something. | ||
| */ | ||
| @Test | ||
| public void importsNonEmptyData() { | ||
| assertDoesNotThrow(() -> { | ||
| OrgApiWrapper api = new OrgApiWrapper(testUrl); | ||
| assertTrue(api.importData()); | ||
| assertFalse(api.getData().length == 0); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * 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()); | ||
| }); | ||
| } | ||
|
|
||
| } |