use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testNullArgument.
/**
* Test is state with invalid parameter.
*/
@Test
void testNullArgument() {
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);
assertThrows(() -> handler.changeState(null), "Unexpected null argument !");
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 testWithConfig.
/**
* Test state with configuration.
*/
@Test
void testWithConfig() {
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));
handler.prepare(featurable);
handler.changeState(StateIdle.class);
handler.postUpdate();
assertEquals(new Animation(StateIdle.class.getSimpleName(), 1, 1, 0.125, false, false), StateIdle.animation);
assertNull(StateWalk.animation);
assertTrue(handler.isState(StateIdle.class));
handler.update(1.0);
assertNull(StateWalk.animation);
handler.postUpdate();
assertEquals(new Animation(StateWalk.class.getSimpleName(), 2, 2, 0.125, false, false), StateWalk.animation);
assertTrue(handler.isState(StateWalk.class));
handler.update(1.0);
handler.postUpdate();
assertTrue(handler.isState(StateIdle.class));
} finally {
Medias.setLoadFromJar(null);
}
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testLast.
/**
* Test transition with last state.
*/
@Test
void testLast() {
final AtomicReference<Class<? extends State>> old = new AtomicReference<>();
final AtomicReference<Class<? extends State>> next = new AtomicReference<>();
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.addListener((o, n) -> {
old.set(o);
next.set(n);
});
handler.changeState(StateMock.class);
handler.postUpdate();
handler.postUpdate();
assertNull(old.get());
assertEquals(StateMock.class, next.get());
old.set(null);
next.set(null);
handler.changeState(StateMock.class);
handler.postUpdate();
assertEquals(StateMock.class, old.get());
assertEquals(StateMock.class, next.get());
assertTrue(config.getFile().delete());
} finally {
Medias.setResourcesDirectory(null);
}
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class CollidableConfigTest method testEmptyAccepted.
/**
* Test with empty accepted.
*/
@Test
void testEmptyAccepted() {
final Media media = Medias.create("Object.xml");
final Xml root = new Xml("test");
root.save(media);
final Services services = new Services();
services.add(new ViewerMock());
final Collidable collidable = new CollidableModel(services, new Setup(media));
collidable.setGroup(Integer.valueOf(1));
CollidableConfig.exports(root, collidable);
root.save(media);
final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
assertEquals(Integer.valueOf(1), config.getGroup());
assertTrue(config.getAccepted().isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class CollidableConfigTest method testExport.
/**
* Test export.
*/
@Test
void testExport() {
final Media media = Medias.create("Object.xml");
final Xml root = new Xml("test");
root.save(media);
final Services services = new Services();
services.add(new ViewerMock());
final Collidable collidable = new CollidableModel(services, new Setup(media));
collidable.setGroup(Integer.valueOf(1));
collidable.addAccept(Integer.valueOf(2));
collidable.addAccept(Integer.valueOf(3));
CollidableConfig.exports(root, collidable);
root.save(media);
final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
assertEquals(Integer.valueOf(1), config.getGroup());
assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
assertTrue(media.getFile().delete());
}
Aggregations