Work on the tests, they no longer fail and we mock a lot more now.

This commit is contained in:
graywolf336 2013-12-05 19:15:32 -06:00
parent 596c9de2ad
commit d66b9d3447
4 changed files with 560 additions and 546 deletions

1
.gitignore vendored
View File

@ -40,4 +40,5 @@ target/
.settings/ .settings/
.classpath .classpath
.project .project
config.yml
src/com/matejdro/ src/com/matejdro/

View File

@ -17,9 +17,9 @@
<system>Dev Bukkit</system> <system>Dev Bukkit</system>
</issueManagement> </issueManagement>
<scm> <scm>
<url>https://github.com/multidude/Jail</url> <url>https://github.com/graywolf336/Jail</url>
<connection>scm:git:git://github.com/multidude/Jail.git</connection> <connection>scm:git:git://github.com/graywolf336/Jail.git</connection>
<developerConnection>scm:git:git:@github.com/multidude/Jail.git</developerConnection> <developerConnection>scm:git:git:@github.com/graywolf336/Jail.git</developerConnection>
</scm> </scm>
<repositories> <repositories>

View File

@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLogger;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
@ -50,19 +51,39 @@ public class TestInstanceCreator {
MockGateway.MOCK_STANDARD_METHODS = false; MockGateway.MOCK_STANDARD_METHODS = false;
// Initialize the Mock server.
mockServer = mock(Server.class);
when(mockServer.getName()).thenReturn("TestBukkit");
when(mockServer.getVersion()).thenReturn("Jail-Testing-0.0.1");
when(mockServer.getBukkitVersion()).thenReturn("0.0.1");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
main = PowerMockito.spy(new JailMain()); main = PowerMockito.spy(new JailMain());
doReturn(pluginDirectory).when(main).getDataFolder();
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain")); PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain"));
when(pdf.getPrefix()).thenReturn("Jail");
List<String> authors = new ArrayList<String>(); List<String> authors = new ArrayList<String>();
authors.add("matejdro"); authors.add("matejdro");
authors.add("multidude"); authors.add("multidude");
authors.add("graywolf336"); authors.add("graywolf336");
when(pdf.getAuthors()).thenReturn(authors); doReturn(authors).when(pdf).getAuthors();
doReturn(pdf).when(main).getDescription(); doReturn(pdf).when(main).getDescription();
doReturn(true).when(main).isEnabled(); doReturn(true).when(main).isEnabled();
doReturn(Util.logger).when(main).getLogger(); doReturn(Util.logger).when(main).getLogger();
doReturn(mockServer).when(main).getServer();
doReturn(pluginDirectory).when(main).getDataFolder();
Field configFile = JavaPlugin.class.getDeclaredField("configFile");
configFile.setAccessible(true);
configFile.set(main, new File(pluginDirectory, "config.yml"));
Field logger = JavaPlugin.class.getDeclaredField("logger");
logger.setAccessible(true);
logger.set(main, new PluginLogger(main));
doReturn(getClass().getClassLoader().getResourceAsStream("config.yml")).when(main).getResource("config.yml");
// Add Jail to the list of loaded plugins // Add Jail to the list of loaded plugins
JavaPlugin[] plugins = new JavaPlugin[] { main }; JavaPlugin[] plugins = new JavaPlugin[] { main };
@ -73,15 +94,6 @@ public class TestInstanceCreator {
when(mockPluginManager.getPlugin("Jail")).thenReturn(main); when(mockPluginManager.getPlugin("Jail")).thenReturn(main);
when(mockPluginManager.getPermission(anyString())).thenReturn(null); when(mockPluginManager.getPermission(anyString())).thenReturn(null);
// Initialize the Mock server.
mockServer = mock(Server.class);
when(mockServer.getName()).thenReturn("TestBukkit");
when(mockServer.getVersion()).thenReturn("Jail-Testing-0.0.1");
when(mockServer.getBukkitVersion()).thenReturn("0.0.1");
Logger.getLogger("Minecraft").setParent(Util.logger);
when(mockServer.getLogger()).thenReturn(Util.logger);
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
// Give the server some worlds // Give the server some worlds
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() { when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
public World answer(InvocationOnMock invocation) throws Throwable { public World answer(InvocationOnMock invocation) throws Throwable {
@ -238,6 +250,7 @@ public class TestInstanceCreator {
main.onDisable(); main.onDisable();
deleteFolder(serverDirectory); deleteFolder(serverDirectory);
return true; return true;