mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-07 12:48:03 +02:00
Add tests for PluginHooks - Multiverse interactions
This commit is contained in:
parent
e8717ba076
commit
1f2a823f99
@ -2,8 +2,13 @@ package fr.xephi.authme.hooks;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -20,6 +25,7 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@ -27,6 +33,11 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class PluginHooksTest {
|
||||
|
||||
/** The plugin name of Essentials. */
|
||||
private static final String ESSENTIALS = "Essentials";
|
||||
/** The plugin name of Multiverse-Core. */
|
||||
private static final String MULTIVERSE = "Multiverse-Core";
|
||||
|
||||
@BeforeClass
|
||||
public static void setLogger() {
|
||||
TestHelper.setupLogger();
|
||||
@ -37,7 +48,7 @@ public class PluginHooksTest {
|
||||
// given
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
setPluginAvailable(pluginManager, "Essentials", Essentials.class);
|
||||
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
|
||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
||||
|
||||
// when
|
||||
@ -53,7 +64,7 @@ public class PluginHooksTest {
|
||||
public void shouldHookIntoEssentialsAtInitialization() {
|
||||
// given
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, "Essentials", Essentials.class);
|
||||
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
|
||||
|
||||
// when
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
@ -62,6 +73,19 @@ public class PluginHooksTest {
|
||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHookIntoMultiverseAtInitialization() {
|
||||
// given
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
|
||||
|
||||
// when
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// then
|
||||
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEssentialsDataFolder() {
|
||||
// given
|
||||
@ -71,7 +95,7 @@ public class PluginHooksTest {
|
||||
ReflectionTestUtils.setField(JavaPlugin.class, ess, "dataFolder", essDataFolder);
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, "Essentials", ess);
|
||||
setPluginAvailable(pluginManager, ESSENTIALS, ess);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// when
|
||||
@ -104,7 +128,7 @@ public class PluginHooksTest {
|
||||
given(ess.getUser(player)).willReturn(user);
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, "Essentials", ess);
|
||||
setPluginAvailable(pluginManager, ESSENTIALS, ess);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// when
|
||||
@ -125,17 +149,20 @@ public class PluginHooksTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUnhookEssentials() {
|
||||
public void shouldUnhookEssentialsAndMultiverse() {
|
||||
// given
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, "Essentials", Essentials.class);
|
||||
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
|
||||
setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// when
|
||||
pluginHooks.unhookEssentials();
|
||||
pluginHooks.unhookMultiverse();
|
||||
|
||||
// then
|
||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
||||
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -154,6 +181,70 @@ public class PluginHooksTest {
|
||||
assertThat(pluginHooks.isCombatTagPlusAvailable(), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForUnavailableMultiverse() {
|
||||
// given
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
World world = mock(World.class);
|
||||
|
||||
// when
|
||||
Location result = pluginHooks.getMultiverseSpawn(world);
|
||||
|
||||
// then
|
||||
assertThat(result, nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetMultiverseSpawn() {
|
||||
// given
|
||||
Location location = mock(Location.class);
|
||||
MultiverseWorld multiverseWorld = mock(MultiverseWorld.class);
|
||||
given(multiverseWorld.getSpawnLocation()).willReturn(location);
|
||||
|
||||
World world = mock(World.class);
|
||||
MVWorldManager mvWorldManager = mock(MVWorldManager.class);
|
||||
given(mvWorldManager.isMVWorld(world)).willReturn(true);
|
||||
given(mvWorldManager.getMVWorld(world)).willReturn(multiverseWorld);
|
||||
MultiverseCore multiverse = mock(MultiverseCore.class);
|
||||
given(multiverse.getMVWorldManager()).willReturn(mvWorldManager);
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
setPluginAvailable(pluginManager, MULTIVERSE, multiverse);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// when
|
||||
Location spawn = pluginHooks.getMultiverseSpawn(world);
|
||||
|
||||
// then
|
||||
assertThat(spawn, equalTo(location));
|
||||
verify(mvWorldManager).isMVWorld(world);
|
||||
verify(mvWorldManager).getMVWorld(world);
|
||||
verify(multiverseWorld).getSpawnLocation();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForNonMvWorld() {
|
||||
// given
|
||||
World world = mock(World.class);
|
||||
MVWorldManager mvWorldManager = mock(MVWorldManager.class);
|
||||
given(mvWorldManager.isMVWorld(world)).willReturn(false);
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
MultiverseCore multiverse = mock(MultiverseCore.class);
|
||||
setPluginAvailable(pluginManager, MULTIVERSE, multiverse);
|
||||
given(multiverse.getMVWorldManager()).willReturn(mvWorldManager);
|
||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||
|
||||
// when
|
||||
Location spawn = pluginHooks.getMultiverseSpawn(world);
|
||||
|
||||
// then
|
||||
assertThat(spawn, nullValue());
|
||||
verify(mvWorldManager).isMVWorld(world);
|
||||
verify(mvWorldManager, never()).getMVWorld(world);
|
||||
}
|
||||
|
||||
private static void setPluginAvailable(PluginManager managerMock, String pluginName,
|
||||
Class<? extends Plugin> pluginClass) {
|
||||
setPluginAvailable(managerMock, pluginName, mock(pluginClass));
|
||||
|
Loading…
Reference in New Issue
Block a user