Update tests

This commit is contained in:
tastybento 2023-11-18 14:44:49 -08:00
parent 3a3c8a320c
commit 1a4077be8c
1 changed files with 198 additions and 201 deletions

View File

@ -72,7 +72,7 @@ import world.bentobox.level.listeners.JoinLeaveListener;
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class}) @PrepareForTest({ Bukkit.class, BentoBox.class, User.class })
public class LevelTest { public class LevelTest {
private static File jFile; private static File jFile;
@ -128,13 +128,13 @@ public class LevelTest {
path = Paths.get("blockconfig.yml"); path = Paths.get("blockconfig.yml");
Files.copy(fromPath, path); Files.copy(fromPath, path);
try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) { try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
//Added the new files to the jar. // Added the new files to the jar.
try (FileInputStream fis = new FileInputStream(path.toFile())) { try (FileInputStream fis = new FileInputStream(path.toFile())) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int bytesRead = 0; int bytesRead = 0;
JarEntry entry = new JarEntry(path.toString()); JarEntry entry = new JarEntry(path.toString());
tempJarOutputStream.putNextEntry(entry); tempJarOutputStream.putNextEntry(entry);
while((bytesRead = fis.read(buffer)) != -1) { while ((bytesRead = fis.read(buffer)) != -1) {
tempJarOutputStream.write(buffer, 0, bytesRead); tempJarOutputStream.write(buffer, 0, bytesRead);
} }
} }
@ -155,7 +155,7 @@ public class LevelTest {
when(plugin.getSettings()).thenReturn(pluginSettings); when(plugin.getSettings()).thenReturn(pluginSettings);
when(pluginSettings.getDatabaseType()).thenReturn(value); when(pluginSettings.getDatabaseType()).thenReturn(value);
//when(plugin.isEnabled()).thenReturn(true); // when(plugin.isEnabled()).thenReturn(true);
// Command manager // Command manager
CommandsManager cm = mock(CommandsManager.class); CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm); when(plugin.getCommandsManager()).thenReturn(cm);
@ -174,15 +174,14 @@ public class LevelTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im); when(plugin.getIslands()).thenReturn(im);
// Locales // Locales
// Return the reference (USE THIS IN THE FUTURE) // Return the reference (USE THIS IN THE FUTURE)
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class)); when(user.getTranslation(Mockito.anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Server // Server
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
@ -196,14 +195,16 @@ public class LevelTest {
File dataFolder = new File("addons/Level"); File dataFolder = new File("addons/Level");
addon.setDataFolder(dataFolder); addon.setDataFolder(dataFolder);
addon.setFile(jFile); addon.setFile(jFile);
AddonDescription desc = new AddonDescription.Builder("bentobox", "Level", "1.3").description("test").authors("tastybento").build(); AddonDescription desc = new AddonDescription.Builder("bentobox", "Level", "1.3").description("test")
.authors("tastybento").build();
addon.setDescription(desc); addon.setDescription(desc);
addon.setSettings(new ConfigSettings()); addon.setSettings(new ConfigSettings());
// Addons manager // Addons manager
when(plugin.getAddonsManager()).thenReturn(am); when(plugin.getAddonsManager()).thenReturn(am);
// One game mode // One game mode
when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode)); when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode));
AddonDescription desc2 = new AddonDescription.Builder("bentobox", "BSkyBlock", "1.3").description("test").authors("tasty").build(); AddonDescription desc2 = new AddonDescription.Builder("bentobox", "BSkyBlock", "1.3").description("test")
.authors("tasty").build();
when(gameMode.getDescription()).thenReturn(desc2); when(gameMode.getDescription()).thenReturn(desc2);
when(gameMode.getOverWorld()).thenReturn(world); when(gameMode.getOverWorld()).thenReturn(world);
@ -219,7 +220,6 @@ public class LevelTest {
when(plugin.getFlagsManager()).thenReturn(fm); when(plugin.getFlagsManager()).thenReturn(fm);
when(fm.getFlags()).thenReturn(Collections.emptyList()); when(fm.getFlags()).thenReturn(Collections.emptyList());
// Bukkit // Bukkit
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(scheduler); when(Bukkit.getScheduler()).thenReturn(scheduler);
@ -260,10 +260,7 @@ public class LevelTest {
private static void deleteAll(File file) throws IOException { private static void deleteAll(File file) throws IOException {
if (file.exists()) { if (file.exists()) {
Files.walk(file.toPath()) Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} }
} }
@ -276,7 +273,7 @@ public class LevelTest {
verify(plugin).logWarning("[Level] Level Addon: No such world in blockconfig.yml : acidisland_world"); verify(plugin).logWarning("[Level] Level Addon: No such world in blockconfig.yml : acidisland_world");
verify(plugin).log("[Level] Level hooking into BSkyBlock"); verify(plugin).log("[Level] Level hooking into BSkyBlock");
verify(cmd, times(3)).getAddon(); // 3 commands verify(cmd, times(3)).getAddon(); // 3 commands
verify(adminCmd, times(4)).getAddon(); // Four commands verify(adminCmd, times(5)).getAddon(); // Five commands
// Placeholders // Placeholders
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_island_level"), any()); verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_island_level"), any());
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_visited_island_level"), any()); verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_visited_island_level"), any());