Search in sources :

Example 1 with PluginManager

use of org.spongepowered.api.plugin.PluginManager in project SpongeCommon by SpongePowered.

the class ShouldFireTest method init.

@Before
public void init() throws Exception {
    PluginManager manager = Mockito.mock(PluginManager.class);
    this.eventManager = new SpongeEventManager(this.logger, manager);
    this.plugin = new Object();
    this.container = Mockito.mock(PluginContainer.class);
    Mockito.when(manager.fromInstance(this.plugin)).thenReturn(Optional.of(this.container));
    this.resetStatics();
}
Also used : PluginManager(org.spongepowered.api.plugin.PluginManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Before(org.junit.Before)

Example 2 with PluginManager

use of org.spongepowered.api.plugin.PluginManager in project SpongeCommon by SpongePowered.

the class SnapshotGenerationTest method init.

@Before
public void init() {
    PluginManager manager = Mockito.mock(PluginManager.class);
    this.eventManager = new SpongeEventManager(this.logger, manager);
    try {
        Field field = Timings.class.getDeclaredField("factory");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(null, Mockito.mock(TimingsFactory.class));
    } catch (IllegalAccessException | NoSuchFieldException e) {
        e.printStackTrace();
    }
    this.plugin = new Object();
    PluginContainer container = Mockito.mock(PluginContainer.class);
    Mockito.when(manager.fromInstance(this.plugin)).thenReturn(Optional.of(container));
    Cause cause = Cause.of(EventContext.empty(), this);
    this.entity = Mockito.mock(Entity.class, withSettings().defaultAnswer(Mockito.RETURNS_MOCKS));
    this.event = SpongeEventFactory.createSpawnEntityEvent(cause, Lists.newArrayList(this.entity));
    Game game = mock(Game.class);
    CauseStackManager csm = mock(CauseStackManager.class);
    Mockito.when(game.getCauseStackManager()).thenReturn(csm);
}
Also used : Entity(org.spongepowered.api.entity.Entity) PluginContainer(org.spongepowered.api.plugin.PluginContainer) PluginManager(org.spongepowered.api.plugin.PluginManager) Field(java.lang.reflect.Field) Game(org.spongepowered.api.Game) CauseStackManager(org.spongepowered.api.event.CauseStackManager) TimingsFactory(co.aikar.timings.TimingsFactory) Cause(org.spongepowered.api.event.cause.Cause) Before(org.junit.Before)

Example 3 with PluginManager

use of org.spongepowered.api.plugin.PluginManager in project SpongeCommon by SpongePowered.

the class TestImplementationModule method configure.

@Override
protected void configure() {
    super.configure();
    this.bind(Server.class).to(TestServer.class);
    this.bind(SpongeGame.class).to(TestGame.class);
    Platform platform = mock(Platform.class);
    PluginContainer mock = mock(PluginContainer.class);
    when(platform.getContainer(any())).thenReturn(mock);
    this.bind(Platform.class).toInstance(platform);
    PluginManager manager = mock(PluginManager.class);
    when(mock.getId()).thenReturn("sponge");
    when(manager.getPlugin(anyString())).thenReturn(Optional.of(mock));
    when(manager.fromInstance(any())).thenReturn(Optional.of(mock));
    this.bind(PluginManager.class).toInstance(manager);
    this.bind(EventManager.class).toInstance(mock(EventManager.class));
    this.bind(ChannelRegistrar.class).toInstance(mock(ChannelRegistrar.class));
}
Also used : PluginManager(org.spongepowered.api.plugin.PluginManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TestServer(org.spongepowered.common.test.TestServer) Server(org.spongepowered.api.Server) Platform(org.spongepowered.api.Platform) SpongePlatform(org.spongepowered.common.SpongePlatform) EventManager(org.spongepowered.api.event.EventManager) ChannelRegistrar(org.spongepowered.api.network.ChannelRegistrar) SpongeGame(org.spongepowered.common.SpongeGame)

Example 4 with PluginManager

use of org.spongepowered.api.plugin.PluginManager in project SpongeForge by SpongePowered.

the class SpongeModEventManagerTest method init.

@Before
public void init() throws Exception {
    PluginManager manager = Mockito.mock(PluginManager.class);
    this.eventManager = new SpongeEventManager(manager);
    this.plugin = new Object();
    this.container = Mockito.mock(PluginContainer.class);
    Mockito.when(manager.fromInstance(plugin)).thenReturn(Optional.of(this.container));
    this.resetStatics();
}
Also used : PluginManager(org.spongepowered.api.plugin.PluginManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) SpongeEventManager(org.spongepowered.common.event.SpongeEventManager) Before(org.junit.Before)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)4 PluginManager (org.spongepowered.api.plugin.PluginManager)4 Before (org.junit.Before)3 TimingsFactory (co.aikar.timings.TimingsFactory)1 Field (java.lang.reflect.Field)1 Game (org.spongepowered.api.Game)1 Platform (org.spongepowered.api.Platform)1 Server (org.spongepowered.api.Server)1 Entity (org.spongepowered.api.entity.Entity)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 EventManager (org.spongepowered.api.event.EventManager)1 Cause (org.spongepowered.api.event.cause.Cause)1 ChannelRegistrar (org.spongepowered.api.network.ChannelRegistrar)1 SpongeGame (org.spongepowered.common.SpongeGame)1 SpongePlatform (org.spongepowered.common.SpongePlatform)1 SpongeEventManager (org.spongepowered.common.event.SpongeEventManager)1 TestServer (org.spongepowered.common.test.TestServer)1