Best MockBukkit code snippet using be.seeseemelk.mockbukkit.profile.PlayerProfileMock.complete
Source:ServerMock.java
...890 }891 }892 public @NotNull List<String> getCommandTabComplete(@NotNull CommandSender sender, @NotNull String commandLine)893 {894 AsyncCatcher.catchOp("command tabcomplete");895 int idx = commandLine.indexOf(' ');896 String commandLabel = commandLine.substring(0, idx);897 String[] args = commandLine.substring(idx + 1).split(" ", -1);898 Command command = getCommandMap().getCommand(commandLabel);899 if (command != null)900 {901 return command.tabComplete(sender, commandLabel, args);902 }903 else904 {905 return Collections.emptyList();906 }907 }908 @Override...
Source:ServerMockTest.java
1package be.seeseemelk.mockbukkit;2import be.seeseemelk.mockbukkit.command.CommandResult;3import be.seeseemelk.mockbukkit.entity.EntityMock;4import be.seeseemelk.mockbukkit.entity.OfflinePlayerMock;5import be.seeseemelk.mockbukkit.entity.PlayerMock;6import be.seeseemelk.mockbukkit.entity.PlayerMockFactory;7import be.seeseemelk.mockbukkit.entity.SimpleEntityMock;8import be.seeseemelk.mockbukkit.inventory.InventoryMock;9import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;10import com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent;11import com.destroystokyo.paper.event.server.WhitelistToggleEvent;12import com.google.common.io.ByteArrayDataOutput;13import com.google.common.io.ByteStreams;14import net.kyori.adventure.text.Component;15import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;16import org.bukkit.Material;17import org.bukkit.OfflinePlayer;18import org.bukkit.Warning;19import org.bukkit.World;20import org.bukkit.WorldCreator;21import org.bukkit.WorldType;22import org.bukkit.block.data.BlockData;23import org.bukkit.command.Command;24import org.bukkit.entity.Player;25import org.bukkit.event.inventory.InventoryType;26import org.bukkit.event.player.AsyncPlayerPreLoginEvent;27import org.bukkit.event.player.PlayerJoinEvent;28import org.bukkit.event.player.PlayerKickEvent;29import org.bukkit.event.player.PlayerLoginEvent;30import org.bukkit.event.server.MapInitializeEvent;31import org.bukkit.inventory.ItemStack;32import org.bukkit.inventory.Recipe;33import org.bukkit.map.MapView;34import org.bukkit.potion.PotionEffectType;35import org.bukkit.scoreboard.ScoreboardManager;36import org.jetbrains.annotations.NotNull;37import org.junit.jupiter.api.AfterEach;38import org.junit.jupiter.api.BeforeEach;39import org.junit.jupiter.api.Test;40import org.junit.jupiter.params.ParameterizedTest;41import org.junit.jupiter.params.provider.CsvSource;42import org.junit.jupiter.params.provider.ValueSource;43import javax.imageio.ImageIO;44import java.awt.Graphics2D;45import java.awt.image.BufferedImage;46import java.io.ByteArrayInputStream;47import java.io.File;48import java.io.IOException;49import java.util.Arrays;50import java.util.Base64;51import java.util.Iterator;52import java.util.List;53import java.util.Set;54import java.util.UUID;55import static org.hamcrest.MatcherAssert.assertThat;56import static org.hamcrest.Matchers.containsInAnyOrder;57import static org.hamcrest.Matchers.equalTo;58import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;59import static org.junit.jupiter.api.Assertions.assertEquals;60import static org.junit.jupiter.api.Assertions.assertFalse;61import static org.junit.jupiter.api.Assertions.assertNotEquals;62import static org.junit.jupiter.api.Assertions.assertNotNull;63import static org.junit.jupiter.api.Assertions.assertNull;64import static org.junit.jupiter.api.Assertions.assertSame;65import static org.junit.jupiter.api.Assertions.assertThrows;66import static org.junit.jupiter.api.Assertions.assertTrue;67import static org.junit.jupiter.api.Assumptions.assumeTrue;68class ServerMockTest69{70 private ServerMock server;71 @BeforeEach72 void setUp()73 {74 server = MockBukkit.mock();75 }76 @AfterEach77 void tearDown()78 {79 MockBukkit.unmock();80 }81 @Test82 void class_NumberOfPlayers_Zero()83 {84 assertEquals(0, server.getOnlinePlayers().size());85 }86 @Test87 void createWorld_WorldCreator()88 {89 WorldCreator worldCreator = new WorldCreator("test")90 .seed(12345)91 .type(WorldType.FLAT)92 .environment(World.Environment.NORMAL);93 World world = server.createWorld(worldCreator);94 assertEquals(1, server.getWorlds().size());95 assertEquals("test", world.getName());96 assertEquals(12345, world.getSeed());97 assertEquals(WorldType.FLAT, world.getWorldType());98 assertEquals(World.Environment.NORMAL, world.getEnvironment());99 }100 @Test101 void addPlayer_TwoPlayers_SizeIsTwo()102 {103 PlayerMockFactory factory = new PlayerMockFactory(server);104 PlayerMock player1 = factory.createRandomPlayer();105 PlayerMock player2 = factory.createRandomPlayer();106 server.addPlayer(player1);107 assertEquals(1, server.getOnlinePlayers().size());108 server.addPlayer(player2);109 assertEquals(2, server.getOnlinePlayers().size());110 assertEquals(player1, server.getPlayer(0));111 assertEquals(player2, server.getPlayer(1));112 Set<EntityMock> entities = server.getEntities();113 assertTrue(entities.contains(player1), "Player 1 was not registered");114 assertTrue(entities.contains(player2), "Player 2 was not registered");115 }116 @Test117 void addPlayers_None_TwoUniquePlayers()118 {119 PlayerMock playerA = server.addPlayer();120 PlayerMock playerB = server.addPlayer();121 PlayerMock player1 = server.getPlayer(0);122 PlayerMock player2 = server.getPlayer(1);123 assertNotNull(player1);124 assertNotNull(player2);125 assertEquals(playerA, player1);126 assertEquals(playerB, player2);127 assertNotEquals(player1, player2);128 }129 @Test130 void addPlayer_Calls_AsyncPreLoginEvent()131 {132 PlayerMock player = server.addPlayer();133 server.getPluginManager().assertEventFired(AsyncPlayerPreLoginEvent.class);134 }135 @Test136 void addPlayer_Calls_PlayerJoinEvent()137 {138 PlayerMock player = server.addPlayer();139 server.getPluginManager().assertEventFired(PlayerJoinEvent.class);140 }141 @Test142 void addPlayer_Calls_PlayerLoginEvent()143 {144 PlayerMock player = server.addPlayer();145 server.getPluginManager().assertEventFired(PlayerLoginEvent.class);146 }147 @Test148 void setPlayers_Two_TwoUniquePlayers()149 {150 server.setPlayers(2);151 PlayerMock player1 = server.getPlayer(0);152 PlayerMock player2 = server.getPlayer(1);153 assertNotNull(player1);154 assertNotNull(player2);155 assertNotEquals(player1, player2);156 }157 @Test158 void getPlayers_Negative_ArrayIndexOutOfBoundsException()159 {160 server.setPlayers(2);161 assertThrows(IndexOutOfBoundsException.class, () -> server.getPlayer(-1));162 }163 @Test164 void getPlayers_LargerThanNumberOfPlayers_ArrayIndexOutOfBoundsException()165 {166 server.setPlayers(2);167 assertThrows(IndexOutOfBoundsException.class, () -> server.getPlayer(2));168 }169 @Test170 void getVersion_NotNull()171 {172 assertNotNull(server.getVersion());173 }174 @Test175 void getVersion_CorrectPattern()176 {177 assertTrue(server.getVersion().matches("MockBukkit \\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)"));178 }179 @Test180 void getBukkitVersion_NotNull()181 {182 assertNotNull(server.getBukkitVersion());183 }184 @Test185 void getBukkitVersion_CorrectPattern()186 {187 assertTrue(server.getBukkitVersion().matches("1\\.[0-9]+(\\.[0-9]+)?-.*SNAPSHOT.*"));188 }189 @Test190 void getMinecraftVersion_NotNull()191 {192 assertNotNull(server.getMinecraftVersion());193 }194 @Test195 void getMinecraftVersion_CorrectPattern()196 {197 assertTrue(server.getMinecraftVersion().matches("1\\.[0-9]+(\\.[0-9]+)?"));198 }199 @Test200 void getName_NotNull()201 {202 assertNotNull(server.getName());203 }204 @Test205 void getPlayers_AllSame()206 {207 server.setPlayers(2);208 PlayerMock player1 = server.getPlayer(0);209 PlayerMock player2 = server.getPlayer(1);210 Iterator<? extends Player> players = server.getOnlinePlayers().iterator();211 assertEquals(player1, players.next());212 assertEquals(player2, players.next());213 assertFalse(players.hasNext());214 }215 @Test216 void getOfflinePlayers_CorrectArraySize()217 {218 server.setPlayers(1);219 server.setOfflinePlayers(2);220 assertEquals(3, server.getOfflinePlayers().length);221 }222 @Test223 void getOfflinePlayerByUnknownId_returnsOfflinePlayerWithGivenId()224 {225 UUID id = UUID.randomUUID();226 OfflinePlayer offlinePlayer = server.getOfflinePlayer(id);227 assertThat(offlinePlayer.getUniqueId(), equalTo(id));228 }229 @ParameterizedTest230 @ValueSource(strings = { "testcommand", "tc", "othercommand" })231 void testPluginCommand(@NotNull String cmd)232 {233 MockBukkit.load(TestPlugin.class);234 assertNotNull(server.getPluginCommand(cmd));235 }236 @Test237 void getPluginCommand_Unknown_Null()238 {239 MockBukkit.load(TestPlugin.class);240 assertNull(server.getPluginCommand("notknown"));241 }242 @Test243 void executeCommand_PlayerAndTrueReturnValue_Succeeds()244 {245 server.setPlayers(1);246 TestPlugin plugin = MockBukkit.load(TestPlugin.class);247 plugin.commandReturns = true;248 Command command = server.getPluginCommand("testcommand");249 CommandResult result = server.executePlayer(command, "a", "b");250 result.assertSucceeded();251 assertEquals(server.getPlayer(0), plugin.commandSender);252 assertEquals(command, plugin.command);253 assertEquals(2, plugin.commandArguments.length);254 assertEquals("a", plugin.commandArguments[0]);255 assertEquals("b", plugin.commandArguments[1]);256 }257 @Test258 void executeCommand_ConsoleAndFalseReturnValue_Fails()259 {260 TestPlugin plugin = MockBukkit.load(TestPlugin.class);261 plugin.commandReturns = false;262 Command command = server.getPluginCommand("testcommand");263 CommandResult result = server.executeConsole(command, "a", "b");264 result.assertFailed();265 assertEquals(server.getConsoleSender(), plugin.commandSender);266 assertEquals(command, plugin.command);267 assertEquals(2, plugin.commandArguments.length);268 assertEquals("a", plugin.commandArguments[0]);269 assertEquals("b", plugin.commandArguments[1]);270 }271 @Test272 void executeCommand_CommandAsStringAndTrueReturnValue_Succeeds()273 {274 TestPlugin plugin = MockBukkit.load(TestPlugin.class);275 plugin.commandReturns = true;276 CommandResult result = server.executeConsole("testcommand");277 result.assertSucceeded();278 }279 @Test280 void getConsoleSender_NotNull()281 {282 assertNotNull(server.getConsoleSender());283 }284 @Test285 void getItemFactory_NotNull()286 {287 assertNotNull(server.getItemFactory());288 }289 @Test290 void addSimpleWorld_Name_WorldWithNameAdded()291 {292 WorldMock world = server.addSimpleWorld("MyWorld");293 assertEquals(1, server.getWorlds().size());294 assertSame(world, server.getWorlds().get(0));295 assertSame(world, server.getWorld(world.getName()));296 assertSame(world, server.getWorld(world.getUID()));297 }298 @Test299 void getScheduler_Default_NotNull()300 {301 assertNotNull(server.getScheduler());302 }303 @Test304 void broadcastMessage_TwoPlayers_BothReceivedMessage()305 {306 PlayerMock playerA = server.addPlayer();307 PlayerMock playerB = server.addPlayer();308 server.broadcastMessage("Hello world");309 playerA.assertSaid("Hello world");310 playerB.assertSaid("Hello world");311 }312 @Test313 void addRecipe_AddsRecipe_ReturnsTrue()314 {315 TestRecipe recipe1 = new TestRecipe();316 TestRecipe recipe2 = new TestRecipe();317 server.addRecipe(recipe1);318 server.addRecipe(recipe2);319 Iterator<Recipe> recipes = server.recipeIterator();320 assertSame(recipe1, recipes.next());321 assertSame(recipe2, recipes.next());322 assertFalse(recipes.hasNext());323 }324 @Test325 void clearRecipes_SomeRecipes_AllRecipesRemoved()326 {327 TestRecipe recipe = new TestRecipe();328 server.addRecipe(recipe);329 assumeTrue(server.recipeIterator().hasNext());330 server.clearRecipes();331 assertFalse(server.recipeIterator().hasNext());332 }333 @Test334 void getRecipesFor_ManyRecipes_OnlyCorrectRecipes()335 {336 TestRecipe recipe1 = new TestRecipe(new ItemStack(Material.STONE));337 TestRecipe recipe2 = new TestRecipe(new ItemStack(Material.APPLE));338 server.addRecipe(recipe1);339 server.addRecipe(recipe2);340 List<Recipe> recipes = server.getRecipesFor(new ItemStack(Material.APPLE));341 assertEquals(1, recipes.size());342 assertSame(recipe2, recipes.get(0));343 }344 @Test345 void getRecipesFor_IgnoresAmount()346 {347 TestRecipe recipe = new TestRecipe(new ItemStack(Material.IRON_NUGGET));348 server.addRecipe(recipe);349 List<Recipe> recipes = server.getRecipesFor(new ItemStack(Material.IRON_NUGGET, 1));350 List<Recipe> recipes2 = server.getRecipesFor(new ItemStack(Material.IRON_NUGGET, 10));351 assertEquals(recipes, recipes2);352 }353 @Test354 void getDataFolder_CleanEnvironment_CreatesTemporaryDataDirectory() throws IOException355 {356 TestPlugin plugin = MockBukkit.load(TestPlugin.class);357 File folder = plugin.getDataFolder();358 assertNotNull(folder);359 assertTrue(folder.isDirectory());360 File file = new File(folder, "data.txt");361 assertFalse(file.exists());362 file.createNewFile();363 assertTrue(file.exists());364 MockBukkit.unmock();365 MockBukkit.mock();366 assertFalse(file.exists());367 }368 @Test369 void createInventory_WithSize_CreatesInventory()370 {371 PlayerMock player = server.addPlayer();372 InventoryMock inventory = server.createInventory(player, 9, "title");373 assertEquals(9, inventory.getSize());374 assertSame(player, inventory.getHolder());375 }376 @Test377 void createInventory_ChestInventoryWithoutSize_CreatesInventoryWithThreeLines()378 {379 InventoryMock inventory = server.createInventory(null, InventoryType.CHEST);380 assertEquals(9 * 3, inventory.getSize());381 }382 @Test383 void performCommand_PerformsCommand()384 {385 TestPlugin plugin = MockBukkit.load(TestPlugin.class);386 plugin.commandReturns = true;387 Player player = server.addPlayer();388 assertTrue(server.dispatchCommand(player, "mockcommand argA argB"));389 assertEquals("argA", plugin.commandArguments[0]);390 assertEquals("argB", plugin.commandArguments[1]);391 assertSame(player, plugin.commandSender);392 }393 @Test394 void getEntities_NoEntities_EmptySet()395 {396 assertTrue(server.getEntities().isEmpty(), "Entities set was not empty");397 }398 @Test399 void getEntities_TwoEntitiesRegistered_SetContainsEntities()400 {401 EntityMock entity1 = new SimpleEntityMock(server);402 EntityMock entity2 = new SimpleEntityMock(server);403 server.registerEntity(entity1);404 server.registerEntity(entity2);405 Set<EntityMock> entities = server.getEntities();406 assertTrue(entities.contains(entity1), "Set did not contain first entity");407 assertTrue(entities.contains(entity2), "Set did not contain second entity");408 }409 @ParameterizedTest410 @CsvSource({411 "player, player",412 "player, PLAYER",413 "player_other, player",414 })415 void getPlayer_NameAndPlayerExists_PlayerFound(@NotNull String actual, @NotNull String expected)416 {417 PlayerMock player = new PlayerMock(server, actual);418 server.addPlayer(player);419 assertSame(player, server.getPlayer(expected));420 }421 @Test422 void getPlayer_UUIDAndPlayerExists_PlayerFound()423 {424 PlayerMock player = new PlayerMock(server, "player");425 server.addPlayer(player);426 assertSame(player, server.getPlayer(player.getUniqueId()));427 }428 @Test429 void getPlayer_PlayerNameIncorrect_PlayerNotFound()430 {431 PlayerMock player = new PlayerMock(server, "player_other");432 server.addPlayer(player);433 assertNull(server.getPlayer("other_player"));434 }435 @Test436 void getPlayer_PlayerNameCasingIncorrect_PlayerFound()437 {438 PlayerMock player = new PlayerMock(server, "player");439 server.addPlayer(player);440 assertSame(player, server.getPlayer("PLAYER"));441 }442 @Test443 void getPlayerExact_CasingMatches_PlayerFound()444 {445 PlayerMock player = new PlayerMock(server, "player");446 server.addPlayer(player);447 assertSame(player, server.getPlayerExact("player"));448 }449 @Test450 void getPlayerExact_CasingDoesNotMatch_PlayerFound()451 {452 PlayerMock player = new PlayerMock(server, "player");453 server.addPlayer(player);454 assertNotNull(server.getPlayerExact("PLAYER"));455 }456 @Test457 void getPlayerExact_PlayerNameIncorrect_PlayerNotFound()458 {459 PlayerMock player = new PlayerMock(server, "player_other");460 server.addPlayer(player);461 assertNull(server.getPlayerExact("player"));462 }463 @Test464 void getOperators_OneOperator()465 {466 PlayerMock player = new PlayerMock(server, "operator");467 server.addPlayer(player);468 player.setOp(true);469 assertTrue(server.getOperators().contains(player));470 assertEquals(1, server.getOperators().size());471 }472 @Test473 void getScoreboardManager_NotNull()474 {475 ScoreboardManager manager = server.getScoreboardManager();476 assertNotNull(manager);477 }478 @Test479 void matchPlayer_NoMatchingPlayers_EmptyList()480 {481 server.addPlayer("Player");482 List<Player> players = server.matchPlayer("Others");483 assertEquals(0, players.size(), "Player list was not empty");484 }485 @Test486 void matchPlayer_SomeMatchingPlayers_ListHasPlayer()487 {488 PlayerMock playerA = server.addPlayer("PlayerA");489 PlayerMock playerAB = server.addPlayer("PlayerAB");490 server.addPlayer("PlayerB");491 List<Player> players = server.matchPlayer("PlayerA");492 assertThat(players, containsInAnyOrder(playerA, playerAB));493 }494 @Test495 void testOfflinePlayerJoin()496 {497 OfflinePlayerMock offlinePlayer = new OfflinePlayerMock("IAmOffline");498 assertFalse(server.getOfflinePlayer(offlinePlayer.getUniqueId()) instanceof PlayerMock);499 PlayerMock onlinePlayer = offlinePlayer.join(server);500 assertTrue(offlinePlayer.isOnline());501 assertTrue(onlinePlayer.isOnline());502 // Assert that this is still the same Player (as far as name and uuid are concerned)503 assertEquals(offlinePlayer.getName(), onlinePlayer.getName());504 assertEquals(offlinePlayer.getUniqueId(), onlinePlayer.getUniqueId());505 // Assert that the PlayerMock takes priority over the OfflinePlayerMock506 assertTrue(server.getOfflinePlayer(offlinePlayer.getUniqueId()) instanceof PlayerMock);507 }508 @Test509 void testDefaultPotionEffects()510 {511 assertEquals(33, PotionEffectType.values().length);512 for (PotionEffectType type : PotionEffectType.values())513 {514 assertNotNull(type);515 }516 }517 @Test518 void testSetSpawnRadius()519 {520 server.setSpawnRadius(51);521 assertEquals(51, server.getSpawnRadius());522 }523 @Test524 void testGetEntity()525 {526 EntityMock entity = new SimpleEntityMock(server);527 UUID uuid = entity.getUniqueId();528 server.registerEntity(entity);529 assertNotNull(server.getEntity(uuid));530 }531 @Test532 void testCreateBlockData()533 {534 BlockData blockData = server.createBlockData(Material.STONE);535 assertEquals(Material.STONE, blockData.getMaterial());536 }537 @Test538 void testWarningState()539 {540 assertEquals(Warning.WarningState.DEFAULT, server.getWarningState());541 server.setWarningState(Warning.WarningState.ON);542 assertEquals(Warning.WarningState.ON, server.getWarningState());543 }544 @Test545 @SuppressWarnings("UnstableApiUsage")546 void testSendPluginMessage()547 {548 MockPlugin plugin = MockBukkit.createMockPlugin();549 server.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");550 ByteArrayDataOutput out = ByteStreams.newDataOutput();551 out.writeUTF("Forward");552 out.writeUTF("ALL");553 out.writeUTF("MockBukkit");554 server.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());555 }556 @Test557 void testGetPlayerUniqueID()558 {559 PlayerMock player = new PlayerMock(server, "player");560 server.addPlayer(player);561 UUID uuid = player.getUniqueId();562 assertEquals(uuid, server.getPlayerUniqueId(player.getName()));563 }564 @Test565 void testGetPlayerUniqueID_OfflineMode()566 {567 OfflinePlayer player = new OfflinePlayerMock("OfflinePlayer");568 assertEquals(player.getUniqueId(), server.getPlayerUniqueId(player.getName()));569 }570 @Test571 void testSetMaxPlayers()572 {573 server.setMaxPlayers(69420);574 assertEquals(69420, server.getMaxPlayers());575 }576 @Test577 void testBroadCastMessageWithComponent()578 {579 PlayerMock playerA = server.addPlayer();580 PlayerMock playerB = server.addPlayer();581 Component component = Component.text("Hello");582 server.broadcast(component);583 playerA.assertSaid(PlainTextComponentSerializer.plainText().serialize(component));584 playerB.assertSaid(PlainTextComponentSerializer.plainText().serialize(component));585 }586 @Test587 void testGetPlayerList()588 {589 PlayerMock playerA = server.addPlayer();590 PlayerMock playerB = server.addPlayer();591 assertThat(server.getPlayerList().getOnlinePlayers(), containsInAnyOrder(playerA, playerB));592 }593 @Test594 void testPlayerListDisconnectPlayer()595 {596 MockPlayerList playerList = server.getPlayerList();597 PlayerMock playerA = server.addPlayer();598 playerList.disconnectPlayer(playerA);599 assertFalse(playerList.getOnlinePlayers().contains(playerA));600 }601 @Test602 void createProfile_NameOnly()603 {604 PlayerProfileMock profile = server.createProfile("Test");605 assertEquals("Test", profile.getName());606 }607 @Test608 void createProfile_UuidOnly()609 {610 UUID uuid = UUID.fromString("b9d9f8f9-f8d9-4f9d-9f8f-9f8f8f8f8f8");611 PlayerProfileMock profile = server.createProfile(uuid);612 assertEquals(uuid, profile.getUniqueId());613 }614 @Test615 void createProfile_NameUuid()616 {617 UUID uuid = UUID.fromString("b9d9f8f9-f8d9-4f9d-9f8f-9f8f8f8f8f8");618 PlayerProfileMock profile = server.createProfile(uuid, "Test");619 assertEquals("Test", profile.getName());620 assertEquals(uuid, profile.getUniqueId());621 }622 @Test623 void createMap_IdIncrements()624 {625 WorldMock world = new WorldMock();626 assertEquals(1, server.createMap(world).getId());627 assertEquals(2, server.createMap(world).getId());628 assertEquals(3, server.createMap(world).getId());629 }630 @Test631 void getMap_ValidId_ReturnsMap()632 {633 WorldMock world = new WorldMock();634 int id = server.createMap(world).getId();635 assertNotNull(server.getMap(id));636 assertEquals(id, server.getMap(id).getId());637 }638 @Test639 void createMap_CallsMapInitEvent()640 {641 MapView mapView = server.createMap(new WorldMock());642 server.getPluginManager().assertEventFired(MapInitializeEvent.class, (e) -> e.getMap().equals(mapView));643 }644 @Test645 void getCommandTabComplete_ReturnsExpectedResults()646 {647 MockBukkit.load(TestPlugin.class);648 Player player = server.addPlayer();649 assertEquals(Arrays.asList("Tab", "Complete", "Results"), server.getCommandTabComplete(player, "mockcommand "));650 assertEquals(Arrays.asList("Other", "Results"), server.getCommandTabComplete(player, "mockcommand argA "));651 }652 @Test653 void testHasWhiteListDefault()654 {655 assertFalse(server.hasWhitelist());656 }657 @Test658 void testSetWhiteList()659 {660 server.setWhitelist(true);661 assertTrue(server.hasWhitelist());662 server.getPluginManager().assertEventFired(WhitelistToggleEvent.class, WhitelistToggleEvent::isEnabled);663 }664 @Test665 void testIsWhiteListEnforcedDefault()666 {667 assertFalse(server.isWhitelistEnforced());668 }669 @Test670 void testSetWhiteListEnforced()671 {672 server.setWhitelistEnforced(true);673 assertTrue(server.isWhitelistEnforced());674 }675 @Test676 void testReloadWhiteList()677 {678 assertDoesNotThrow(() -> server.reloadWhitelist());679 }680 @Test681 void testReloadWhiteListWithEnforcedWhiteList()682 {683 PlayerMock playerMock = server.addPlayer();684 server.setWhitelist(true);685 server.setWhitelistEnforced(true);686 server.reloadWhitelist();687 assertFalse(server.getOnlinePlayers().contains(playerMock));688 server.getPluginManager().assertEventFired(PlayerKickEvent.class);689 }690 @Test691 void tstReloadWhiteListWithNotEnforcedWhiteList()692 {693 PlayerMock playerMock = server.addPlayer();694 server.setWhitelist(true);695 server.setWhitelistEnforced(false);696 server.reloadWhitelist();697 assertTrue(server.getOnlinePlayers().contains(playerMock));698 server.getPluginManager().assertEventNotFired(PlayerKickEvent.class);699 }700 @Test701 void testReloadWhiteListWithNotEnforcedWhiteListAndPlayerIsWhitelisted()702 {703 PlayerMock playerMock = server.addPlayer();704 playerMock.setWhitelisted(true);705 server.setWhitelist(true);706 server.setWhitelistEnforced(true);707 server.reloadWhitelist();708 assertTrue(server.getOnlinePlayers().contains(playerMock));709 server.getPluginManager().assertEventNotFired(PlayerKickEvent.class);710 }711 @Test712 void testReloadWithListWithoutWhitelistEnabled()713 {714 PlayerMock playerMock = server.addPlayer();715 playerMock.setWhitelisted(true);716 server.setWhitelist(false);717 server.setWhitelistEnforced(true);718 server.reloadWhitelist();719 assertTrue(server.getOnlinePlayers().contains(playerMock));720 server.getPluginManager().assertEventNotFired(PlayerKickEvent.class);721 }722 @Test723 void testAddPlayerWithWhitelistEnabled()724 {725 server.setWhitelist(true);726 PlayerMock playerMock = new PlayerMock(server, "Player", UUID.randomUUID());727 playerMock.setWhitelisted(true);728 server.addPlayer(playerMock);729 assertTrue(server.getOnlinePlayers().contains(playerMock));730 server.getPluginManager().assertEventNotFired(PlayerKickEvent.class);731 }732 @Test733 void testAddPlayerWithWhitelistEnabledAndNotWhitelisted()734 {735 server.setWhitelist(true);736 PlayerMock player = server.addPlayer();737 assertFalse(server.getOnlinePlayers().contains(player));738 server.getPluginManager().assertEventFired(PlayerConnectionCloseEvent.class);739 }740 @Test741 void testGetBannedPlayersDefault()742 {743 assertEquals(0, server.getBannedPlayers().size());744 }745 @Test746 void testGetBannedPlayers()747 {748 PlayerMock player = server.addPlayer();749 player.banPlayer("test");750 assertEquals(1, server.getBannedPlayers().size());751 assertTrue(server.getBannedPlayers().contains(player));752 }753 @Test754 void getPermissionMessage_NotNull()755 {756 assertNotNull(server.getPermissionMessage());757 }758 @Test759 void permissionMessage_NotNull()760 {761 assertNotNull(server.permissionMessage());762 }763 @Test764 void loadServerIcon_NullFile_ThrowsException()765 {766 assertThrows(NullPointerException.class, () -> server.loadServerIcon((File) null));767 }768 @Test769 void loadServerIcon_NullImage_ThrowsException()770 {771 assertThrows(NullPointerException.class, () -> server.loadServerIcon((BufferedImage) null));772 }773 @Test774 void loadServerIcon_WrongWidth_ThrowsException()775 {776 BufferedImage image63 = new BufferedImage(63, 64, BufferedImage.TYPE_INT_RGB);777 BufferedImage image65 = new BufferedImage(65, 64, BufferedImage.TYPE_INT_RGB);778 assertThrows(IllegalArgumentException.class, () -> server.loadServerIcon(image63));779 assertThrows(IllegalArgumentException.class, () -> server.loadServerIcon(image65));780 }781 @Test782 void loadServerIcon_WrongHeight_ThrowsException()783 {784 BufferedImage image63 = new BufferedImage(64, 63, BufferedImage.TYPE_INT_RGB);785 BufferedImage image65 = new BufferedImage(64, 65, BufferedImage.TYPE_INT_RGB);786 assertThrows(IllegalArgumentException.class, () -> server.loadServerIcon(image63));787 assertThrows(IllegalArgumentException.class, () -> server.loadServerIcon(image65));788 }789 @Test790 void loadServerIcon_CorrectSize()791 {792 BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);793 assertDoesNotThrow(() -> server.loadServerIcon(image));794 }795 @Test796 void loadServerIcon_CorrectData() throws IOException797 {798 BufferedImage image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);799 Graphics2D g = image.createGraphics();800 g.drawOval(0, 0, 64, 64);801 g.dispose();802 CachedServerIconMock icon = server.loadServerIcon(image);803 byte[] decodedBase64 = Base64.getDecoder().decode(icon.getData().replace(CachedServerIconMock.PNG_BASE64_PREFIX, ""));804 BufferedImage decodedImage = ImageIO.read(new ByteArrayInputStream(decodedBase64));805 for (int x = 0; x < 64; x++)806 {807 for (int y = 0; y < 64; y++)808 {809 assertEquals(image.getRGB(x, y), decodedImage.getRGB(x, y));810 }811 }812 }813}814class TestRecipe implements Recipe815{816 private final @NotNull ItemStack result;817 public TestRecipe(@NotNull ItemStack result)818 {819 this.result = result;820 }821 public TestRecipe()822 {823 this(null);824 }825 @Override826 public @NotNull ItemStack getResult()827 {828 return result;829 }830}...
Source:PlayerProfileMock.java
...122 // TODO Auto-generated method stub123 throw new UnimplementedOperationException();124 }125 @Override126 public boolean completeFromCache()127 {128 // TODO Auto-generated method stub129 throw new UnimplementedOperationException();130 }131 @Override132 public boolean completeFromCache(boolean onlineMode)133 {134 // TODO Auto-generated method stub135 throw new UnimplementedOperationException();136 }137 @Override138 public boolean completeFromCache(boolean lookupUUID, boolean onlineMode)139 {140 // TODO Auto-generated method stub141 throw new UnimplementedOperationException();142 }143 @Override144 public boolean complete(boolean textures)145 {146 // TODO Auto-generated method stub147 throw new UnimplementedOperationException();148 }149 @Override150 public boolean complete(boolean textures, boolean onlineMode)151 {152 // TODO Auto-generated method stub153 throw new UnimplementedOperationException();154 }155 @Override156 public @NotNull Map<String, Object> serialize()157 {158 Map<String, Object> map = new LinkedHashMap<>();159 if (this.getId() != null)160 {161 map.put("uniqueId", this.getId().toString());162 }163 if (this.getName() != null)164 {...
complete
Using AI Code Generation
1PlayerProfileMock playerProfileMock = new PlayerProfileMock();2playerProfileMock.complete();3PlayerProfileMock playerProfileMock = new PlayerProfileMock();4playerProfileMock.complete();5PlayerProfileMock playerProfileMock = new PlayerProfileMock();6playerProfileMock.complete();7PlayerProfileMock playerProfileMock = new PlayerProfileMock();8playerProfileMock.complete();9PlayerProfileMock playerProfileMock = new PlayerProfileMock();10playerProfileMock.complete();11PlayerProfileMock playerProfileMock = new PlayerProfileMock();12playerProfileMock.complete();13PlayerProfileMock playerProfileMock = new PlayerProfileMock();14playerProfileMock.complete();15PlayerProfileMock playerProfileMock = new PlayerProfileMock();16playerProfileMock.complete();17PlayerProfileMock playerProfileMock = new PlayerProfileMock();18playerProfileMock.complete();19PlayerProfileMock playerProfileMock = new PlayerProfileMock();20playerProfileMock.complete();21PlayerProfileMock playerProfileMock = new PlayerProfileMock();22playerProfileMock.complete();23PlayerProfileMock playerProfileMock = new PlayerProfileMock();24playerProfileMock.complete();25PlayerProfileMock playerProfileMock = new PlayerProfileMock();26playerProfileMock.complete();
complete
Using AI Code Generation
1PlayerProfileMock playerProfileMock = new PlayerProfileMock();2playerProfileMock.complete();3PlayerProfileMock playerProfileMock = new PlayerProfileMock();4playerProfileMock.complete();5PlayerProfileMock playerProfileMock = new PlayerProfileMock();6playerProfileMock.complete();7PlayerProfileMock playerProfileMock = new PlayerProfileMock();8playerProfileMock.complete();9PlayerProfileMock playerProfileMock = new PlayerProfileMock();10playerProfileMock.complete();11PlayerProfileMock playerProfileMock = new PlayerProfileMock();12playerProfileMock.complete();13PlayerProfileMock playerProfileMock = new PlayerProfileMock();14playerProfileMock.complete();15PlayerProfileMock playerProfileMock = new PlayerProfileMock();16playerProfileMock.complete();17PlayerProfileMock playerProfileMock = new PlayerProfileMock();18playerProfileMock.complete();19PlayerProfileMock playerProfileMock = new PlayerProfileMock();20playerProfileMock.complete();21PlayerProfileMock playerProfileMock = new PlayerProfileMock();22playerProfileMock.complete();23PlayerProfileMock playerProfileMock = new PlayerProfileMock();24playerProfileMock.complete();
complete
Using AI Code Generation
1import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;2import be.seeseemelk.mockbukkit.profile.PlayerProfileMockFactory;3import java.util.UUID;4public class Main {5 public static void main(String[] args) {6 PlayerProfileMockFactory factory = new PlayerProfileMockFactory();7 PlayerProfileMock profile = factory.createProfile(UUID.randomUUID());8 profile.complete();9 System.out.println(profile.getName());10 }11}
complete
Using AI Code Generation
1PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());2profile.complete(true);3Player player = server.addPlayer(profile);4PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());5profile.complete(false);6Player player = server.addPlayer(profile);7PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());8profile.complete(true);9Player player = server.addPlayer(profile);10PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());11profile.complete(false);12Player player = server.addPlayer(profile);13PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());14profile.complete(true);15Player player = server.addPlayer(profile);16PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());17profile.complete(false);18Player player = server.addPlayer(profile);19PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());20profile.complete(true);21Player player = server.addPlayer(profile);22PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());23profile.complete(false);24Player player = server.addPlayer(profile);25PlayerProfileMock profile = new PlayerProfileMock("ExamplePlayer", UUID.randomUUID());26profile.complete(true);27Player player = server.addPlayer(profile);
complete
Using AI Code Generation
1import be.seeseemelk.mockbukkit.MockBukkit;2import be.seeseemelk.mockbukkit.ServerMock;3import be.seeseemelk.mockbukkit.entity.PlayerMock;4import be.seeseemelk.mockbukkit.inventory.InventoryMock;5import be.seeseemelk.mockbukkit.inventory.PlayerInventoryMock;6import be.seeseemelk.mockbukkit.profile.PlayerProfileMock;7import org.bukkit.Bukkit;8import org.bukkit.entity.Player;9import org.bukkit.inventory.Inventory;10import org.bukkit.inventory.ItemStack;11import org.bukkit.inventory.PlayerInventory;12public class Main {13 public static void main(String[] args) {14 ServerMock server = MockBukkit.mock();15 PlayerProfileMock playerProfile = new PlayerProfileMock();16 playerProfile.complete("LoneDev");17 PlayerMock player = new PlayerMock(playerProfile, server);18 PlayerInventoryMock playerInventory = new PlayerInventoryMock(player);19 playerInventory.addItem(new ItemStack(1, 1));20 ItemStack item = playerInventory.getItem(0);21 System.out.println(item);22 Inventory inventory = player.getInventory();23 System.out.println(inventory);24 PlayerInventory playerInventory1 = player.getInventory();25 System.out.println(playerInventory1);26 MockBukkit.unmock();27 }28}29import be.seeseemelk.mockbukkit.Mock
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!