MockBukkit / MockBukkit

MockBukkit is a mocking framework for Bukkit/PaperMC to allow the easy unit testing of Bukkit plugins.
https://mockbukkit.org/
MIT License
615 stars 139 forks source link

Could not find file plugin.yml #694

Closed NyashMyash99 closed 2 years ago

NyashMyash99 commented 2 years ago

Is there an existing issue for this?

Are you using the latest version of MockBukkit?

Minecraft Version

1.19

Describe the bug

I have a modular Maven project and I'm creating tests for one of modules, using files of another module, but for some reason MockBukkit can't find plugin.yml, although debug says it exists.

Reproducible Test

@FieldDefaults(level = AccessLevel.PRIVATE)
public class TestPlugin {
    static Plugin plugin;

    @BeforeAll
    @SneakyThrows
    public static void setUp() {
        var server = MockBukkit.mock();

        System.out.println(LibraryBukkitPlugin.class.getClassLoader().getResource("plugin.yml"));
        System.out.println(LibraryBukkitPlugin.class.getClassLoader().getResources("plugin.yml").hasMoreElements());
        System.out.println(LibraryBukkitPlugin.class.getClassLoader().getResources("plugin.yml").nextElement());

        plugin = MockBukkit.load(LibraryBukkitPlugin.class);
    }

    @AfterAll
    public static void tearDown() {
        MockBukkit.unmock();
    }
}

Anything else?

Test response:

file:/D:/Development/Projects/IdeaProjects/Library/bukkit/target/classes/plugin.yml
true
file:/D:/Development/Projects/IdeaProjects/Library/bukkit/target/classes/plugin.yml

Test ignored.

java.lang.RuntimeException: java.io.FileNotFoundException: Could not find file plugin.yml. Maybe forgot to add the 'main' property?
    at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.loadPlugin(PluginManagerMock.java:422)
    at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:179)
    at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:165)
    at TestPlugin.setUp(TestPlugin.java:31)

File by link:

name: Library
description: Basic classes for project development.
version: 1.0.0

main: su.nyashmyash99.library.bukkit.BukkitPlugin

Plugin class:

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class LibraryBukkitPlugin extends JavaPlugin {
    @Getter static Injector injector;

    @Override
    public void onEnable() {
        injector = Guice.createInjector(new LibraryInjectionModule(), new BukkitLibraryInjectionModule(this));
    }
}
NyashMyash99 commented 2 years ago

Wrong path to main file was specified.