How to use getPluginCommand method of be.seeseemelk.mockbukkit.ServerMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.ServerMock.getPluginCommand

Source:ServerMock.java Github

copy

Full Screen

...252 */253 public CommandResult executeConsole(String command, String... args)254 {255 assertMainThread();256 return executeConsole(getPluginCommand(command), args);257 }258 /**259 * Executes a command as a player.260 * 261 * @param command The command to execute.262 * @param args The arguments to pass to the commands.263 * @return The value returned by {@link Command#execute}.264 */265 public CommandResult executePlayer(Command command, String... args)266 {267 assertMainThread();268 if (players.size() > 0)269 {270 return execute(command, players.get(0), args);271 }272 else273 {274 throw new IllegalStateException("Need at least one player to run the command");275 }276 }277 /**278 * Executes a command as a player.279 * 280 * @param command The command to execute.281 * @param args The arguments to pass to the commands.282 * @return The value returned by {@link Command#execute}.283 */284 public CommandResult executePlayer(String command, String... args)285 {286 assertMainThread();287 return executePlayer(getPluginCommand(command), args);288 }289 /**290 * Executes a command.291 * 292 * @param command The command to execute.293 * @param sender The person that executed the command.294 * @param args The arguments to pass to the commands.295 * @return The value returned by {@link Command#execute}.296 */297 public CommandResult execute(Command command, CommandSender sender, String... args)298 {299 assertMainThread();300 if (!(sender instanceof MessageTarget))301 {302 throw new IllegalArgumentException("Only a MessageTarget can be the sender of the command");303 }304 boolean status = command.execute(sender, command.getName(), args);305 CommandResult result = new CommandResult(status, (MessageTarget) sender);306 return result;307 }308 /**309 * Executes a command.310 * 311 * @param command The command to execute.312 * @param sender The person that executed the command.313 * @param args The arguments to pass to the commands.314 * @return The value returned by {@link Command#execute}.315 */316 public CommandResult execute(String command, CommandSender sender, String... args)317 {318 assertMainThread();319 return execute(getPluginCommand(command), sender, args);320 }321 @Override322 public String getName()323 {324 return "ServerMock";325 }326 @Override327 public String getVersion()328 {329 return "0.1.0";330 }331 @Override332 public String getBukkitVersion()333 {334 return "1.12.1";335 }336 @Override337 public Collection<? extends PlayerMock> getOnlinePlayers()338 {339 assertMainThread();340 return players;341 }342 @Override343 public OfflinePlayer[] getOfflinePlayers()344 {345 return offlinePlayers.toArray(new OfflinePlayer[0]);346 }347 @Override348 public Player getPlayer(String name)349 {350 Player player = getPlayerExact(name);351 if (player != null)352 return player;353 354 final String lowercase = name.toLowerCase(Locale.ENGLISH);355 int delta = Integer.MAX_VALUE;356 for (Player namedPlayer : players)357 {358 if (namedPlayer.getName().toLowerCase(Locale.ENGLISH).startsWith(lowercase))359 {360 int currentDelta = Math.abs(namedPlayer.getName().length() - lowercase.length());361 if (currentDelta < delta)362 {363 delta = currentDelta;364 player = namedPlayer;365 }366 }367 }368 return player;369 }370 @Override371 public Player getPlayerExact(String name)372 {373 assertMainThread();374 return this.players.stream().filter(playerMock -> playerMock.getName().equals(name)).findFirst().orElse(null);375 }376 @Override377 public List<Player> matchPlayer(String name)378 {379 assertMainThread();380 return players.stream().filter(player -> player.getName().toLowerCase(Locale.ENGLISH).startsWith(name))381 .collect(Collectors.toList());382 }383 @Override384 public Player getPlayer(UUID id)385 {386 assertMainThread();387 for (Player player : getOnlinePlayers())388 {389 if (id.equals(player.getUniqueId()))390 {391 return player;392 }393 }394 return null;395 }396 @Override397 public PluginManagerMock getPluginManager()398 {399 return pluginManager;400 }401 402 /**403 * Checks if the label given is a possible label of the command.404 * @param command The command to check against.405 * @param label The label that should be checked if it's a label for the command. 406 * @return {@code true} if the label is a label of the command, {@code false} if it's not.407 */408 private boolean isLabelOfCommand(PluginCommand command, String label)409 {410 assertMainThread();411 if (label.equals(command.getName()))412 {413 return true;414 }415 for (String alias : command.getAliases())416 {417 if (label.equals(alias))418 {419 return true;420 }421 }422 return false;423 }424 @Override425 public PluginCommand getPluginCommand(String name)426 {427 assertMainThread();428 for (PluginCommand command : getPluginManager().getCommands())429 {430 if (isLabelOfCommand(command, name))431 {432 return command;433 }434 }435 return null;436 }437 @Override438 public Logger getLogger()439 {440 return logger;441 }442 @Override443 public ConsoleCommandSender getConsoleSender()444 {445 if (consoleSender == null)446 {447 consoleSender = new ConsoleCommandSenderMock();448 }449 return consoleSender;450 }451 452 public InventoryMock createInventory(InventoryHolder owner, InventoryType type, String title, int size)453 {454 assertMainThread();455 InventoryMock inventory;456 switch (type)457 {458 case PLAYER:459 inventory = new PlayerInventoryMock((HumanEntity) owner, title);460 return inventory;461 case CHEST:462 inventory = new ChestInventoryMock(owner, title, size > 0 ? size : 9*3);463 return inventory;464 default:465 throw new UnimplementedOperationException("Inventory type not yet supported");466 }467 }468 @Override469 public InventoryMock createInventory(InventoryHolder owner, InventoryType type)470 {471 return createInventory(owner, type, "Inventory");472 }473 474 @Override475 public InventoryMock createInventory(InventoryHolder owner, InventoryType type, String title)476 {477 return createInventory(owner, type, title, -1);478 }479 @Override480 public InventoryMock createInventory(InventoryHolder owner, int size) throws IllegalArgumentException481 {482 return createInventory(owner, size, "Inventory");483 }484 @Override485 public InventoryMock createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException486 {487 return createInventory(owner, InventoryType.CHEST, title, size);488 }489 @Override490 public ItemFactory getItemFactory()491 {492 return factory;493 }494 @Override495 public List<World> getWorlds()496 {497 return new ArrayList<>(worlds);498 }499 @Override500 public World getWorld(String name)501 {502 return worlds.stream().filter(world -> world.getName().equals(name)).findAny().orElse(null);503 }504 @Override505 public World getWorld(UUID uid)506 {507 return worlds.stream().filter(world -> world.getUID().equals(uid)).findAny().orElse(null);508 }509 @Override510 public BukkitSchedulerMock getScheduler()511 {512 return scheduler;513 }514 @Override515 public int getMaxPlayers()516 {517 return playerList.getMaxPlayers();518 }519 @Override520 public Set<String> getIPBans()521 {522 return this.playerList.getIPBans().getBanEntries().stream().map(BanEntry::getTarget)523 .collect(Collectors.toSet());524 }525 @Override526 public void banIP(String address)527 {528 assertMainThread();529 this.playerList.getIPBans().addBan(address, null, null, null);530 }531 @Override532 public void unbanIP(String address)533 {534 assertMainThread();535 this.playerList.getIPBans().pardon(address);536 }537 @Override538 public BanList getBanList(Type type)539 {540 switch (type)541 {542 case IP:543 return playerList.getIPBans();544 case NAME:545 default:546 return playerList.getProfileBans();547 }548 }549 @Override550 public Set<OfflinePlayer> getOperators()551 {552 assertMainThread();553 final Set<OfflinePlayer> players = new HashSet<>();554 players.addAll(this.offlinePlayers);555 players.addAll(this.players);556 return players.stream().filter(OfflinePlayer::isOp).collect(Collectors.toSet());557 }558 @Override559 public GameMode getDefaultGameMode()560 {561 return this.defaultGameMode;562 }563 @Override564 public void setDefaultGameMode(GameMode mode)565 {566 assertMainThread();567 this.defaultGameMode = mode;568 }569 @Override570 public int broadcastMessage(String message)571 {572 assertMainThread();573 for (Player player : players)574 player.sendMessage(message);575 return players.size();576 }577 578 @Override579 public boolean addRecipe(Recipe recipe)580 {581 assertMainThread();582 recipes.add(recipe);583 return true;584 }585 586 @Override587 public List<Recipe> getRecipesFor(ItemStack result)588 {589 assertMainThread();590 return recipes.stream()591 .filter(recipe -> recipe.getResult().equals(result))592 .collect(Collectors.toList());593 }594 @Override595 public Iterator<Recipe> recipeIterator()596 {597 assertMainThread();598 return recipes.iterator();599 }600 @Override601 public void clearRecipes()602 {603 assertMainThread();604 recipes.clear();605 }606 607 @Override608 public boolean dispatchCommand(CommandSender sender, String commandLine) throws CommandException609 {610 assertMainThread();611 String[] commands = commandLine.split(" ");612 String commandLabel = commands[0];613 String[] args = Arrays.copyOfRange(commands, 1, commands.length);614 Command command = getPluginCommand(commandLabel);615 if (command != null)616 return command.execute(sender, commandLabel, args);617 else618 return false;619 }620 @Override621 public void sendPluginMessage(Plugin source, String channel, byte[] message)622 {623 // TODO Auto-generated method stub624 throw new UnimplementedOperationException();625 }626 @Override627 public Set<String> getListeningPluginChannels()628 {...

Full Screen

Full Screen

Source:CommandsTest.java Github

copy

Full Screen

...53 void testCommandTimehandlerHelp_ServerArgs_1() {54 boolean condition;55 String label = "timehandler";56 String[] args = {"help"};57 Command command = server.getPluginCommand(label);58 PluginCommand pluginCommand = timeHandler.getCommand("timehandler info");59 assert pluginCommand != null;60 pluginCommand.setAliases(Collections.singletonList("th info"));61 server.getConsoleSender().addPermission("timehandler.info.use");62 assert command != null;63 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);64 assertTrue(condition);65 }66 /* ==== TEST /TIMEHANDLER INFO ==== */67 @Test68 void testCommandTimehandlerInfo_PlayerArgs_1() {69 boolean condition;70 String label = "timehandler";71 Command command = server.getPluginCommand(label);72 PlayerMock pMock = new PlayerMock(server, "player");73 String[] args = {"info"};74 assert command != null;75 condition = timeHandler.onCommand(pMock, command, label, args);76 77 assertTrue(condition);78 }79 @Test80 void testCommandTimehandlerInfo_ServerArgs_1() {81 boolean condition;82 String label = "timehandler";83 String[] args = {"info"};84 Command command = server.getPluginCommand(label);85 assert command != null;86 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);87 88 assertFalse(condition);89 }90 @Test91 void testCommandTimehandlerInfo_ServerArgs_2() {92 boolean condition;93 String label = "timehandler";94 String[] args = {"info", "test"};95 Command command = server.getPluginCommand(label);96 assert command != null;97 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);98 99 assertTrue(condition);100 }101 /* ==== TEST /TIMEHANDLER LIST ==== */102 @Test103 void testCommandTimehandlerList_ServerArgs_1() {104 boolean condition;105 String label = "timehandler";106 String[] args = {"list"};107 Command command = server.getPluginCommand(label);108 assert command != null;109 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);110 111 assertTrue(condition);112 }113 @Test114 void testCommandTimehandlerList_ServerArgs_2() {115 boolean condition;116 String label = "timehandler";117 String[] args = {"list", "test"};118 Command command = server.getPluginCommand(label);119 assert command != null;120 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);121 122 assertFalse(condition);123 }124 /* ==== TEST /TIMEHANDLER SET ==== */125 @Test126 @Order(1)127 void testCommandTimehandlerSet_ServerArgs_2() {128 boolean condition;129 String label = "timehandler";130 String[] args = {"set", "test"};131 Command command = server.getPluginCommand(label);132 assert command != null;133 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);134 135 assertTrue(condition);136 }137 @Test138 void testCommandTimehandlerSet_ServerArgs_4() {139 boolean condition;140 String label = "timehandler";141 String[] args = {"set", "test", "enabled", "false"};142 Command command = server.getPluginCommand(label);143 assert command != null;144 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);145 146 assertTrue(condition);147 148 WorldManager wm = TimeManager.getRunablesWorld().get("test");149 150 assertNotNull(wm);151 assertFalse(wm.isEnabled());152 }153 @Test154 void testCommandTimehandlerSet_ServerArgs_3() {155 boolean condition;156 String label = "timehandler";157 String[] args = {"set", "test", "enabled"};158 Command command = server.getPluginCommand(label);159 assert command != null;160 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);161 162 assertFalse(condition);163 }164 /* ==== TEST /TIMEHANDLER UPDATE ==== */165 @Test166 void testCommandTimehandlerUpdate_ServerArgs_0() {167 boolean condition;168 String label = "timehandler";169 String[] args = {"update"};170 Command command = server.getPluginCommand(label);171 172 assert command != null;173 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);174 175 assertTrue(condition);176 }177 /* ==== TEST /TIMEHANDLER ANYTHING ==== */178 @Test179 void testCommandTimehandlerAnything_ServerArgs_0() {180 boolean condition;181 String label = "timehandler";182 String[] args = {"testErro"};183 Command command = server.getPluginCommand(label);184 185 assert command != null;186 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);187 188 assertFalse(condition);189 }190 /* ==== TEST /DAY ==== */191 @Test192 void testCommandDay_ServerArgs_0() {193 boolean condition;194 String label = "day";195 String[] args = {};196 Command command = server.getPluginCommand(label);197 198 assert command != null;199 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);200 201 assertFalse(condition);202 }203 @Test204 void testCommandDay_ServerArgs_1() {205 boolean condition;206 String label = "day";207 String[] args = {"test"};208 Command command = server.getPluginCommand(label);209 210 wMock.setTime(18000);211 assertEquals(wMock.getTime(), 18000);212 213 assert command != null;214 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);215 216 assertTrue(condition);217 assertTrue(wMock.getTime() < 12000);218 }219 @Test220 void testCommandDay_PlayerArgs_0() {221 boolean condition;222 String label = "day";223 String[] args = {};224 Command command = server.getPluginCommand(label);225 PlayerMock pMock = new PlayerMock(server, "player");226 World world = pMock.getWorld();227 world.setTime(18000);228 assertEquals(world.getTime(), 18000);229 230 assert command != null;231 condition = timeHandler.onCommand(pMock, command, label, args);232 233 assertTrue(condition);234 assertTrue(world.getTime() < 12000);235 }236 /* ==== TEST /NIGHT ==== */237 @Test238 void testCommandNight_ServerArgs_0() {239 boolean condition;240 String label = "night";241 String[] args = {};242 Command command = server.getPluginCommand(label);243 244 assert command != null;245 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);246 247 assertFalse(condition);248 }249 @Test250 void testCommandNight_ServerArgs_1() {251 boolean condition;252 String label = "night";253 String[] args = {"test"};254 Command command = server.getPluginCommand(label);255 256 wMock.setTime(6000);257 assertEquals(wMock.getTime(), 6000);258 259 assert command != null;260 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);261 262 assertTrue(condition);263 assertTrue(wMock.getTime() > 12000);264 }265 @Test266 void testCommandNight_PlayerArgs_0() {267 boolean condition;268 String label = "night";269 String[] args = {};270 Command command = server.getPluginCommand(label);271 PlayerMock pMock = new PlayerMock(server, "player");272 World world = pMock.getWorld();273 world.setTime(6000);274 275 assertEquals(world.getTime(), 6000);276 277 assert command != null;278 condition = timeHandler.onCommand(pMock, command, label, args);279 280 assertTrue(condition);281 assertTrue(world.getTime() > 12000);282 }283 /* ==== TEST /MOONPHASE ==== */284 @Test285 void testCommandMoonPhase_PlayerArgs_1() {286 boolean condition;287 String label = "moonphase";288 Set<String> phases = MoonPhasesEnum.getList();289 Command command = server.getPluginCommand(label);290 PlayerMock pMock = new PlayerMock(server, "player");291 World world = pMock.getWorld();292 for(String p : phases) {293 String[] args = {p};294 assert command != null;295 condition = timeHandler.onCommand(pMock, command, label, args);296 297 if(MoonPhasesEnum.getEnumPorValue(p) == MoonPhasesEnum.DEFAULT) {298 assertFalse(condition);299 continue;300 }301 302 assertTrue(condition);303 304 long fullTime = world.getFullTime();305 int days = (int) (fullTime / 24000);306 int actual = days % 8;307 int expected = MoonPhasesEnum.getEnumPorValue(p).ordinal();308 309 assertEquals(expected, actual);310 }311 String[] aux = {"testeErro"};312 assert command != null;313 condition = timeHandler.onCommand(pMock, command, label, aux);314 assertFalse(condition);315 316 }317 @Test318 void testCommandMoonPhase_ServerArgs_1() {319 boolean condition;320 String label = "moonphase";321 Command command = server.getPluginCommand(label);322 String[] testeErro = {"testeErro"};323 assert command != null;324 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, testeErro);325 assertFalse(condition);326 327 String[] testeTest = {"test"};328 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, testeTest);329 assertFalse(condition);330 331 }332 @Test333 void testCommandMoonPhase_ServerArgs_2() {334 boolean condition;335 String label = "moonphase";336 Set<String> phases = MoonPhasesEnum.getList();337 Command command = server.getPluginCommand(label);338 for(String p : phases) {339 String[] args = {p, "test"};340 assert command != null;341 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);342 343 if(MoonPhasesEnum.getEnumPorValue(p) == MoonPhasesEnum.DEFAULT) {344 assertFalse(condition);345 continue;346 }347 348 assertTrue(condition);349 350 long fullTime = wMock.getFullTime();351 int days = (int) (fullTime / 24000);352 int actual = days % 8;353 int expected = MoonPhasesEnum.getEnumPorValue(p).ordinal();354 355 assertEquals(expected, actual);356 }357 String[] aux = {"testeErro", "test"};358 assert command != null;359 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, aux);360 assertFalse(condition);361 362 }363 /* ==== TEST /RAIN ==== */364 @Test365 void testCommandRain_ServerArgs_0() {366 boolean condition;367 String label = "rain";368 String[] args = {};369 Command command = server.getPluginCommand(label);370 371 wMock.setStorm(false);372 wMock.setThundering(false);373 374 assertFalse(wMock.hasStorm());375 assertFalse(wMock.isThundering());376 assert command != null;377 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);378 379 assertFalse(condition);380 }381 @Test382 void testCommandRain_ServerArgs_1() {383 boolean condition;384 String label = "rain";385 String[] args = {"test"};386 Command command = server.getPluginCommand(label);387 wMock.setStorm(false);388 wMock.setThundering(false);389 390 assertFalse(wMock.hasStorm());391 assertFalse(wMock.isThundering());392 assert command != null;393 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);394 395 assertTrue(condition);396 397 assertTrue(wMock.hasStorm());398 assertFalse(wMock.isThundering());399 }400 @Test401 void testCommandRain_ServerArgs_2() {402 boolean condition;403 String label = "rain";404 String[] args = {"test", "20000"};405 Command command = server.getPluginCommand(label);406 wMock.setStorm(false);407 wMock.setThundering(false);408 409 assertFalse(wMock.hasStorm());410 assertFalse(wMock.isThundering());411 assert command != null;412 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);413 414 assertTrue(condition);415 416 assertTrue(wMock.hasStorm());417 assertEquals(wMock.getWeatherDuration(), 20000);418 assertFalse(wMock.isThundering());419 }420 @Test421 void testCommandRain_PlayerArgs_0() {422 boolean condition;423 String label = "rain";424 String[] args = {};425 Command command = server.getPluginCommand(label);426 PlayerMock pMock = new PlayerMock(server, "player");427 World world = pMock.getWorld();428 429 world.setStorm(false);430 world.setThundering(false);431 432 assertFalse(world.hasStorm());433 assertFalse(world.isThundering());434 assert command != null;435 condition = timeHandler.onCommand(pMock, command, label, args);436 437 assertTrue(condition);438 439 assertTrue(world.hasStorm());440 assertFalse(world.isThundering());441 }442 /* ==== TEST /THUNDERING ==== */443 @Test444 void testCommandThundering_ServerArgs_0() {445 boolean condition;446 String label = "thundering";447 String[] args = {};448 Command command = server.getPluginCommand(label);449 450 wMock.setStorm(false);451 wMock.setThundering(false);452 453 assertFalse(wMock.hasStorm());454 assertFalse(wMock.isThundering());455 456 assert command != null;457 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);458 459 assertFalse(condition);460 }461 @Test462 void testCommandThundering_ServerArgs_1() {463 boolean condition;464 String label = "thundering";465 String[] args = {"test"};466 Command command = server.getPluginCommand(label);467 wMock.setStorm(false);468 wMock.setThundering(false);469 470 assertFalse(wMock.hasStorm());471 assertFalse(wMock.isThundering());472 473 assert command != null;474 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);475 476 assertTrue(condition);477 478 assertTrue(wMock.hasStorm());479 assertTrue(wMock.isThundering());480 }481 @Test482 void testCommandThundering_ServerArgs_2() {483 boolean condition;484 String label = "thundering";485 String[] args = {"test", "15000"};486 Command command = server.getPluginCommand(label);487 wMock.setStorm(false);488 wMock.setThundering(false);489 490 assertFalse(wMock.hasStorm());491 assertFalse(wMock.isThundering());492 493 assert command != null;494 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);495 496 assertTrue(condition);497 498 assertTrue(wMock.hasStorm());499 assertTrue(wMock.isThundering());500 assertEquals(wMock.getThunderDuration(), 15000);501 }502 @Test503 void testCommandThundering_PlayerArgs_0() {504 boolean condition;505 String label = "thundering";506 String[] args = {};507 Command command = server.getPluginCommand(label);508 PlayerMock pMock = new PlayerMock(server, "player");509 World world = pMock.getWorld();510 511 world.setStorm(false);512 world.setThundering(false);513 514 assertFalse(world.hasStorm());515 assertFalse(world.isThundering());516 517 assert command != null;518 condition = timeHandler.onCommand(pMock, command, label, args);519 520 assertTrue(condition);521 522 assertTrue(world.hasStorm());523 assertTrue(world.isThundering());524 }525 /* ==== TEST /CALM ==== */526 @Test527 void testCommandCalm_ServerArgs_0() {528 boolean condition;529 String label = "calm";530 String[] args = {};531 Command command = server.getPluginCommand(label);532 533 wMock.setStorm(true);534 wMock.setThundering(true);535 536 assertTrue(wMock.hasStorm());537 assertTrue(wMock.isThundering());538 539 assert command != null;540 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);541 542 assertFalse(condition);543 }544 @Test545 void testCommandCalm_ServerArgs_1() {546 boolean condition;547 String label = "calm";548 String[] args = {"test"};549 Command command = server.getPluginCommand(label);550 wMock.setStorm(true);551 wMock.setThundering(true);552 553 assertTrue(wMock.hasStorm());554 assertTrue(wMock.isThundering());555 556 assert command != null;557 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);558 559 assertTrue(condition);560 561 assertFalse(wMock.hasStorm());562 assertFalse(wMock.isThundering());563 }564 @Test565 void testCommandCalm_ServerArgs_2() {566 boolean condition;567 String label = "calm";568 String[] args = {"test", "30000"};569 Command command = server.getPluginCommand(label);570 wMock.setStorm(true);571 wMock.setThundering(true);572 573 assertTrue(wMock.hasStorm());574 assertTrue(wMock.isThundering());575 576 assert command != null;577 condition = timeHandler.onCommand(server.getConsoleSender(), command, label, args);578 579 assertTrue(condition);580 assertFalse(wMock.hasStorm());581 assertFalse(wMock.isThundering());582 assertEquals(wMock.getWeatherDuration(), 30000);583 }584 @Test585 void testCommandCalm_PlayerArgs_0() {586 boolean condition;587 String label = "calm";588 String[] args = {};589 Command command = server.getPluginCommand(label);590 PlayerMock pMock = new PlayerMock(server, "player");591 World world = pMock.getWorld();592 wMock.setStorm(true);593 wMock.setThundering(true);594 595 assertTrue(wMock.hasStorm());596 assertTrue(wMock.isThundering());597 598 assert command != null;599 condition = timeHandler.onCommand(pMock, command, label, args);600 601 assertTrue(condition);602 603 assertFalse(world.hasStorm());...

Full Screen

Full Screen

Source:ServerMockTest.java Github

copy

Full Screen

...148 server.setOfflinePlayers(2);149 assertEquals(3, server.getOfflinePlayers().length);150 }151 @Test152 public void getPluginCommand_testcommand_Command()153 {154 MockBukkit.load(TestPlugin.class);155 assertNotNull(server.getPluginCommand("testcommand"));156 }157 158 @Test159 public void getPluginCommand_tcAlias_Command()160 {161 MockBukkit.load(TestPlugin.class);162 assertNotNull(server.getPluginCommand("tc"));163 }164 165 @Test166 public void getPluginCommand_ocWithoutAlias_Command()167 {168 MockBukkit.load(TestPlugin.class);169 assertNotNull(server.getPluginCommand("othercommand"));170 }171 172 @Test173 public void getPluginCommand_Unknown_Null()174 {175 MockBukkit.load(TestPlugin.class);176 assertNull(server.getPluginCommand("notknown"));177 }178 179 @Test180 public void executeCommand_PlayerAndTrueReturnValue_Succeeds()181 {182 server.setPlayers(1);183 TestPlugin plugin = (TestPlugin) MockBukkit.load(TestPlugin.class);184 plugin.commandReturns = true;185 186 Command command = server.getPluginCommand("testcommand");187 CommandResult result = server.executePlayer(command, "a", "b");188 result.assertSucceeded();189 assertEquals(server.getPlayer(0), plugin.commandSender);190 assertEquals(command, plugin.command);191 192 assertEquals(2, plugin.commandArguments.length);193 assertEquals("a", plugin.commandArguments[0]);194 assertEquals("b", plugin.commandArguments[1]);195 }196 197 @Test198 public void executeCommand_ConsoleAndFalseReturnValue_Fails()199 {200 TestPlugin plugin = (TestPlugin) MockBukkit.load(TestPlugin.class);201 plugin.commandReturns = false;202 203 Command command = server.getPluginCommand("testcommand");204 CommandResult result = server.executeConsole(command, "a", "b");205 result.assertFailed();206 assertEquals(server.getConsoleSender(), plugin.commandSender);207 assertEquals(command, plugin.command);208 209 assertEquals(2, plugin.commandArguments.length);210 assertEquals("a", plugin.commandArguments[0]);211 assertEquals("b", plugin.commandArguments[1]);212 }213 214 @Test215 public void executeCommand_CommandAsStringAndTrueReturnValue_Succeeds()216 {217 TestPlugin plugin = (TestPlugin) MockBukkit.load(TestPlugin.class);...

Full Screen

Full Screen

getPluginCommand

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.command.CommandResult;4import be.seeseemelk.mockbukkit.command.CommandSenderMock;5import be.seeseemelk.mockbukkit.entity.PlayerMock;6import org.bukkit.command.CommandSender;7import org.bukkit.entity.Player;8import org.junit.After;9import org.junit.Before;10import org.junit.Test;11import static org.junit.Assert.*;12public class CommandTest {13 private ServerMock server;14 private CommandSenderMock sender;15 private PlayerMock player;16 public void setUp() throws Exception {17 server = MockBukkit.mock();18 sender = server.addPlayer();19 player = server.addPlayer();20 }21 public void tearDown() throws Exception {22 MockBukkit.unmock();23 }24 public void testCommand() {25 CommandResult result = server.getPluginCommand("test").dispatch(sender, "test");26 assertTrue(result.wasSuccessful());27 assertEquals("test", result.getMessage());28 }29 public void testCommandWithPlayer() {30 CommandResult result = server.getPluginCommand("test").dispatch(player, "test");31 assertTrue(result.wasSuccessful());32 assertEquals("test", result.getMessage());33 }34 public void testCommandWithArgs() {35 CommandResult result = server.getPluginCommand("test").dispatch(sender, "test", "arg1", "arg2");36 assertTrue(result.wasSuccessful());37 assertEquals("test arg1 arg2", result.getMessage());38 }39 public void testCommandWithPlayerAndArgs() {40 CommandResult result = server.getPluginCommand("test").dispatch(player, "test", "arg1", "arg2");41 assertTrue(result.wasSuccessful());42 assertEquals("test arg1 arg2", result.getMessage());43 }44 public void testCommandWithInvalidSender() {45 CommandResult result = server.getPluginCommand("test").dispatch(server.getConsoleSender(), "test");46 assertFalse(result.wasSuccessful());47 assertEquals("You must be a player to use this command", result.getMessage());48 }49}50package com.example.test;51import be.seeseemelk.mockbukkit.MockBukkit;52import be.seeseemelk.mockbukkit.ServerMock;53import be.seese

Full Screen

Full Screen

getPluginCommand

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.command.CommandMock;4import be.seeseemelk.mockbukkit.command.SimpleCommandMapMock;5import be.seeseemelk.mockbukkit.entity.PlayerMock;6import org.bukkit.Bukkit;7import org.bukkit.command.Command;8import org.bukkit.command.CommandExecutor;9import org.bukkit.command.CommandSender;10import org.bukkit.entity.Player;11import org.bukkit.plugin.Plugin;12import org.bukkit.plugin.java.JavaPlugin;13import org.junit.After;14import org.junit.Assert;15import org.junit.Before;16import org.junit.Test;17{18 private ServerMock server;19 private Plugin plugin;20 public void setUp()21 {22 server = MockBukkit.mock();23 plugin = MockBukkit.load(JavaPlugin.class);24 server.addSimpleWorld("world");25 }26 public void tearDown()27 {28 MockBukkit.unmock();29 }30 public void testCommand()31 {32 CommandMock command = server.getPluginCommand("test", plugin);33 command.setExecutor(new TestExecutor());34 Player player = server.addPlayer();35 server.dispatchCommand(player, "test");36 Assert.assertTrue(player.isOp());37 }38 {39 public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings)40 {41 if (commandSender instanceof Player)42 {43 Player player = (Player) commandSender;44 player.setOp(true);45 }46 return true;47 }48 }49}

