Fix codestyle, add test

This commit is contained in:
Gabriele C 2017-11-29 08:38:34 +01:00
parent c7c8e673f0
commit 610fed3c7b
5 changed files with 26 additions and 10 deletions

View File

@ -41,7 +41,7 @@ public class ServerListener implements Listener {
pluginHookService.unhookEssentials();
ConsoleLogger.info("Essentials has been disabled: unhooking");
} else if ("CMI".equalsIgnoreCase(pluginName)) {
pluginHookService.unhookCMI();
pluginHookService.unhookCmi();
spawnLoader.unloadCMISpawn();
ConsoleLogger.info("CMI has been disabled: unhooking");
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
@ -75,7 +75,7 @@ public class ServerListener implements Listener {
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
spawnLoader.loadEssentialsSpawn();
} else if ("CMI".equalsIgnoreCase(pluginName)) {
pluginHookService.tryHookToCMI();
pluginHookService.tryHookToCmi();
spawnLoader.loadCMISpawn();
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
protocolLibService.setup();

View File

@ -34,7 +34,7 @@ public class PluginHookService {
public PluginHookService(PluginManager pluginManager) {
this.pluginManager = pluginManager;
tryHookToEssentials();
tryHookToCMI();
tryHookToCmi();
tryHookToMultiverse();
}
@ -67,7 +67,7 @@ public class PluginHookService {
*
* @return The CMI data folder, or null if unavailable
*/
public File getCMIDataFolder() {
public File getCmiDataFolder() {
Plugin plugin = pluginManager.getPlugin("CMI");
if(plugin == null) {
return null;
@ -105,7 +105,7 @@ public class PluginHookService {
/**
* @return true if we have a hook to CMI, false otherwise
*/
public boolean isCMIAvailable() {
public boolean isCmiAvailable() {
return cmi != null;
}
@ -134,7 +134,7 @@ public class PluginHookService {
/**
* Attempts to create a hook into CMI.
*/
public void tryHookToCMI() {
public void tryHookToCmi() {
try {
cmi = getPlugin(pluginManager, "CMI", Plugin.class);
} catch (Exception | NoClassDefFoundError ignored) {
@ -167,7 +167,7 @@ public class PluginHookService {
/**
* Unhooks from CMI.
*/
public void unhookCMI() {
public void unhookCmi() {
cmi = null;
}

View File

@ -135,7 +135,7 @@ public class SpawnLoader implements Reloadable {
* Load the spawn point defined in CMI.
*/
public void loadCMISpawn() {
File cmiFolder = pluginHookService.getCMIDataFolder();
File cmiFolder = pluginHookService.getCmiDataFolder();
if (cmiFolder == null) {
return;
}

View File

@ -60,7 +60,7 @@ public class ServerListenerTest {
checkEnableHandling(ESSENTIALS, () -> verify(pluginHookService).tryHookToEssentials());
checkEnableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).loadEssentialsSpawn());
checkEnableHandling(CMI, () -> {
verify(pluginHookService).tryHookToCMI();
verify(pluginHookService).tryHookToCmi();
verify(spawnLoader).loadCMISpawn();
});
checkEnableHandling(MULTIVERSE, () -> verify(pluginHookService).tryHookToMultiverse());
@ -73,7 +73,7 @@ public class ServerListenerTest {
checkDisableHandling(ESSENTIALS, () -> verify(pluginHookService).unhookEssentials());
checkDisableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).unloadEssentialsSpawn());
checkDisableHandling(CMI, () -> {
verify(pluginHookService).unhookCMI();
verify(pluginHookService).unhookCmi();
verify(spawnLoader).unloadCMISpawn();
});
checkDisableHandling(MULTIVERSE, () -> verify(pluginHookService).unhookMultiverse());

View File

@ -35,6 +35,8 @@ public class PluginHookServiceTest {
/** The plugin name of Essentials. */
private static final String ESSENTIALS = "Essentials";
/** The plugin name of CMI. */
private static final String CMI = "CMI";
/** The plugin name of Multiverse-Core. */
private static final String MULTIVERSE = "Multiverse-Core";
@ -71,6 +73,19 @@ public class PluginHookServiceTest {
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
}
@Test
public void shouldHookIntoCmiAtInitialization() {
// given
PluginManager pluginManager = mock(PluginManager.class);
setPluginAvailable(pluginManager, CMI, Plugin.class);
// when
PluginHookService pluginHookService = new PluginHookService(pluginManager);
// then
assertThat(pluginHookService.isCmiAvailable(), equalTo(true));
}
@Test
public void shouldHookIntoMultiverseAtInitialization() {
// given
@ -175,6 +190,7 @@ public class PluginHookServiceTest {
// then
assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
assertThat(pluginHookService.isCmiAvailable(), equalTo(false));
assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
}