forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #53 from AY2223S1-CS2103T-W11-4/master
Add unit tests
- Loading branch information
Showing
75 changed files
with
4,704 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
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,5 @@ | ||
{ | ||
"logLevel" : "INFO", | ||
"userPrefsFilePath" : "preferences.json", | ||
"extra" : "extra value" | ||
} |
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 @@ | ||
this file is not in json format! |
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,4 @@ | ||
{ | ||
"logLevel" : "INFO", | ||
"userPrefsFilePath" : "preferences.json" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/data/JsonSerializableWaddleTest/duplicateItineraryWaddle.json
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,17 @@ | ||
{ | ||
"itineraries" : [ { | ||
"name" : "Spring Trip", | ||
"country" : "Australia", | ||
"startDate" : "2022-01-01", | ||
"endDate" : "2022-01-15", | ||
"people" : "1", | ||
"items" : [ ] | ||
}, { | ||
"name" : "Spring Trip", | ||
"country" : "Australia", | ||
"startDate" : "2022-01-01", | ||
"endDate" : "2022-01-15", | ||
"people" : "1", | ||
"items" : [ ] | ||
} ] | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/data/JsonSerializableWaddleTest/invalidItineraryWaddle.json
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,10 @@ | ||
{ | ||
"itineraries" : [ { | ||
"name" : "Spring Trip", | ||
"country" : "Australia", | ||
"startDate" : "10", | ||
"endDate" : "20", | ||
"people" : "1", | ||
"items" : [ ] | ||
} ] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/data/JsonSerializableWaddleTest/typicalItinerariesWaddle.json
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,25 @@ | ||
{ | ||
"_comment": "Waddle save file which contains the same Itinerary values as in TypicalItineraries#getTypicalWaddle()", | ||
"itineraries" : [ { | ||
"name" : "Spring Trip", | ||
"country" : "Australia", | ||
"startDate" : "2022-01-01", | ||
"endDate" : "2022-01-15", | ||
"people" : "1", | ||
"items" : [ ] | ||
}, { | ||
"name" : "Autumn Hiking", | ||
"country" : "Canada", | ||
"startDate" : "2022-02-02", | ||
"endDate" : "2022-02-23", | ||
"people" : "2", | ||
"items" : [ ] | ||
}, { | ||
"name" : "Graduation Trip", | ||
"country" : "France", | ||
"startDate" : "2022-03-03", | ||
"endDate" : "2022-03-07", | ||
"people" : "4", | ||
"items" : [ ] | ||
} ] | ||
} |
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,3 @@ | ||
{ | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/test/data/JsonUserPrefsStorageTest/ExtraValuesUserPref.json
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,13 @@ | ||
{ | ||
"guiSettings" : { | ||
"windowWidth" : 1000.0, | ||
"windowHeight" : 500.0, | ||
"extra" : "some value ", | ||
"windowCoordinates" : { | ||
"x" : 300, | ||
"y" : 100, | ||
"z" : 99 | ||
} | ||
}, | ||
"addressBookFilePath" : "addressbook.json" | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/data/JsonUserPrefsStorageTest/NotJsonFormatUserPrefs.json
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 @@ | ||
Not a json file! |
11 changes: 11 additions & 0 deletions
11
src/test/data/JsonUserPrefsStorageTest/TypicalUserPref.json
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,11 @@ | ||
{ | ||
"guiSettings" : { | ||
"windowWidth" : 1000.0, | ||
"windowHeight" : 500.0, | ||
"windowCoordinates" : { | ||
"x" : 300, | ||
"y" : 100 | ||
} | ||
}, | ||
"addressBookFilePath" : "waddle.json" | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/data/JsonWaddleStorageTest/invalidAndValidItineraryWaddle.json
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,13 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Valid Person", | ||
"phone": "9482424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
}, { | ||
"name": "Person With Invalid Phone Field", | ||
"phone": "948asdf2424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
} ] | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/data/JsonWaddleStorageTest/invalidItineraryWaddle.json
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,8 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Person with invalid name field: Ha!ns Mu@ster", | ||
"phone": "9482424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
} ] | ||
} |
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 @@ | ||
not json format! |
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,58 @@ | ||
package seedu.waddle; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import javafx.application.Application; | ||
|
||
public class AppParametersTest { | ||
|
||
private final ParametersStub parametersStub = new ParametersStub(); | ||
private final AppParameters expected = new AppParameters(); | ||
|
||
@Test | ||
public void parse_validConfigPath_success() { | ||
parametersStub.namedParameters.put("config", "config.json"); | ||
expected.setConfigPath(Paths.get("config.json")); | ||
assertEquals(expected, AppParameters.parse(parametersStub)); | ||
} | ||
|
||
@Test | ||
public void parse_nullConfigPath_success() { | ||
parametersStub.namedParameters.put("config", null); | ||
assertEquals(expected, AppParameters.parse(parametersStub)); | ||
} | ||
|
||
@Test | ||
public void parse_invalidConfigPath_success() { | ||
parametersStub.namedParameters.put("config", "a\0"); | ||
expected.setConfigPath(null); | ||
assertEquals(expected, AppParameters.parse(parametersStub)); | ||
} | ||
|
||
private static class ParametersStub extends Application.Parameters { | ||
private Map<String, String> namedParameters = new HashMap<>(); | ||
|
||
@Override | ||
public List<String> getRaw() { | ||
throw new AssertionError("should not be called"); | ||
} | ||
|
||
@Override | ||
public List<String> getUnnamed() { | ||
throw new AssertionError("should not be called"); | ||
} | ||
|
||
@Override | ||
public Map<String, String> getNamed() { | ||
return Collections.unmodifiableMap(namedParameters); | ||
} | ||
} | ||
} |
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,27 @@ | ||
package seedu.waddle.commons.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ConfigTest { | ||
|
||
@Test | ||
public void toString_defaultObject_stringReturned() { | ||
String defaultConfigAsString = "Current log level : INFO\n" | ||
+ "Preference file Location : preferences.json"; | ||
|
||
assertEquals(defaultConfigAsString, new Config().toString()); | ||
} | ||
|
||
@Test | ||
public void equalsMethod() { | ||
Config defaultConfig = new Config(); | ||
assertNotNull(defaultConfig); | ||
assertTrue(defaultConfig.equals(defaultConfig)); | ||
} | ||
|
||
|
||
} |
135 changes: 135 additions & 0 deletions
135
src/test/java/seedu/waddle/commons/core/VersionTest.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,135 @@ | ||
package seedu.waddle.commons.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.waddle.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class VersionTest { | ||
|
||
@Test | ||
public void versionParsing_acceptableVersionString_parsedVersionCorrectly() { | ||
verifyVersionParsedCorrectly("V0.0.0ea", 0, 0, 0, true); | ||
verifyVersionParsedCorrectly("V3.10.2", 3, 10, 2, false); | ||
verifyVersionParsedCorrectly("V100.100.100ea", 100, 100, 100, true); | ||
} | ||
|
||
@Test | ||
public void versionParsing_wrongVersionString_throwIllegalArgumentException() { | ||
assertThrows(IllegalArgumentException.class, () -> Version.fromString("This is not a version string")); | ||
} | ||
|
||
@Test | ||
public void versionConstructor_correctParameter_valueAsExpected() { | ||
Version version = new Version(19, 10, 20, true); | ||
|
||
assertEquals(19, version.getMajor()); | ||
assertEquals(10, version.getMinor()); | ||
assertEquals(20, version.getPatch()); | ||
assertEquals(true, version.isEarlyAccess()); | ||
} | ||
|
||
@Test | ||
public void versionToString_validVersion_correctStringRepresentation() { | ||
// boundary at 0 | ||
Version version = new Version(0, 0, 0, true); | ||
assertEquals("V0.0.0ea", version.toString()); | ||
|
||
// normal values | ||
version = new Version(4, 10, 5, false); | ||
assertEquals("V4.10.5", version.toString()); | ||
|
||
// big numbers | ||
version = new Version(100, 100, 100, true); | ||
assertEquals("V100.100.100ea", version.toString()); | ||
} | ||
|
||
@Test | ||
public void versionComparable_validVersion_compareToIsCorrect() { | ||
Version one; | ||
Version another; | ||
|
||
// Tests equality | ||
one = new Version(0, 0, 0, true); | ||
another = new Version(0, 0, 0, true); | ||
assertTrue(one.compareTo(another) == 0); | ||
|
||
one = new Version(11, 12, 13, false); | ||
another = new Version(11, 12, 13, false); | ||
assertTrue(one.compareTo(another) == 0); | ||
|
||
// Tests different patch | ||
one = new Version(0, 0, 5, false); | ||
another = new Version(0, 0, 0, false); | ||
assertTrue(one.compareTo(another) > 0); | ||
|
||
// Tests different minor | ||
one = new Version(0, 0, 0, false); | ||
another = new Version(0, 5, 0, false); | ||
assertTrue(one.compareTo(another) < 0); | ||
|
||
// Tests different major | ||
one = new Version(10, 0, 0, true); | ||
another = new Version(0, 0, 0, true); | ||
assertTrue(one.compareTo(another) > 0); | ||
|
||
// Tests high major vs low minor | ||
one = new Version(10, 0, 0, true); | ||
another = new Version(0, 1, 0, true); | ||
assertTrue(one.compareTo(another) > 0); | ||
|
||
// Tests high patch vs low minor | ||
one = new Version(0, 0, 10, false); | ||
another = new Version(0, 1, 0, false); | ||
assertTrue(one.compareTo(another) < 0); | ||
|
||
// Tests same major minor different patch | ||
one = new Version(2, 15, 0, false); | ||
another = new Version(2, 15, 5, false); | ||
assertTrue(one.compareTo(another) < 0); | ||
|
||
// Tests early access vs not early access on same version number | ||
one = new Version(2, 15, 0, true); | ||
another = new Version(2, 15, 0, false); | ||
assertTrue(one.compareTo(another) < 0); | ||
|
||
// Tests early access lower version vs not early access higher version compare by version number first | ||
one = new Version(2, 15, 0, true); | ||
another = new Version(2, 15, 5, false); | ||
assertTrue(one.compareTo(another) < 0); | ||
|
||
// Tests early access higher version vs not early access lower version compare by version number first | ||
one = new Version(2, 15, 0, false); | ||
another = new Version(2, 15, 5, true); | ||
assertTrue(one.compareTo(another) < 0); | ||
} | ||
|
||
@Test | ||
public void versionComparable_validVersion_hashCodeIsCorrect() { | ||
Version version = new Version(100, 100, 100, true); | ||
assertEquals(100100100, version.hashCode()); | ||
|
||
version = new Version(10, 10, 10, false); | ||
assertEquals(1010010010, version.hashCode()); | ||
} | ||
|
||
@Test | ||
public void versionComparable_validVersion_equalIsCorrect() { | ||
Version one; | ||
Version another; | ||
|
||
one = new Version(0, 0, 0, false); | ||
another = new Version(0, 0, 0, false); | ||
assertTrue(one.equals(another)); | ||
|
||
one = new Version(100, 191, 275, true); | ||
another = new Version(100, 191, 275, true); | ||
assertTrue(one.equals(another)); | ||
} | ||
|
||
private void verifyVersionParsedCorrectly(String versionString, | ||
int major, int minor, int patch, boolean isEarlyAccess) { | ||
assertEquals(new Version(major, minor, patch, isEarlyAccess), Version.fromString(versionString)); | ||
} | ||
} |
Oops, something went wrong.