Skip to content

Commit

Permalink
Fix #209 : Captain bonus no more cumulative with boostOnePlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Oct 19, 2021
1 parent 93a0568 commit 0f4ea11
Show file tree
Hide file tree
Showing 11 changed files with 1,619 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,11 @@ private static CoachRequest getCoachRequest(Team team, Coach coach, List<Player>
List<Player> midfielders = players.stream().filter(p -> p.getPosition().equals(Position.M)).collect(Collectors.toList());
List<Player> attackers = players.stream().filter(p -> p.getPosition().equals(Position.A)).collect(Collectors.toList());

String playerIdForBonusOrCaptain = midfielders.get(0).getId();
request.setBonusSelected(
selectBonus(coach.getBonusSelected(), team.getBonuses(), gameRemaining, config.isUseBonus(), playerIdForBonusOrCaptain));
request.setCaptain(selectCapatain(coach.getCaptain(), playerIdForBonusOrCaptain, config.isUseBonus()));
String playerIdForBonus = midfielders.get(0).getId();
request.setBonusSelected(selectBonus(coach.getBonusSelected(), team.getBonuses(), gameRemaining, config.isUseBonus(), playerIdForBonus));
String playerIdForCaptain = request.getBonusSelected() != null
&& SelectedBonus.BONUS_BOOT_ONE_PLAYER.equals(request.getBonusSelected().getName()) ? midfielders.get(1).getId() : playerIdForBonus;
request.setCaptain(selectCapatain(coach.getCaptain(), playerIdForCaptain, config.isUseBonus()));

// Main lines
setPlayersOnPitch(request, defenders, nbrDefenders, 1);
Expand Down Expand Up @@ -532,21 +533,21 @@ private static CoachRequest getCoachRequest(Team team, Coach coach, List<Player>
}

// If Bonus is player power up (boostOnePlayer), verify that player is on pitch, override otherwise
verifyBonusPlayerOverrideOnPitch(request, playerIdForBonusOrCaptain);
verifyBonusPlayersOverrideOnPitch(request, playerIdForBonus, playerIdForCaptain);

return request;
}

static void verifyBonusPlayerOverrideOnPitch(CoachRequest request, String playerIdEnfored) {
static void verifyBonusPlayersOverrideOnPitch(CoachRequest request, String playerIdForBonusEnforced, String playerIdForCaptainEnforced) {
// Bonus
if (request.getBonusSelected() != null && SelectedBonus.BONUS_BOOT_ONE_PLAYER.equals(request.getBonusSelected().getName())
&& !verifyPlayerOnPitch(request.getPlayersOnPitch(), request.getBonusSelected().getPlayerId())) {
request.getBonusSelected().setPlayerId(playerIdEnfored);
request.getBonusSelected().setPlayerId(playerIdForBonusEnforced);
}

// Captain
if (StringUtils.isNotBlank(request.getCaptain()) && !verifyPlayerOnPitch(request.getPlayersOnPitch(), request.getCaptain())) {
request.setCaptain(playerIdEnfored);
request.setCaptain(playerIdForCaptainEnforced);
}
}

Expand Down
25 changes: 24 additions & 1 deletion src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ public void testRealWithBadCredentials() throws Exception {
}
}

@Test
public void testCaptainAndBoostPlayerBonus() throws Exception {
prepareMainFrenchLigue2Mocks("MLEFEX6G-20211019", "2021", "20211019", "20211019");
stubFor(get("/division/mpg_division_MLEFEX6G_3_1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json")));
stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json")));
stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json")));
stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2")
.withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json")))
.willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json")
.withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2")));

Config config = spy(getConfig());
doReturn(true).when(config).isTeampUpdate();
doReturn(false).when(config).isTacticalSubstitutes();
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Boissier Remy"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Picouleau Mathis)"));
}

@Test
public void testCaptainNotOnMainPitch() throws Exception {
prepareMainFrenchLigue1Mocks("MLAX7HMK-status-4", "2021", "20210812", "20210812");
Expand All @@ -82,7 +105,7 @@ public void testCaptainNotOnMainPitch() throws Exception {
// 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(" Captain: Faivre Romain"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Bamba Jonathan)"));
}

Expand Down
Loading

0 comments on commit 0f4ea11

Please sign in to comment.