Skip to content

Commit

Permalink
Improve Code Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Nov 24, 2024
1 parent 5a98969 commit d203866
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static void main(String[] args) { // NOSONAR : args used as file option,
configFile = args[0];
}
Config config = Config.build(configFile);
MpgClient mpgClient = MpgClient.build(config);
MpgStatsClient mpgStatsClient = MpgStatsClient.build(config);
InjuredSuspendedWrapperClient outPlayersClient = InjuredSuspendedWrapperClient.build(config);
MpgClient mpgClient = MpgClient.build(config);
ApiClients apiClients = ApiClients.build(mpgClient, mpgStatsClient, outPlayersClient);
process(apiClients, config);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static void configMain(Config config, Properties properties, File fileCo
config.password = parseString(properties, "password");
if (StringUtils.isBlank(config.login) || StringUtils.isBlank(config.password)) {
throw new UnsupportedOperationException(
String.format("Login and/or password can't be retrieved from file '%s' of environement variables", fileConfig.getName()));
String.format("Login and/or password cannot be retrieved from file '%s' or environement variables", fileConfig.getName()));
}
config.teampUpdate = parseBoolean(properties, "team.update", config.teampUpdate);
config.efficiencyRecentFocus = parseBoolean(properties, "efficiency.recent.focus", config.efficiencyRecentFocus);
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ public void testRealWithBadCredentials() {
}
}

@Test
public void testLeaguesNotSupported() {
stubFor(post("/user/sign-in")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json")));
stubFor(get("/dashboard/leagues")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.unsupported.json")));

Config config = spy(getConfig());
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains("Sorry, Champions League is currently not supported"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Sorry, Ligue Super is currently not supported"));
}

@Test
public void testLeagueWaitMercatoEnd() {
stubFor(post("/user/sign-in")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json")));
stubFor(get("/dashboard/leagues")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.wait-mercato-end.json")));

Config config = spy(getConfig());
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains("Some users should select players to kept before Mercato can start, come back soon !"));
}

@Test
public void testFollowed() {
stubFor(post("/user/sign-in")
Expand Down Expand Up @@ -515,6 +542,22 @@ public void testProcessFromEmptyCoach() throws IOException {
Assert.assertFalse(getLogOut(), getLogOut().contains("Players to sell (initial cash"));
}

@Test
public void testNoConfig() {
try {
Main.main(null);
Assert.fail("No Credentials");
} catch (UnsupportedOperationException e) {
Assert.assertTrue(e.getMessage().contains("Login and/or password cannot be retrieved"));
}
try {
Main.main(new String[] {});
Assert.fail("No Credentials");
} catch (UnsupportedOperationException e) {
Assert.assertTrue(e.getMessage().contains("Login and/or password cannot be retrieved"));
}
}

private void executeMainProcess(Config config) {
executeMainProcess(null, null, null, config);
}
Expand Down
45 changes: 45 additions & 0 deletions src/test/resources/__files/mpg.dashboard.unsupported.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"leaguesDivisionsItems": [
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 4,
"season": 1,
"mode": 1,
"defaultDivisionId": "mpg_division_RJH6ZHRM_1_1",
"createdAt": "2023-08-01T10:56:48.082Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 6,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/ef7dd623-5fe8-4e1a-a924-932777afe21f.jpg",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
},
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 4,
"season": 3,
"mode": 1,
"defaultDivisionId": "mpg_division_PJHY1S98_3_1",
"createdAt": "2022-08-01T17:47:04.196Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 7,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/befdd6ab-2a86-46e8-915a-561a6fc73b3d.png",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
}
],
"defaultOrder": false
}
25 changes: 25 additions & 0 deletions src/test/resources/__files/mpg.dashboard.wait-mercato-end.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"leaguesDivisionsItems": [
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 6,
"season": 1,
"mode": 1,
"defaultDivisionId": "mpg_division_RJH6ZHRM_1_1",
"createdAt": "2023-08-01T10:56:48.082Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 1,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/ef7dd623-5fe8-4e1a-a924-932777afe21f.jpg",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
}
],
"defaultOrder": false
}

0 comments on commit d203866

Please sign in to comment.