use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class LauncherModelTest method testLauncherDelay.
/**
* Test the launcher with delay.
*
* @throws InterruptedException If error.
*/
@Test
void testLauncherDelay() throws InterruptedException {
final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia, 100);
final Setup setup = new Setup(launcherMedia);
final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
final AtomicBoolean fired = new AtomicBoolean();
final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
launcher.addListener(UtilLaunchable.createListener(fired));
launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
}
});
final Handler handler = services.get(Handler.class);
launcher.update(1.0);
handler.update(1.0);
assertEquals(0, handler.size());
assertTrue(fired.get());
assertNull(firedLaunchable.get());
assertTimeout(1000L, () -> {
while (firedLaunchable.get() == null) {
launcher.update(1.0);
handler.update(1.0);
}
});
assertEquals(1, handler.size());
firedLaunchable.set(null);
handler.removeAll();
handler.update(1.0);
assertEquals(0, handler.size());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class ProducibleModelTest method testProducibleSelf.
/**
* Test the producible self listener.
*/
@Test
void testProducibleSelf() {
final Media media = UtilProducible.createProducibleMedia();
final Setup setup = new Setup(media);
final ProducibleListenerSelf object = new ProducibleListenerSelf(services, setup);
final Producible producible = new ProducibleModel(services, setup);
producible.prepare(object);
assertTrue(producible.getListeners().contains(object));
producible.getFeature(Identifiable.class).notifyDestroyed();
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testHandlerConverter.
/**
* Test the state handling with custom converter.
*/
@Test
void testHandlerConverter() {
Medias.setLoadFromJar(StateHandlerTest.class);
try {
final Setup setup = new Setup(Medias.create("Object.xml"));
final Featurable featurable = new FeaturableModel(services, setup);
final StateHandler handler;
handler = featurable.addFeatureAndGet(new StateHandler(services, setup, Class::getName));
handler.prepare(featurable);
handler.changeState(StateIdle.class);
assertCause(() -> handler.postUpdate(), "Animation not found: " + StateIdle.class.getName());
} finally {
Medias.setLoadFromJar(null);
}
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testUnknownState.
/**
* Test is state with invalid parameter.
*/
@Test
void testUnknownState() {
Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
try {
final Setup setup = new Setup(config);
final StateHandler handler = new StateHandler(services, setup);
handler.changeState(State.class);
assertCause(() -> handler.postUpdate(), NoSuchMethodException.class);
assertTrue(config.getFile().delete());
} finally {
Medias.setResourcesDirectory(null);
}
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testHandler.
/**
* Test the state handling.
*/
@Test
void testHandler() {
Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
try {
final Setup setup = new Setup(config);
final StateHandler handler = new StateHandler(services, setup);
assertFalse(handler.isState(StateBase.class));
assertFalse(StateBase.entered);
assertFalse(StateBase.updated);
assertFalse(StateBase.exited);
handler.update(1.0);
handler.postUpdate();
assertFalse(handler.isState(StateBase.class));
assertFalse(StateBase.entered);
assertFalse(StateBase.updated);
assertFalse(StateBase.exited);
handler.changeState(StateBase.class);
handler.postUpdate();
assertTrue(handler.isState(StateBase.class));
assertTrue(StateBase.entered);
assertFalse(StateBase.updated);
assertFalse(StateBase.exited);
StateBase.reset();
handler.update(1.0);
handler.postUpdate();
assertFalse(StateBase.entered);
assertTrue(StateBase.updated);
assertFalse(StateBase.exited);
assertFalse(StateNext.entered);
assertFalse(StateNext.updated);
assertFalse(StateNext.exited);
StateBase.reset();
StateBase.check = true;
handler.update(1.0);
handler.postUpdate();
assertFalse(StateBase.entered);
assertTrue(StateBase.updated);
assertTrue(StateBase.exited);
assertTrue(StateNext.entered);
assertFalse(StateNext.updated);
assertFalse(StateNext.exited);
StateBase.reset();
handler.update(1.0);
handler.postUpdate();
assertFalse(StateBase.entered);
assertFalse(StateBase.updated);
assertFalse(StateBase.exited);
assertTrue(StateNext.updated);
assertFalse(StateNext.exited);
assertTrue(config.getFile().delete());
} finally {
Medias.setResourcesDirectory(null);
}
}
Aggregations