use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class StateAnimationUtil method loadStates.
/**
* Load all existing animations defined in the xml file.
*
* @param states The states values.
* @param factory The factory reference.
* @param provider The featurable reference.
* @param setup The setup reference.
*/
public static void loadStates(StateAnimationBased[] states, StateFactory factory, FeatureProvider provider, Setup setup) {
final AnimationConfig configAnimations = AnimationConfig.imports(setup);
for (final StateAnimationBased type : states) {
try {
final Animation animation = configAnimations.getAnimation(type.getAnimationName());
final State state = UtilReflection.create(type.getStateClass(), UtilReflection.getParamTypes(provider, animation), provider, animation);
factory.addState(state);
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception);
}
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class XmlTest method testWrongWriteXml.
/**
* Test wrong write in xml file.
*
* @throws IOException If error.
*/
private void testWrongWriteXml() throws IOException {
try {
new Xml("child").save(Medias.create(Constant.EMPTY_STRING));
Assert.fail();
} catch (final LionEngineException exception) {
// Success
Assert.assertNotNull(exception);
}
final File file = File.createTempFile("foo", null);
file.deleteOnExit();
if (file.mkdir()) {
try {
new Xml("child").save(Medias.create(file.getPath()));
Assert.fail();
} catch (final LionEngineException exception) {
// Success
Assert.assertNotNull(exception);
} finally {
UtilFolder.deleteDirectory(file);
}
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class SpriteParallaxedTest method testParallaxFailure.
/**
* Test parallax sprite failure.
*/
@Test
public void testParallaxFailure() {
try {
final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, 0, 60, 100);
Assert.assertNotNull(spriteC);
Assert.fail();
} catch (final LionEngineException exception) {
// Success
Assert.assertNotNull(exception);
}
try {
final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 60, 0);
Assert.assertNotNull(spriteC);
Assert.fail();
} catch (final LionEngineException exception) {
// Success
Assert.assertNotNull(exception);
}
try {
final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 0, 60);
Assert.assertNotNull(spriteC);
Assert.fail();
} catch (final LionEngineException exception) {
// Success
Assert.assertNotNull(exception);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ProducerModelTest method testEnumFail.
/**
* Test with enum fail.
*
* @throws NoSuchFieldException If error.
* @throws IllegalArgumentException If error.
* @throws IllegalAccessException If error.
*/
@Test
public void testEnumFail() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
final ProducerModel producer = new ProducerModel(services);
final Field field = producer.getClass().getDeclaredField("state");
UtilReflection.setAccessible(field, true);
field.set(producer, ProducerState.values()[5]);
try {
producer.update(1.0);
Assert.fail();
} catch (final LionEngineException exception) {
Assert.assertEquals("Unknown enum: FAIL", exception.getMessage());
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ServerImpl method start.
@Override
public void start(String name, int port) {
if (!started) {
try {
serverSocket = new ServerSocket(port);
clientConnectionListener = new ClientConnecter(serverSocket, this);
clientConnectionListener.start();
this.port = port;
bandwidthTimer.start();
started = true;
} catch (final IOException exception) {
throw new LionEngineException(exception, "Cannot create the server !");
}
}
}
Aggregations