MiscUtils { public static String getPlayerName(String[] args, Sender sender) { return getPlayerName(args, sender, Permissions.INSPECT_OTHER); } private  MiscUtils(); static String getPlayerName(String[] args, Sender sender); static String getPlayerName(String[] args, Sender sender, Permissions perm); static void close(AutoCloseable... close); static long now(); static long dayAgo(); static long weekAgo(); static long monthAgo();  }
@Test void getNameShouldReturnNameWithPermission() { String[] args = new String[]{"Rsl1122", "Test"}; Sender sender = mockAPlayerSender("TestName", true); String expResult = "Rsl1122"; String result = MiscUtils.getPlayerName(args, sender); assertEquals(expResult, result); }
@Test void getNameShouldReturnNullWithoutPermission() { String[] args = new String[]{"Rsl1122", "Test"}; Sender sender = mockAPlayerSender("TestName", false); String result = MiscUtils.getPlayerName(args, sender); assertNull(result); }
@Test void getNameShouldReturnPlayerNameWithoutArgs() { String[] args = new String[]{}; String expected = "TestName"; Sender sender = mockAPlayerSender(expected, true); String result = MiscUtils.getPlayerName(args, sender); assertEquals(expected, result); }
@Test void getNameShouldReturnPlayerNameWithoutArgsOrPermission() { String[] args = new String[]{}; String expected = "TestName2"; Sender sender = mockAPlayerSender(expected, false); String result = MiscUtils.getPlayerName(args, sender); assertEquals(expected, result); }
@Test void getNameShouldReturnPlayerNameWithoutPermissionForOwnName() { String[] args = new String[]{"testname2"}; String expected = "TestName2"; Sender sender = mockAPlayerSender(expected, false); String result = MiscUtils.getPlayerName(args, sender); assertEquals(expected, result); }
@Test void getNameShouldReturnArgumentForConsole() { String[] args = new String[]{"TestConsoleSender"}; String expected = "TestConsoleSender"; Sender sender = Mockito.mock(Sender.class); when(sender.getSenderType()).thenReturn(SenderType.CONSOLE); String result = MiscUtils.getPlayerName(args, sender); assertEquals(expected, result); }