Full Screen

Full Screen

getPluginCommand

Using AI Code Generation

copy

Full Screen

1import org.junit.jupiter.api.Test;2import org.junit.jupiter.api.extension.ExtendWith;3import org.mockito.Mock;4import org.mockito.junit.jupiter.MockitoExtension;5import org.mockito.junit.jupiter.MockitoSettings;6import org.mockito.quality.Strictness;7import be.seeseemelk.mockbukkit.MockBukkit;8import be.seeseemelk.mockbukkit.ServerMock;9import static org.junit.jupiter.api.Assertions.*;10import static org.mockito.Mockito.*;11@ExtendWith(MockitoExtension.class)12@MockitoSettings(strictness = Strictness.LENIENT)13{14 private ServerMock server;15 public void testGetPluginCommand()16 {17 MockBukkit.mock();18 when(server.getPluginCommand("test")).thenReturn(null);19 assertNull(server.getPluginCommand("test"));20 }21}22at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:200)23at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:183)24at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:74)25at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestClassConstructor(ClassBasedTestDescriptor.java:342)26at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateTestClass(ClassBasedTestDescriptor.java:289)27at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:79)28at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:267)29at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:259)30at java.base/java.util.Optional.orElseGet(Optional.java:369)31at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:258)32at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)33at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:101)34at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

