Skip to content

Commit

Permalink
Merge pull request #66 from Treescrub/more-tests
Browse files Browse the repository at this point in the history
Add more unit tests
  • Loading branch information
Treescrub authored Jul 26, 2024
2 parents 4819a23 + e9d6dc5 commit 93da14d
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.treescrub</groupId>
<artifactId>spedran</artifactId>
<version>0.29.0</version>
<version>0.29.1</version>
<packaging>jar</packaging>

<name>Spedran</name>
Expand Down
106 changes: 106 additions & 0 deletions src/test/java/com/treescrub/spedran/data/GameAssetsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.treescrub.spedran.data;

import com.treescrub.spedran.JSONLoader;
import kong.unirest.json.JSONObject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class GameAssetsTest {
@Test
void getLogo() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/theme/68q122rp/logo?v=c717a0c", gameAssets.getLogo().getURI());
}

@Test
void getTinyCover() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e", gameAssets.getTinyCover().getURI());
}

@Test
void getSmallCover() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e", gameAssets.getSmallCover().getURI());
}

@Test
void getMediumCover() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e", gameAssets.getMediumCover().getURI());
}

@Test
void getLargeCover() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e", gameAssets.getLargeCover().getURI());
}

@Test
void getIcon() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/theme/68q122rp/favicon?v=ad6f2ef", gameAssets.getIcon().getURI());
}

@Test
void getFirstTrophy() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/theme/68q122rp/1st?v=0e9d8ee", gameAssets.getFirstTrophy().getURI());
}

@Test
void getSecondTrophy() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/theme/68q122rp/2nd?v=aa0f425", gameAssets.getSecondTrophy().getURI());
}

@Test
void getThirdTrophy() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertEquals("https://www.speedrun.com/static/theme/68q122rp/3rd?v=38513e4", gameAssets.getThirdTrophy().getURI());
}

@Test
void getFourthTrophy() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertTrue(gameAssets.getFourthTrophy().isEmpty());
}

@Test
void getBackground() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertTrue(gameAssets.getBackground().isPresent());
assertEquals("https://www.speedrun.com/static/theme/68q122rp/background?v=e461fae", gameAssets.getBackground().get().getURI());
}

@Test
void getForeground() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/gameassets");
GameAssets gameAssets = new GameAssets(json);

assertTrue(gameAssets.getForeground().isEmpty());
}
}
6 changes: 3 additions & 3 deletions src/test/java/com/treescrub/spedran/data/GameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void getBoostsReceived() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/game/game");
Game game = new Game(json);

assertEquals(10, game.getBoostsReceived());
assertEquals(11, game.getBoostsReceived());
}

@Test
Expand Down Expand Up @@ -145,8 +145,8 @@ void getModerators() {
Game game = new Game(json);

assertFalse(game.getModerators().isEmpty());
assertTrue(game.getModerators().containsKey("qjoq74l8"));
assertEquals(ModeratorType.MODERATOR, game.getModerators().get("qjoq74l8"));
assertTrue(game.getModerators().containsKey("98rm993j"));
assertEquals(ModeratorType.MODERATOR, game.getModerators().get("98rm993j"));
assertThrows(UnsupportedOperationException.class, () -> game.getModerators().clear());
}

Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/treescrub/spedran/data/GuestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.treescrub.spedran.data;

import com.treescrub.spedran.JSONLoader;
import kong.unirest.json.JSONObject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class GuestTest {

@Test
void getName() {
JSONObject json = JSONLoader.getJsonTestFile("guest");
Guest guest = new Guest(json);

assertEquals("test", guest.getName());
}

@Test
void testEquals() {
JSONObject json = JSONLoader.getJsonTestFile("guest");
Guest guest = new Guest(json);
Guest sameGuest = new Guest(json);

assertEquals(guest, sameGuest);
}

@Test
void testHashCode() {
JSONObject json = JSONLoader.getJsonTestFile("guest");
Guest guest = new Guest(json);
Guest sameGuest = new Guest(json);

assertEquals(guest.hashCode(), sameGuest.hashCode());
}
}
49 changes: 49 additions & 0 deletions src/test/java/com/treescrub/spedran/data/NotificationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.treescrub.spedran.data;

import com.treescrub.spedran.JSONLoader;
import kong.unirest.json.JSONObject;
import org.junit.jupiter.api.Test;

import java.time.Instant;

import static org.junit.jupiter.api.Assertions.*;

class NotificationTest {

@Test
void getCreationTime() {
JSONObject json = JSONLoader.getJsonTestFile("notifications/run");
Notification notification = new Notification(json);

assertEquals(Instant.parse("2024-07-24T15:32:28Z"), notification.getCreationTime());
}

@Test
void getStatus() {
JSONObject readJson = JSONLoader.getJsonTestFile("notifications/run");
JSONObject unreadJson = JSONLoader.getJsonTestFile("notifications/post");
Notification readNotification = new Notification(readJson);
Notification unreadNotification = new Notification(unreadJson);

assertEquals(NotificationStatus.READ, readNotification.getStatus());
assertEquals(NotificationStatus.UNREAD, unreadNotification.getStatus());
}

@Test
void getNotificationText() {
JSONObject json = JSONLoader.getJsonTestFile("notifications/run");
Notification notification = new Notification(json);

assertEquals("A new run is waiting for verification in Left 4 Dead 2 Dead Center Solo - Any Difficulty", notification.getNotificationText());
}

@Test
void getItemLink() {
JSONObject json = JSONLoader.getJsonTestFile("notifications/post");
Notification notification = new Notification(json);

assertTrue(notification.getItemLink().getRelation().isPresent());
assertEquals("post", notification.getItemLink().getRelation().get());
assertEquals("https://www.speedrun.com/l4d2_cc/runs/y8p9n7wz", notification.getItemLink().getURI());
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/treescrub/spedran/data/UserAssetsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.treescrub.spedran.data;

import com.treescrub.spedran.JSONLoader;
import kong.unirest.json.JSONObject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class UserAssetsTest {

@Test
void getIcon() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/user/userassets");
UserAssets userAssets = new UserAssets(json);

assertTrue(userAssets.getIcon().isEmpty());
}

@Test
void getSupporterIcon() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/user/userassets");
UserAssets userAssets = new UserAssets(json);

assertTrue(userAssets.getSupporterIcon().isEmpty());
}

@Test
void getAvatar() {
JSONObject json = JSONLoader.getJsonTestFile("l4d/user/userassets");
UserAssets userAssets = new UserAssets(json);

assertTrue(userAssets.getAvatar().isPresent());
assertEquals("https://www.speedrun.com/static/user/zx721w08/image?v=0705d37", userAssets.getAvatar().get().getURI());
}
}
13 changes: 13 additions & 0 deletions src/test/resources/guest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test",
"links": [
{
"rel": "self",
"uri": "https://www.speedrun.com/api/v1/guests/test"
},
{
"rel": "runs",
"uri": "https://www.speedrun.com/api/v1/runs?guest=test"
}
]
}
30 changes: 15 additions & 15 deletions src/test/resources/l4d/game/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"japanese": null,
"twitch": "Left 4 Dead 2"
},
"boostReceived": 10,
"boostReceived": 11,
"boostDistinctDonors": 4,
"abbreviation": "l4d2",
"weblink": "https://www.speedrun.com/l4d2",
Expand Down Expand Up @@ -49,46 +49,46 @@
"moderators": {
"68wk1gl8": "super-moderator",
"v8l434rj": "super-moderator",
"98rm993j": "super-moderator",
"qjoq74l8": "moderator",
"zxzevrrx": "moderator",
"zx721w08": "moderator",
"98rm993j": "moderator",
"j4r0d0w8": "super-moderator",
"xkm1206j": "super-moderator"
"x3m4pd78": "super-moderator",
"xkm73z7j": "super-moderator"
},
"created": null,
"assets": {
"logo": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/logo?v=c717a0c"
"uri": "https://www.speedrun.com/static/theme/68q122rp/logo?v=c717a0c"
},
"cover-tiny": {
"uri": "https://www.speedrun.com/gameasset/9dowpe1p/cover?v=7b4712e"
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-small": {
"uri": "https://www.speedrun.com/gameasset/9dowpe1p/cover?v=7b4712e"
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-medium": {
"uri": "https://www.speedrun.com/gameasset/9dowpe1p/cover?v=7b4712e"
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-large": {
"uri": "https://www.speedrun.com/gameasset/9dowpe1p/cover?v=7b4712e"
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"icon": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/favicon?v=ad6f2ef"
"uri": "https://www.speedrun.com/static/theme/68q122rp/favicon?v=ad6f2ef"
},
"trophy-1st": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/1st?v=0e9d8ee"
"uri": "https://www.speedrun.com/static/theme/68q122rp/1st?v=0e9d8ee"
},
"trophy-2nd": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/2nd?v=aa0f425"
"uri": "https://www.speedrun.com/static/theme/68q122rp/2nd?v=aa0f425"
},
"trophy-3rd": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/3rd?v=38513e4"
"uri": "https://www.speedrun.com/static/theme/68q122rp/3rd?v=38513e4"
},
"trophy-4th": {
"uri": null
},
"background": {
"uri": "https://www.speedrun.com/themeasset/68q122rp/background?v=e461fae"
"uri": "https://www.speedrun.com/static/theme/68q122rp/background?v=e461fae"
},
"foreground": {
"uri": null
Expand Down
38 changes: 38 additions & 0 deletions src/test/resources/l4d/game/gameassets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"logo": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/logo?v=c717a0c"
},
"cover-tiny": {
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-small": {
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-medium": {
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"cover-large": {
"uri": "https://www.speedrun.com/static/game/9dowpe1p/cover?v=7b4712e"
},
"icon": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/favicon?v=ad6f2ef"
},
"trophy-1st": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/1st?v=0e9d8ee"
},
"trophy-2nd": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/2nd?v=aa0f425"
},
"trophy-3rd": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/3rd?v=38513e4"
},
"trophy-4th": {
"uri": null
},
"background": {
"uri": "https://www.speedrun.com/static/theme/68q122rp/background?v=e461fae"
},
"foreground": {
"uri": null
}
}
9 changes: 9 additions & 0 deletions src/test/resources/l4d/user/userassets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"icon": {
"uri":null
},
"supporterIcon":null,
"image": {
"uri":"https://www.speedrun.com/static/user/zx721w08/image?v=0705d37"
}
}
Loading

0 comments on commit 93da14d

Please sign in to comment.