mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-18 22:57:47 +01:00
#1460 Fix null handling in recent players command
- Last login might be null
This commit is contained in:
parent
ea87075cd2
commit
a29738e2a8
@ -42,8 +42,13 @@ public class RecentPlayersCommand implements ExecutableCommand {
|
||||
}
|
||||
|
||||
private String formatPlayerMessage(PlayerAuth auth) {
|
||||
LocalDateTime lastLogin = LocalDateTime.ofInstant(ofEpochMilli(auth.getLastLogin()), getZoneId());
|
||||
String lastLoginText = DATE_FORMAT.format(lastLogin);
|
||||
String lastLoginText;
|
||||
if (auth.getLastLogin() == null) {
|
||||
lastLoginText = "never";
|
||||
} else {
|
||||
LocalDateTime lastLogin = LocalDateTime.ofInstant(ofEpochMilli(auth.getLastLogin()), getZoneId());
|
||||
lastLoginText = DATE_FORMAT.format(lastLogin);
|
||||
}
|
||||
|
||||
return "- " + auth.getRealName() + " (" + lastLoginText + " with IP " + auth.getLastIp() + ")";
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.containsStringIgnoringCase;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@ -60,4 +59,29 @@ public class RecentPlayersCommandTest {
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- Hannah (08:09 AM, 11 Nov with IP 11.11.11.11)")));
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- MATT (11:15 PM, 09 Nov with IP 22.11.22.33)")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandlePlayerWithNullLastLogin() {
|
||||
// given
|
||||
PlayerAuth auth1 = PlayerAuth.builder()
|
||||
.name("xephren").realName("Xephren").lastIp("11.11.11.11")
|
||||
.lastLogin(null)
|
||||
.build();
|
||||
PlayerAuth auth2 = PlayerAuth.builder()
|
||||
.name("silvah777").realName("silvah777").lastIp("22.11.22.33")
|
||||
.lastLogin(1510269301000L) // 11/09/2017 @ 11:15pm
|
||||
.build();
|
||||
doReturn(ZoneId.of("UTC")).when(command).getZoneId();
|
||||
given(dataSource.getRecentlyLoggedInPlayers()).willReturn(Arrays.asList(auth1, auth2));
|
||||
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Recently logged in players")));
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- Xephren (never with IP 11.11.11.11)")));
|
||||
verify(sender).sendMessage(argThat(equalToIgnoringCase("- silvah777 (11:15 PM, 09 Nov with IP 22.11.22.33)")));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user