Launcher/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java

69 lines
2.8 KiB
Java
Raw Normal View History

package pro.gravit.launcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
2019-10-19 19:46:04 +03:00
import pro.gravit.launcher.impl.*;
import pro.gravit.launcher.impl.event.CancelEvent;
import pro.gravit.launcher.impl.event.NormalEvent;
import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launcher.modules.impl.SimpleModuleManager;
2019-10-19 19:46:04 +03:00
import java.nio.file.Path;
public class ModulesTest {
@TempDir
public static Path configDir;
@TempDir
public static Path modulesDir;
public static SimpleModuleManager moduleManager;
public static int dependInt = 0;
2019-10-19 19:46:04 +03:00
public static void add(int a) {
if (dependInt != a) throw new IllegalStateException(String.valueOf(a));
dependInt++;
}
2019-10-19 19:46:04 +03:00
@BeforeAll
2019-10-19 19:46:04 +03:00
public static void prepare() {
moduleManager = new SimpleModuleManager(modulesDir, configDir);
}
2019-10-19 19:46:04 +03:00
@Test
2019-10-19 19:46:04 +03:00
public void baseModule() {
moduleManager.loadModule(new TestModule());
moduleManager.initModules(null);
NormalEvent e = new NormalEvent();
moduleManager.invokeEvent(e);
Assertions.assertTrue(e.passed);
CancelEvent e1 = new CancelEvent();
moduleManager.invokeEvent(e1);
Assertions.assertTrue(e1.isCancel());
}
2019-10-19 19:46:04 +03:00
@Test
2019-10-19 19:46:04 +03:00
public void dependenciesTest() {
moduleManager.loadModule(new Depend1Module());
moduleManager.loadModule(new Depend2Module());
moduleManager.loadModule(new Depend3Module());
moduleManager.loadModule(new MainModule());
moduleManager.initModules(null);
Assertions.assertEquals(moduleManager.getModule("depend1").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("depend2").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("depend3").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("internal").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("virtual").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("main").getInitStatus(), LauncherModule.InitStatus.FINISH);
}
2019-10-19 19:46:04 +03:00
@Test
2019-10-19 19:46:04 +03:00
public void cyclicTest() {
moduleManager.loadModule(new CyclicDependModule());
moduleManager.loadModule(new Cyclic2DependModule());
moduleManager.initModules(null);
Assertions.assertEquals(moduleManager.getModule("cyclic1").getInitStatus(), LauncherModule.InitStatus.FINISH);
Assertions.assertEquals(moduleManager.getModule("cyclic2").getInitStatus(), LauncherModule.InitStatus.FINISH);
}
}