Skip to content

Commit

Permalink
🐛 Correct issue with unexpected string format
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGraversen committed Jan 22, 2020
1 parent ba7afcb commit 217663e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public class PlayerListMapper implements IRconResponseMapper<PlayerList> {

@Override
public PlayerList apply(RconResponse rconResponse) {
final String[] players = rconResponse.getResponseString().split(PATTERN_INITIAL.pattern());
if (rconResponse.getResponseString() != null) {
final String responseString = rconResponse.getResponseString().trim();
final String[] players = responseString.split(PATTERN_INITIAL.pattern());

if (players.length == 2) {
return extractPlayerUuids(players[1]);
} else {
return new PlayerList(List.of());
if (players.length == 2) {
return extractPlayerUuids(players[1]);
} else {
return new PlayerList(List.of());
}
}

return new PlayerList(List.of());
}

private PlayerList extractPlayerUuids(String players) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void apply_playersOnline() {
@Test
void apply_noPlayersOnline() {
final var testRconResponse =
new RconResponse(0, 0, 0, 0, "There are 0 of a max 20 players online:");
new RconResponse(0, 0, 0, 0, "There are 0 of a max 20 players online: ");

final var playerList = playerListMapper.apply(testRconResponse);

Expand Down

0 comments on commit 217663e

Please sign in to comment.