### Question:
BukkitService implements SettingsDependent { @SuppressWarnings("unchecked") public Collection<? extends Player> getOnlinePlayers() { if (getOnlinePlayersIsCollection) { return Bukkit.getOnlinePlayers(); } try { if (getOnlinePlayers == null) { getOnlinePlayers = Bukkit.class.getDeclaredMethod("getOnlinePlayers"); } Object obj = getOnlinePlayers.invoke(null); if (obj instanceof Collection<?>) { return (Collection<? extends Player>) obj; } else if (obj instanceof Player[]) { return Arrays.asList((Player[]) obj); } else { String type = (obj == null) ? "null" : obj.getClass().getName(); ConsoleLogger.warning("Unknown list of online players of type " + type); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { ConsoleLogger.logException("Could not retrieve list of online players:", e); } return Collections.emptyList(); } @Inject  BukkitService(AuthMe authMe, Settings settings); int scheduleSyncDelayedTask(Runnable task); int scheduleSyncDelayedTask(Runnable task, long delay); void scheduleSyncTaskFromOptionallyAsyncTask(Runnable task); BukkitTask runTask(Runnable task); BukkitTask runTaskLater(Runnable task, long delay); void runTaskOptionallyAsync(Runnable task); BukkitTask runTaskAsynchronously(Runnable task); BukkitTask runTaskTimerAsynchronously(Runnable task, long delay, long period); BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period); int broadcastMessage(String message); Player getPlayerExact(String name); OfflinePlayer getOfflinePlayer(String name); Set<OfflinePlayer> getBannedPlayers(); OfflinePlayer[] getOfflinePlayers(); @SuppressWarnings("unchecked") Collection<? extends Player> getOnlinePlayers(); void callEvent(Event event); E createAndCallEvent(Function<Boolean, E> eventSupplier); World getWorld(String name); boolean dispatchCommand(CommandSender sender, String commandLine); boolean dispatchConsoleCommand(String commandLine); @Override void reload(Settings settings); void sendBungeeMessage(byte[] bytes); BanEntry banIp(String ip, String reason, Date expires, String source); Optional<Boolean> isBungeeCordConfiguredForSpigot(); static final int TICKS_PER_SECOND; static final int TICKS_PER_MINUTE; }### Answer:
@Test public void shouldRetrieveListOfOnlinePlayersFromReflectedMethod() { ReflectionTestUtils.setField(BukkitService.class, bukkitService, "getOnlinePlayersIsCollection", false); ReflectionTestUtils.setField(BukkitService.class, bukkitService, "getOnlinePlayers", ReflectionTestUtils.getMethod(BukkitServiceTest.class, "onlinePlayersImpl")); Collection<? extends Player> players = bukkitService.getOnlinePlayers(); assertThat(players, hasSize(2)); }