mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01: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.Essentials;
|
||||||
import com.earth2me.essentials.User;
|
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.ReflectionTestUtils;
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
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.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,6 +33,11 @@ import static org.mockito.Mockito.verify;
|
|||||||
*/
|
*/
|
||||||
public class PluginHooksTest {
|
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
|
@BeforeClass
|
||||||
public static void setLogger() {
|
public static void setLogger() {
|
||||||
TestHelper.setupLogger();
|
TestHelper.setupLogger();
|
||||||
@ -37,7 +48,7 @@ public class PluginHooksTest {
|
|||||||
// given
|
// given
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||||
setPluginAvailable(pluginManager, "Essentials", Essentials.class);
|
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
|
||||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -53,7 +64,7 @@ public class PluginHooksTest {
|
|||||||
public void shouldHookIntoEssentialsAtInitialization() {
|
public void shouldHookIntoEssentialsAtInitialization() {
|
||||||
// given
|
// given
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
setPluginAvailable(pluginManager, "Essentials", Essentials.class);
|
setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||||
@ -62,6 +73,19 @@ public class PluginHooksTest {
|
|||||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true));
|
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
|
@Test
|
||||||
public void shouldReturnEssentialsDataFolder() {
|
public void shouldReturnEssentialsDataFolder() {
|
||||||
// given
|
// given
|
||||||
@ -71,7 +95,7 @@ public class PluginHooksTest {
|
|||||||
ReflectionTestUtils.setField(JavaPlugin.class, ess, "dataFolder", essDataFolder);
|
ReflectionTestUtils.setField(JavaPlugin.class, ess, "dataFolder", essDataFolder);
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
setPluginAvailable(pluginManager, "Essentials", ess);
|
setPluginAvailable(pluginManager, ESSENTIALS, ess);
|
||||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -104,7 +128,7 @@ public class PluginHooksTest {
|
|||||||
given(ess.getUser(player)).willReturn(user);
|
given(ess.getUser(player)).willReturn(user);
|
||||||
|
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
PluginManager pluginManager = mock(PluginManager.class);
|
||||||
setPluginAvailable(pluginManager, "Essentials", ess);
|
setPluginAvailable(pluginManager, ESSENTIALS, ess);
|
||||||
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -125,17 +149,20 @@ public class PluginHooksTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldUnhookEssentials() {
|
public void shouldUnhookEssentialsAndMultiverse() {
|
||||||
// given
|
// given
|
||||||
PluginManager pluginManager = mock(PluginManager.class);
|
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);
|
PluginHooks pluginHooks = new PluginHooks(pluginManager);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
pluginHooks.unhookEssentials();
|
pluginHooks.unhookEssentials();
|
||||||
|
pluginHooks.unhookMultiverse();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false));
|
||||||
|
assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -154,6 +181,70 @@ public class PluginHooksTest {
|
|||||||
assertThat(pluginHooks.isCombatTagPlusAvailable(), equalTo(false));
|
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,
|
private static void setPluginAvailable(PluginManager managerMock, String pluginName,
|
||||||
Class<? extends Plugin> pluginClass) {
|
Class<? extends Plugin> pluginClass) {
|
||||||
setPluginAvailable(managerMock, pluginName, mock(pluginClass));
|
setPluginAvailable(managerMock, pluginName, mock(pluginClass));
|
||||||
|
Loading…
Reference in New Issue
Block a user