Skip to content
Permalink
Browse files

ConfigTest with Mockito.

  • Loading branch information...
bmhm committed Apr 8, 2016
1 parent a17cd9d commit 03aff107a778d3d5ea64da86f51c25433a0977db
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/test/java/de/bmarwell/bukkit/test/ConfigTest.java
@@ -0,0 +1,43 @@
package de.bmarwell.bukkit.test;

import de.bmarwell.bukkit.ExamplePlugin;
import de.bmarwell.bukkit.ExamplePluginConfig;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Logger;

public class ConfigTest {

private static final Logger LOG = Logger.getLogger("ConfigTest");

private ExamplePluginConfig epc;

@Before
public void setUp() throws FileNotFoundException, IOException, InvalidConfigurationException {
ExamplePlugin exPl = Mockito.mock(ExamplePlugin.class);

File configfile = new File(getClass().getResource("/config.yml").getPath());
LOG.info("Using config file [" + configfile.getAbsolutePath() + "].");
YamlConfiguration configuration = new YamlConfiguration();
configuration.load(configfile.getAbsolutePath());
Mockito.doReturn(configuration).when(exPl).getConfig();
this.epc = new ExamplePluginConfig(exPl);
}

@Test
public void testCreateConfig() {
Assert.assertTrue(epc.getTeleportCauseToCancel().isPresent());
Assert.assertEquals(TeleportCause.ENDER_PEARL, epc.getTeleportCauseToCancel().get());
}

}

0 comments on commit 03aff10

Please sign in to comment.
You can’t perform that action at this time.