From 8069d9b54a34b4584c9f8a03d49a8fbbe36bfa57 Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Thu, 12 Aug 2021 20:55:42 +0200 Subject: [PATCH 1/4] Fix efficiency for first day of season --- src/main/java/org/blondin/mpg/Main.java | 3 ++- .../java/org/blondin/mpg/stats/model/Championship.java | 4 +++- src/main/java/org/blondin/mpg/stats/model/CurrentDay.java | 7 ------- src/main/java/org/blondin/mpg/stats/model/Stats.java | 6 +++--- src/test/java/org/blondin/mpg/MainTest.java | 1 + 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/blondin/mpg/Main.java b/src/main/java/org/blondin/mpg/Main.java index 12e9db6..f5f562f 100644 --- a/src/main/java/org/blondin/mpg/Main.java +++ b/src/main/java/org/blondin/mpg/Main.java @@ -450,8 +450,9 @@ private static List calculateEfficiency(List players, MpgStatsCl private static int getCurrentDay(MpgStatsClient stats, ChampionshipStatsType championship) { int daysPeriod = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getDay(); + int lastDayReached = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getLastDayReached(); // If league not started, we take the number of day of season, because average will be on this period - if (daysPeriod == 0 || stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getPlayed() == 0) { + if (daysPeriod == 0 || (daysPeriod == 1 && lastDayReached == 0)) { // The previous season statistics could be null, in this case current annual max day is used daysPeriod = stats.getStats(championship).getInfos().getLastStats() == null ? stats.getStats(championship).getInfos().getAnnualStats().getMaxDay() diff --git a/src/main/java/org/blondin/mpg/stats/model/Championship.java b/src/main/java/org/blondin/mpg/stats/model/Championship.java index f55d85d..1e6590e 100644 --- a/src/main/java/org/blondin/mpg/stats/model/Championship.java +++ b/src/main/java/org/blondin/mpg/stats/model/Championship.java @@ -35,7 +35,9 @@ public List getPlayers() { // If last season statistics does not exist (Dominos L2 in 2019 use case, first one in MPG), current annual max day is used final int previousMaxSeasonDay = getInfos().getLastStats() == null ? getInfos().getAnnualStats().getMaxDay() : getInfos().getLastStats().getMaxDay(); - final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDay(); + final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDay() <= 1 + && getInfos().getAnnualStats().getCurrentDay().getLastDayReached() == 0 ? 0 + : getInfos().getAnnualStats().getCurrentDay().getDay(); players.forEach(p -> p.getStats().setCurrentSeasonDay(currentSeasonDay)); players.forEach(p -> p.getStats().setPreviousMaxSeasonDay(previousMaxSeasonDay)); maxDaySetOnPlayer = true; diff --git a/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java b/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java index 700795f..84601a9 100644 --- a/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java +++ b/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java @@ -12,9 +12,6 @@ public class CurrentDay { @JsonProperty("lD") private int lastDayReached; - @JsonProperty("p") - private int played; - public int getDay() { return day; } @@ -23,8 +20,4 @@ public int getLastDayReached() { return lastDayReached; } - public int getPlayed() { - return played; - } - } diff --git a/src/main/java/org/blondin/mpg/stats/model/Stats.java b/src/main/java/org/blondin/mpg/stats/model/Stats.java index ea32da8..4383dba 100644 --- a/src/main/java/org/blondin/mpg/stats/model/Stats.java +++ b/src/main/java/org/blondin/mpg/stats/model/Stats.java @@ -41,7 +41,7 @@ public class Stats { * @return number of goals */ public int getGoals(int days) { - if (currentSeasonDay <= 1 && days <= 0) { + if (currentSeasonDay <= 0 && days <= 0) { return oldGoals; } if (days <= 0) { @@ -67,7 +67,7 @@ public int getGoals(int days) { * @return note */ public double getAverage(int days) { - if (currentSeasonDay <= 1 && days <= 0) { + if (currentSeasonDay <= 0 && days <= 0) { return oldAverage; } if (days <= 0) { @@ -98,7 +98,7 @@ public double getAverage(int days) { * @return number of matchs */ public int getMatchs(int days) { - if (currentSeasonDay <= 1 && days <= 0) { + if (currentSeasonDay <= 0 && days <= 0) { return oldMatchs; } if (days <= 0) { diff --git a/src/test/java/org/blondin/mpg/MainTest.java b/src/test/java/org/blondin/mpg/MainTest.java index d291796..bbf75d9 100644 --- a/src/test/java/org/blondin/mpg/MainTest.java +++ b/src/test/java/org/blondin/mpg/MainTest.java @@ -120,6 +120,7 @@ public void testCaptainAdd() throws Exception { Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); + doReturn(true).when(config).isEfficiencyRecentFocus(); executeMainProcess(config); Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ...")); Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic")); From 73c003ba233de05d805bc6bc754d82091a265145 Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Fri, 13 Aug 2021 09:53:02 +0200 Subject: [PATCH 2/4] Fix unit tests --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- src/test/java/org/blondin/mpg/MainTest.java | 17 +++++++++---- .../org/blondin/mpg/root/MpgClientTest.java | 2 +- ...MLAX7HMK.20210812.withCaptain-Request.json | 22 ++++++++--------- ...g.coach.MLAX7HMK.20210812.withCaptain.json | 2 +- ...AX7HMK.20210812.withNoCaptain-Request.json | 22 ++++++++--------- ...812.withNotOnMainPitchCaptain-Request.json | 24 +++++++++---------- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 28f7255..fa893d6 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -15,7 +15,7 @@ A clear and concise description of what the bug is, with a copy/paste of Java ex Depending your championship, join data files set in attachment. -1. The MPG Mobile App JSon *Response* of these *Request* on https://api.mpg.football (use the browser network monitor - F12, see wiki [Get MPG data for opening a bug](https://github.com/axel3rd/mpg-coach-bot/wiki/Get-MPG-data-for-opening-a-bug) for more details): +1. The MPG Mobile App JSon *Response* of these *Request* on https://api.mpg.football (see wiki [Get MPG data for opening a bug](https://github.com/axel3rd/mpg-coach-bot/wiki/Get-MPG-data-for-opening-a-bug) for authentication and details): | Feature | URL | Reason | | --- | --- | --- | diff --git a/src/test/java/org/blondin/mpg/MainTest.java b/src/test/java/org/blondin/mpg/MainTest.java index bbf75d9..960130f 100644 --- a/src/test/java/org/blondin/mpg/MainTest.java +++ b/src/test/java/org/blondin/mpg/MainTest.java @@ -79,8 +79,11 @@ public void testCaptainNotOnMainPitch() throws Exception { doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); executeMainProcess(config); - Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic")); - Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Blas Ludovic)")); + // Day 1 => efficiency with "Recent Focus" or global is the same + Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |")); + Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |")); + Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan")); + Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Bamba Jonathan)")); } @Test @@ -100,8 +103,11 @@ public void testCaptainAlreadySelected() throws Exception { doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); executeMainProcess(config); + // Day 1 => efficiency with "Recent Focus" or global is the same + Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |")); + Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |")); Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ...")); - Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan")); + Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Botman Sven")); } @Test @@ -122,8 +128,11 @@ public void testCaptainAdd() throws Exception { doReturn(false).when(config).isTacticalSubstitutes(); doReturn(true).when(config).isEfficiencyRecentFocus(); executeMainProcess(config); + // Day 1 => efficiency with "Recent Focus" or global is the same + Assert.assertTrue(getLogOut(), getLogOut().contains("| G | Rajkovic Predrag | 6.00 |")); + Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Laborde Gaëtan | 15.40 |")); Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ...")); - Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Blas Ludovic")); + Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan")); } @Test diff --git a/src/test/java/org/blondin/mpg/root/MpgClientTest.java b/src/test/java/org/blondin/mpg/root/MpgClientTest.java index 59b1ccf..d461ee6 100644 --- a/src/test/java/org/blondin/mpg/root/MpgClientTest.java +++ b/src/test/java/org/blondin/mpg/root/MpgClientTest.java @@ -156,7 +156,7 @@ public void testMockCoachNotEmpty() throws Exception { Assert.assertNotNull(coach); Assert.assertTrue(coach.getComposition() > 0); Assert.assertEquals("mpg_match_team_formation_MLAX7HMK_3_1_1_5_6", coach.getIdMatch()); - Assert.assertEquals("mpg_championship_player_195883", coach.getCaptain()); + Assert.assertEquals("mpg_championship_player_220237", coach.getCaptain()); } @Test diff --git a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json index eaff67a..a51ca9f 100644 --- a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json +++ b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json @@ -2,17 +2,17 @@ "composition": "343", "playersOnPitch": { "1": "mpg_championship_player_104407", - "2": "mpg_championship_player_155335", - "3": "mpg_championship_player_38580", - "4": "mpg_championship_player_52573", - "5": "mpg_championship_player_213940", - "6": "mpg_championship_player_195883", - "7": "mpg_championship_player_441240", - "8": "mpg_championship_player_159967", + "2": "mpg_championship_player_220237", + "3": "mpg_championship_player_52573", + "4": "mpg_championship_player_38580", + "5": "mpg_championship_player_195883", + "6": "mpg_championship_player_441240", + "7": "mpg_championship_player_159967", + "8": "mpg_championship_player_213940", "9": "mpg_championship_player_167443", - "10": "mpg_championship_player_168539", - "11": "mpg_championship_player_193454", - "12": "mpg_championship_player_220237", + "10": "mpg_championship_player_193454", + "11": "mpg_championship_player_168539", + "12": "mpg_championship_player_155335", "13": "mpg_championship_player_437753", "14": "mpg_championship_player_61170", "15": "mpg_championship_player_240146", @@ -22,5 +22,5 @@ }, "tacticalSubs": [ ], - "captain": "mpg_championship_player_195883" + "captain": "mpg_championship_player_220237" } diff --git a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain.json b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain.json index 308c17d..cda8357 100644 --- a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain.json +++ b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withCaptain.json @@ -56,7 +56,7 @@ "starterId": "mpg_championship_player_168539" } ], - "captain": "mpg_championship_player_195883" + "captain": "mpg_championship_player_220237" }, "nextGameWeek": { "gameWeekNumber": 2, diff --git a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json index 98d91a4..a97e045 100644 --- a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json +++ b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json @@ -2,17 +2,17 @@ "composition": "343", "playersOnPitch": { "1": "mpg_championship_player_104407", - "2": "mpg_championship_player_155335", - "3": "mpg_championship_player_38580", - "4": "mpg_championship_player_52573", - "5": "mpg_championship_player_213940", - "6": "mpg_championship_player_195883", - "7": "mpg_championship_player_441240", - "8": "mpg_championship_player_159967", + "2": "mpg_championship_player_220237", + "3": "mpg_championship_player_52573", + "4": "mpg_championship_player_38580", + "5": "mpg_championship_player_195883", + "6": "mpg_championship_player_441240", + "7": "mpg_championship_player_159967", + "8": "mpg_championship_player_213940", "9": "mpg_championship_player_167443", - "10": "mpg_championship_player_168539", - "11": "mpg_championship_player_193454", - "12": "mpg_championship_player_220237", + "10": "mpg_championship_player_193454", + "11": "mpg_championship_player_168539", + "12": "mpg_championship_player_155335", "13": "mpg_championship_player_437753", "14": "mpg_championship_player_61170", "15": "mpg_championship_player_240146", @@ -22,5 +22,5 @@ }, "tacticalSubs": [ ], - "captain": "mpg_championship_player_213940" + "captain": "mpg_championship_player_195883" } diff --git a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain-Request.json b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain-Request.json index af5a138..f3efe9f 100644 --- a/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain-Request.json +++ b/src/test/resources/__files/mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain-Request.json @@ -2,17 +2,17 @@ "composition": "343", "playersOnPitch": { "1": "mpg_championship_player_104407", - "2": "mpg_championship_player_155335", - "3": "mpg_championship_player_38580", - "4": "mpg_championship_player_52573", - "5": "mpg_championship_player_213940", - "6": "mpg_championship_player_195883", - "7": "mpg_championship_player_441240", - "8": "mpg_championship_player_159967", + "2": "mpg_championship_player_220237", + "3": "mpg_championship_player_52573", + "4": "mpg_championship_player_38580", + "5": "mpg_championship_player_195883", + "6": "mpg_championship_player_441240", + "7": "mpg_championship_player_159967", + "8": "mpg_championship_player_213940", "9": "mpg_championship_player_167443", - "10": "mpg_championship_player_168539", - "11": "mpg_championship_player_193454", - "12": "mpg_championship_player_220237", + "10": "mpg_championship_player_193454", + "11": "mpg_championship_player_168539", + "12": "mpg_championship_player_155335", "13": "mpg_championship_player_437753", "14": "mpg_championship_player_61170", "15": "mpg_championship_player_240146", @@ -24,7 +24,7 @@ ], "selectedBonus": { "name": "boostOnePlayer", - "playerId": "mpg_championship_player_213940" + "playerId": "mpg_championship_player_195883" }, - "captain": "mpg_championship_player_213940" + "captain": "mpg_championship_player_195883" } From 9be8a814db8bf955c858a14e1aa33e2e85fb4cb1 Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Fri, 13 Aug 2021 10:10:30 +0200 Subject: [PATCH 3/4] Fix method usage --- src/main/java/org/blondin/mpg/Main.java | 7 +++---- .../blondin/mpg/stats/model/Championship.java | 4 +--- .../org/blondin/mpg/stats/model/CurrentDay.java | 8 ++++---- .../blondin/mpg/stats/MpgStatsClientTest.java | 16 +++++++++++++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/blondin/mpg/Main.java b/src/main/java/org/blondin/mpg/Main.java index f5f562f..7591966 100644 --- a/src/main/java/org/blondin/mpg/Main.java +++ b/src/main/java/org/blondin/mpg/Main.java @@ -202,7 +202,7 @@ static void processGames(League league, ApiClients apiClients, Config config) { LOG.info("\nTransactions proposal ..."); CurrentDay cd = apiClients.getStats().getStats(ChampionshipTypeWrapper.toStats(league.getChampionship())).getInfos() .getAnnualStats().getCurrentDay(); - if (cd.getLastDayReached() < cd.getDay()) { + if (!cd.isStatsDayReached()) { LOG.info("\nWARNING: Last day stats have not fully reached! Please retry tomorrow"); } List playersAvailable = apiClients.getMpg().getAvailablePlayers(league.getDivisionId()).getList(); @@ -449,10 +449,9 @@ private static List calculateEfficiency(List players, MpgStatsCl } private static int getCurrentDay(MpgStatsClient stats, ChampionshipStatsType championship) { - int daysPeriod = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getDay(); - int lastDayReached = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getLastDayReached(); + int daysPeriod = stats.getStats(championship).getInfos().getAnnualStats().getCurrentDay().getDayReached(); // If league not started, we take the number of day of season, because average will be on this period - if (daysPeriod == 0 || (daysPeriod == 1 && lastDayReached == 0)) { + if (daysPeriod == 0) { // The previous season statistics could be null, in this case current annual max day is used daysPeriod = stats.getStats(championship).getInfos().getLastStats() == null ? stats.getStats(championship).getInfos().getAnnualStats().getMaxDay() diff --git a/src/main/java/org/blondin/mpg/stats/model/Championship.java b/src/main/java/org/blondin/mpg/stats/model/Championship.java index 1e6590e..2d0154b 100644 --- a/src/main/java/org/blondin/mpg/stats/model/Championship.java +++ b/src/main/java/org/blondin/mpg/stats/model/Championship.java @@ -35,9 +35,7 @@ public List getPlayers() { // If last season statistics does not exist (Dominos L2 in 2019 use case, first one in MPG), current annual max day is used final int previousMaxSeasonDay = getInfos().getLastStats() == null ? getInfos().getAnnualStats().getMaxDay() : getInfos().getLastStats().getMaxDay(); - final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDay() <= 1 - && getInfos().getAnnualStats().getCurrentDay().getLastDayReached() == 0 ? 0 - : getInfos().getAnnualStats().getCurrentDay().getDay(); + final int currentSeasonDay = getInfos().getAnnualStats().getCurrentDay().getDayReached(); players.forEach(p -> p.getStats().setCurrentSeasonDay(currentSeasonDay)); players.forEach(p -> p.getStats().setPreviousMaxSeasonDay(previousMaxSeasonDay)); maxDaySetOnPlayer = true; diff --git a/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java b/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java index 84601a9..4059892 100644 --- a/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java +++ b/src/main/java/org/blondin/mpg/stats/model/CurrentDay.java @@ -12,12 +12,12 @@ public class CurrentDay { @JsonProperty("lD") private int lastDayReached; - public int getDay() { - return day; + public int getDayReached() { + return lastDayReached; } - public int getLastDayReached() { - return lastDayReached; + public boolean isStatsDayReached() { + return day == lastDayReached; } } diff --git a/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java b/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java index b176e3c..70445c3 100644 --- a/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java +++ b/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java @@ -25,6 +25,8 @@ public void testPlayersWithSameName() { .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-2.20210804.json"))); MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port()); Assert.assertEquals(25, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getPlayer("Ba Pape Ibnou").getPrice()); + Assert.assertEquals(1, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getInfos().getAnnualStats().getCurrentDay().getDayReached()); + Assert.assertFalse(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_2).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); } @Test @@ -33,7 +35,8 @@ public void testEfficiencyRecentFocus() { stubFor(get("/leagues/Ligue-1") .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.ligue-1.20190406.json"))); MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port()); - + Assert.assertEquals(30, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().getDayReached()); + Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); testEfficiencyRecentFocusNeymar(mpgStatsClient); testEfficiencyRecentFocusMBappe(mpgStatsClient); testEfficiencyRecentFocusTrapp(mpgStatsClient); @@ -93,6 +96,17 @@ public void testMockAllLeagues() { MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port()); + Assert.assertEquals(8, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().getDayReached()); + Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); + + Assert.assertEquals(8, + mpgStatsClient.getStats(ChampionshipStatsType.PREMIER_LEAGUE).getInfos().getAnnualStats().getCurrentDay().getDayReached()); + Assert.assertTrue( + mpgStatsClient.getStats(ChampionshipStatsType.PREMIER_LEAGUE).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); + + Assert.assertEquals(8, mpgStatsClient.getStats(ChampionshipStatsType.LIGA).getInfos().getAnnualStats().getCurrentDay().getDayReached()); + Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGA).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); + for (ChampionshipStatsType type : Arrays.asList(ChampionshipStatsType.LIGUE_1, ChampionshipStatsType.PREMIER_LEAGUE, ChampionshipStatsType.LIGA)) { Championship championship = mpgStatsClient.getStats(type); From c718d10b0cfaa04dbb4f0618a1bd15da74488ce9 Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Fri, 13 Aug 2021 10:15:39 +0200 Subject: [PATCH 4/4] Fix old unit test data --- .../blondin/mpg/stats/MpgStatsClientTest.java | 16 ++++++++-------- src/test/resources/__files/README.md | 18 +++++++++++------- ...1017.json => mlnstats.builds.20181017.json} | 0 ...0406.json => mlnstats.builds.20190406.json} | 0 ...181017.json => mlnstats.liga.20181017.json} | 0 ...017.json => mlnstats.ligue-1.20181017.json} | 0 ...406.json => mlnstats.ligue-1.20190406.json} | 0 ...n => mlnstats.premier-league.20181017.json} | 0 8 files changed, 19 insertions(+), 15 deletions(-) rename src/test/resources/__files/{mpgstats.leagues.20181017.json => mlnstats.builds.20181017.json} (100%) rename src/test/resources/__files/{mpgstats.leagues.20190406.json => mlnstats.builds.20190406.json} (100%) rename src/test/resources/__files/{mpgstats.liga.20181017.json => mlnstats.liga.20181017.json} (100%) rename src/test/resources/__files/{mpgstats.ligue-1.20181017.json => mlnstats.ligue-1.20181017.json} (100%) rename src/test/resources/__files/{mpgstats.ligue-1.20190406.json => mlnstats.ligue-1.20190406.json} (100%) rename src/test/resources/__files/{mpgstats.premier-league.20181017.json => mlnstats.premier-league.20181017.json} (100%) diff --git a/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java b/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java index 70445c3..129d941 100644 --- a/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java +++ b/src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java @@ -31,9 +31,9 @@ public void testPlayersWithSameName() { @Test public void testEfficiencyRecentFocus() { - stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.leagues.20190406.json"))); + stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20190406.json"))); stubFor(get("/leagues/Ligue-1") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.ligue-1.20190406.json"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20190406.json"))); MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port()); Assert.assertEquals(30, mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().getDayReached()); Assert.assertTrue(mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getInfos().getAnnualStats().getCurrentDay().isStatsDayReached()); @@ -86,13 +86,13 @@ private void testEfficiencyRecentFocusTrapp(MpgStatsClient mpgStatsClient) { @Test public void testMockAllLeagues() { - stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.leagues.20181017.json"))); + stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20181017.json"))); stubFor(get("/leagues/Ligue-1") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.ligue-1.20181017.json"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20181017.json"))); stubFor(get("/leagues/Premier-League") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.premier-league.20181017.json"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20181017.json"))); stubFor(get("/leagues/Liga") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpgstats.liga.20181017.json"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.liga.20181017.json"))); MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port()); @@ -117,7 +117,7 @@ public void testMockAllLeagues() { @Test public void testLocalMapping() throws Exception { for (String subFile : Arrays.asList("ligue-1", "premier-league", "liga")) { - Championship championship = new ObjectMapper().readValue(new File("src/test/resources/__files", "mpgstats." + subFile + ".20181017.json"), + Championship championship = new ObjectMapper().readValue(new File("src/test/resources/__files", "mlnstats." + subFile + ".20181017.json"), Championship.class); subChampionshipTest(championship, subFile); } @@ -125,7 +125,7 @@ public void testLocalMapping() throws Exception { @Test public void testLocalMappingRefresh() throws Exception { - LeaguesRefresh refresh = new ObjectMapper().readValue(new File("src/test/resources/__files", "mpgstats.leagues.20181017.json"), + LeaguesRefresh refresh = new ObjectMapper().readValue(new File("src/test/resources/__files", "mlnstats.builds.20181017.json"), LeaguesRefresh.class); Assert.assertNotNull(refresh); Assert.assertNotNull(refresh.getDate(1)); diff --git a/src/test/resources/__files/README.md b/src/test/resources/__files/README.md index 787b15f..529ed0e 100644 --- a/src/test/resources/__files/README.md +++ b/src/test/resources/__files/README.md @@ -32,12 +32,6 @@ The `XXX` should be replaced by a use case scenario (like date, some league, dat | `mlnstats.ligue-2.XXX.json` | https://api.mlnstats.com/leagues/Ligue-2 | MpgStats for **Ligue 2 (France)** | | `mlnstats.premier-league.XXX.json` | https://api.mlnstats.com/leagues/Premier-League | MpgStats for **Premiere League (England)** | | `mlnstats.serie-a.XXX.json` | https://api.mlnstats.com/leagues/Serie-A | MpgStats for **Seria A (Italia)** | -| `mpgstats.leagues.XXX.json` | https://www.mpgstats.fr/json/leagues.json | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | -| `mpgstats.liga.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Liga | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | -| `mpgstats.ligue-1.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-1 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | -| `mpgstats.ligue-2.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-2 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | -| `mpgstats.premier-league.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Premier-League | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | -| `mpgstats.serie-a.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Serie-A | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | ### Players Injury / Suspended @@ -63,4 +57,14 @@ The `XXX` should be replaced by a use case scenario (like date, some league, dat | `mpg.dashboard.XXX.json` | https://api.monpetitgazon.com/user/dashboard | MPG **dashboard** | | `mpg.mercato.XXX.json` | https://api.monpetitgazon.com/league/[leagueId]/mercato | MPG league **mercato** | | `mpg.transfer.buy.XXX.json` | https://api.monpetitgazon.com/league/[leagueId]/transfer/buy | MPG league **transfer** | -| `mpg.user-signIn.XXX.json` | https://api.monpetitgazon.com/user/signIn | **Login** | \ No newline at end of file +| `mpg.user-signIn.XXX.json` | https://api.monpetitgazon.com/user/signIn | **Login** | + +### Players statistics (deprecated since 15 December 2019) + +| **File** | **URL** | **Description** | +| `mpgstats.leagues.XXX.json` | https://www.mpgstats.fr/json/leagues.json | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | +| `mpgstats.liga.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Liga | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | +| `mpgstats.ligue-1.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-1 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | +| `mpgstats.ligue-2.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Ligue-2 | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | +| `mpgstats.premier-league.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Premier-League | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | +| `mpgstats.serie-a.XXX.json` | https://www.mpgstats.fr/json/customteam.json/Serie-A | Used prior end of 2019. See [#134](https://github.com/axel3rd/mpg-coach-bot/issues/134) | diff --git a/src/test/resources/__files/mpgstats.leagues.20181017.json b/src/test/resources/__files/mlnstats.builds.20181017.json similarity index 100% rename from src/test/resources/__files/mpgstats.leagues.20181017.json rename to src/test/resources/__files/mlnstats.builds.20181017.json diff --git a/src/test/resources/__files/mpgstats.leagues.20190406.json b/src/test/resources/__files/mlnstats.builds.20190406.json similarity index 100% rename from src/test/resources/__files/mpgstats.leagues.20190406.json rename to src/test/resources/__files/mlnstats.builds.20190406.json diff --git a/src/test/resources/__files/mpgstats.liga.20181017.json b/src/test/resources/__files/mlnstats.liga.20181017.json similarity index 100% rename from src/test/resources/__files/mpgstats.liga.20181017.json rename to src/test/resources/__files/mlnstats.liga.20181017.json diff --git a/src/test/resources/__files/mpgstats.ligue-1.20181017.json b/src/test/resources/__files/mlnstats.ligue-1.20181017.json similarity index 100% rename from src/test/resources/__files/mpgstats.ligue-1.20181017.json rename to src/test/resources/__files/mlnstats.ligue-1.20181017.json diff --git a/src/test/resources/__files/mpgstats.ligue-1.20190406.json b/src/test/resources/__files/mlnstats.ligue-1.20190406.json similarity index 100% rename from src/test/resources/__files/mpgstats.ligue-1.20190406.json rename to src/test/resources/__files/mlnstats.ligue-1.20190406.json diff --git a/src/test/resources/__files/mpgstats.premier-league.20181017.json b/src/test/resources/__files/mlnstats.premier-league.20181017.json similarity index 100% rename from src/test/resources/__files/mpgstats.premier-league.20181017.json rename to src/test/resources/__files/mlnstats.premier-league.20181017.json