Search in sources :

Example 1 with CulpritFinder

use of space.arim.libertybans.bootstrap.CulpritFinder in project LibertyBans by A248.

the class VelocityCulpritFinderTest method findCulprit.

@Test
public void findCulprit(@Mock ProxyServer server, @Mock PluginManager pluginManager, @Mock PluginContainer pluginString, @Mock PluginContainer pluginOwnClass) {
    class OwnClass {
    }
    {
        when(server.getPluginManager()).thenReturn(pluginManager);
        when(pluginManager.getPlugins()).thenReturn(List.of(pluginString, pluginOwnClass));
        when(pluginString.getInstance()).thenAnswer((i) -> Optional.of("a".concat("b")));
        setDescription(pluginString, "JDK", "0");
        when(pluginOwnClass.getInstance()).thenAnswer((i) -> Optional.of(new OwnClass()));
        setDescription(pluginOwnClass, "Self", "1");
    }
    CulpritFinder culpritFinder = new VelocityCulpritFinder(server);
    assertEquals("JDK 0", culpritFinder.findCulprit(List.class));
    assertEquals("Self 1", culpritFinder.findCulprit(getClass()));
}
Also used : MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CulpritFinder(space.arim.libertybans.bootstrap.CulpritFinder) PluginDescription(com.velocitypowered.api.plugin.PluginDescription) Mock(org.mockito.Mock) Mockito.when(org.mockito.Mockito.when) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Optional(java.util.Optional) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PluginManager(com.velocitypowered.api.plugin.PluginManager) Mockito.mock(org.mockito.Mockito.mock) CulpritFinder(space.arim.libertybans.bootstrap.CulpritFinder) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

PluginContainer (com.velocitypowered.api.plugin.PluginContainer)1 PluginDescription (com.velocitypowered.api.plugin.PluginDescription)1 PluginManager (com.velocitypowered.api.plugin.PluginManager)1 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)1 List (java.util.List)1 Optional (java.util.Optional)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Mock (org.mockito.Mock)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1 CulpritFinder (space.arim.libertybans.bootstrap.CulpritFinder)1