Full Screen

Full Screen

getPluginCommand

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.junit.jupiter.api.AfterEach;3import org.junit.jupiter.api.BeforeEach;4import org.junit.jupiter.api.Test;5import org.junit.jupiter.api.extension.ExtendWith;6import org.mockito.Mockito;7import org.mockito.junit.jupiter.MockitoExtension;8import be.seeseemelk.mockbukkit.MockBukkit;9import be.seeseemelk.mockbukkit.ServerMock;10@ExtendWith(MockitoExtension.class)11class MockBukkitTest {12 private ServerMock server;13 void setUp() {14 server = MockBukkit.mock();15 }16 void tearDown() {17 MockBukkit.unmock();18 }19 void test() {20 server.getPluginCommand("test");21 Mockito.verify(server).getPluginCommand("test");22 }23}24 server.getPluginCommand("test");25 symbol: method getPluginCommand(String)

Full Screen

Full Screen

getPluginCommand

Using AI Code Generation

copy

Full Screen

1public class 2 extends JavaPlugin {2 public void onEnable() {3 getPluginCommand("command").setExecutor(new MyCommand());4 }5}6public class 3 extends JavaPlugin {7 public void onEnable() {8 getCommandMap().register("command", new MyCommand());9 }10}11public class 4 extends JavaPlugin {12 public void onEnable() {13 getServer().registerEvents(new MyListener(), this);14 }15}16public class 5 extends JavaPlugin {17 public void onEnable() {18 getServer().getScheduler().runTaskLater(this, () -> {19 }, 20L);20 }21}22public class 6 extends JavaPlugin {23 public void onEnable() {24 getServer().getPluginManager().callEvent(new MyEvent());25 }26}27public class 7 extends JavaPlugin {28 public void onEnable() {29 getServer().getOfflinePlayer("name");30 }31}32public class 8 extends JavaPlugin {33 public void onEnable() {34 getServer().getOfflinePlayer(UUID.randomUUID());35 }36}37public class 9 extends JavaPlugin {38 public void onEnable() {39 getServer().getOfflinePlayer(new OfflinePlayer() {40 public boolean isOnline() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run MockBukkit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ServerMock

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful