use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.
the class FeaturableModelTest method testAddFeatures.
/**
* Test the add features.
*/
@Test
void testAddFeatures() {
final Media media = Medias.create("Features.xml");
final Xml root = new Xml(FeaturableConfig.NODE_FEATURABLE);
final Xml unknown = root.createChild(FeaturableConfig.NODE_FEATURE);
unknown.setText(MyFeature.class.getName());
root.save(media);
Featurable featurable = new FeaturableModel(new Services(), new Setup(media));
featurable.checkListener(featurable);
assertEquals(media, featurable.getMedia());
for (final Feature next : featurable.getFeatures()) {
assertTrue(MyFeature.class.equals(next.getClass()) || Identifiable.class.isAssignableFrom(next.getClass()) || Recycler.class.isAssignableFrom(next.getClass()), next.getClass().getName());
}
featurable = new FeaturableModel(new Services(), new Setup(media));
UtilFile.deleteFile(media.getFile());
}
use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.
the class FeaturableModelTest method testFeaturableCompatible.
/**
* Test the featurable model with compatible feature.
*/
@Test
void testFeaturableCompatible() {
final Featurable featurable = new FeaturableModel(services, setup);
final MyFeatureInterface feature = new MyFeature(services, setup);
featurable.addFeature(feature);
assertTrue(featurable.hasFeature(MyFeatureInterface.class));
assertTrue(featurable.hasFeature(MyFeature.class));
assertEquals(feature, featurable.getFeature(MyFeature.class));
for (final Feature current : featurable.getFeatures()) {
assertTrue(feature.getClass().equals(current.getClass()) || Identifiable.class.isAssignableFrom(current.getClass()) || Recycler.class.isAssignableFrom(current.getClass()), current.getClass().getName());
}
for (final Class<? extends Feature> type : featurable.getFeaturesType()) {
assertTrue(MyFeatureInterface.class.isAssignableFrom(type) || Identifiable.class.isAssignableFrom(type) || Recycler.class.isAssignableFrom(type), type.getName());
}
}
use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.
the class FeaturableModelTest method testFeaturableNotcompatible.
/**
* Test the featurable model with not compatible interface.
*/
@Test
void testFeaturableNotcompatible() {
final Featurable featurable = new FeaturableModel(services, setup);
final MyFeatureNotCompatible feature = new MyFeatureNotCompatible(services, setup);
featurable.addFeature(feature);
assertTrue(featurable.hasFeature(MyFeatureNotCompatible.class));
assertEquals(feature, featurable.getFeature(MyFeatureNotCompatible.class));
for (final Feature current : featurable.getFeatures()) {
assertTrue(feature.getClass().equals(current.getClass()) || Identifiable.class.isAssignableFrom(current.getClass()) || Recycler.class.isAssignableFrom(current.getClass()), current.getClass().getName());
}
for (final Class<? extends Feature> type : featurable.getFeaturesType()) {
assertTrue(MyFeatureNotCompatible.class.isAssignableFrom(type) || Identifiable.class.isAssignableFrom(type) || Recycler.class.isAssignableFrom(type), type.getName());
}
}
use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.
the class FeaturableModelTest method testFeatureAnnotationNotFound.
/**
* Test with annotation and feature not found.
*/
@Test
void testFeatureAnnotationNotFound() {
final Featurable featurable = new FeaturableModel(services, setup);
final AtomicReference<String> unfilledType = new AtomicReference<>();
final Feature feature = new FeatureModel(services, setup) {
@FeatureGet
private String type;
@Override
public void prepare(FeatureProvider provider) {
super.prepare(provider);
unfilledType.set(type);
}
};
assertThrows(() -> featurable.addFeature(feature), "[transformable_FeaturableModelTest.xml] Class not found: " + String.class + " in " + feature);
}
use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.
the class FeaturableConfigTest method testGetFeaturesCache.
/**
* Test with cached feature class.
*/
@Test
void testGetFeaturesCache() {
final Xml root = new Xml("test");
root.createChild(FeaturableConfig.NODE_FEATURES).createChild(FeaturableConfig.NODE_FEATURE).setText(FeatureModel.class.getName());
final Media media = Medias.create("Object.xml");
root.save(media);
final ClassLoader loader = ClassLoader.getSystemClassLoader();
final Services services = new Services();
final Setup setup = new Setup(media);
final List<Feature> a = FeaturableConfig.getFeatures(loader, services, setup);
final List<Feature> b = FeaturableConfig.getFeatures(loader, services, setup);
assertNotEquals(a.get(0), b.get(0));
}
Aggregations