Search in sources :

Example 1 with NucleusPlugin

use of io.github.nucleuspowered.nucleus.NucleusPlugin in project Nucleus by NucleusPowered.

the class TestModule method configure.

@Override
protected void configure() {
    Path test;
    Path test2;
    try {
        test = Files.createTempDirectory("quick");
        test2 = Files.createTempFile(test, "quick", "conf");
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    this.bind(Path.class).annotatedWith(DefaultConfig.class).toInstance(test2);
    this.bind(Path.class).annotatedWith(ConfigDir.class).toInstance(test);
    this.bind(Game.class).toInstance(Mockito.mock(Game.class));
    this.bind(Logger.class).toInstance(Mockito.mock(Logger.class));
    CoreConfigAdapter mock = Mockito.mock(CoreConfigAdapter.class);
    PowerMockito.replace(PowerMockito.method(CoreConfigAdapter.class, "getNode")).with((obj, method, arguments) -> new CoreConfig());
    this.bind(CoreConfigAdapter.class).toInstance(mock);
    try {
        NucleusPlugin plugin = getMockPlugin();
        this.bind(NucleusPlugin.class).toInstance(plugin);
        this.bind(UserDataManager.class).toInstance(plugin.getUserDataManager());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) Game(org.spongepowered.api.Game) ConfigDir(org.spongepowered.api.config.ConfigDir) CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) DefaultConfig(org.spongepowered.api.config.DefaultConfig) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) IOException(java.io.IOException) Logger(org.slf4j.Logger) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) IOException(java.io.IOException)

Example 2 with NucleusPlugin

use of io.github.nucleuspowered.nucleus.NucleusPlugin in project Nucleus by NucleusPowered.

the class TestModule method getMockPlugin.

private NucleusPlugin getMockPlugin() {
    NucleusPlugin plugin = Mockito.mock(NucleusPlugin.class);
    PermissionRegistry pr = new PermissionRegistry();
    Mockito.when(plugin.getMessageProvider()).thenReturn(new ResourceMessageProvider(ResourceMessageProvider.messagesBundle));
    Mockito.when(plugin.getPermissionRegistry()).thenReturn(pr);
    Mockito.when(plugin.getUserDataManager()).thenReturn(Mockito.mock(UserDataManager.class));
    /*
        Field f = Nucleus.class.getDeclaredField("nucleus");
        f.setAccessible(true);
        f.set(null, plugin);
*/
    try {
        Path file = Files.createTempFile("quickstartcmdtest", "conf");
        CommandsConfig cc = new CommandsConfig(file);
        Mockito.when(plugin.getCommandsConfig()).thenReturn(cc);
        return plugin;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) CommandsConfig(io.github.nucleuspowered.nucleus.config.CommandsConfig) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) IOException(java.io.IOException) ResourceMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider)

Example 3 with NucleusPlugin

use of io.github.nucleuspowered.nucleus.NucleusPlugin in project Nucleus by NucleusPowered.

the class ChatUtilTests method setup.

@BeforeClass
public static void setup() throws Exception {
    TestBase.testSetup();
    NucleusPlugin plugin = Guice.createInjector(new TestModule()).getInstance(NucleusPlugin.class);
    Field parserToTest = TextParsingUtils.class.getDeclaredField("urlParser");
    parserToTest.setAccessible(true);
    patternToTest = (Pattern) parserToTest.get(new TextParsingUtils(plugin));
}
Also used : Field(java.lang.reflect.Field) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) TestModule(io.github.nucleuspowered.nucleus.tests.util.TestModule) TextParsingUtils(io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils) BeforeClass(org.junit.BeforeClass)

Aggregations

NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)3 UserDataManager (io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 CommandsConfig (io.github.nucleuspowered.nucleus.config.CommandsConfig)1 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)1 ResourceMessageProvider (io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider)1 TextParsingUtils (io.github.nucleuspowered.nucleus.internal.text.TextParsingUtils)1 CoreConfig (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig)1 CoreConfigAdapter (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)1 TestModule (io.github.nucleuspowered.nucleus.tests.util.TestModule)1 Field (java.lang.reflect.Field)1 BeforeClass (org.junit.BeforeClass)1 Logger (org.slf4j.Logger)1 Game (org.spongepowered.api.Game)1 ConfigDir (org.spongepowered.api.config.ConfigDir)1 DefaultConfig (org.spongepowered.api.config.DefaultConfig)1