use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class MapTilePersisterModelTest method testListener.
/**
* Test load listener.
*
* @throws IOException If error.
*/
@Test
void testListener() throws IOException {
final MapTileGame map = new MapTileGame();
final MapTilePersister mapPersister = map.addFeatureAndGet(new MapTilePersisterModel());
final Media level = Medias.create("level");
map.create(16, 32, 3, 3);
UtilMapTilePersister.saveMap(map, level);
final AtomicBoolean load = new AtomicBoolean();
final MapTilePersisterListener listener = new MapTilePersisterListener() {
@Override
public void notifyMapLoadStart() {
load.set(false);
}
@Override
public void notifyMapLoaded() {
load.set(true);
}
};
mapPersister.addListener(listener);
try (FileReading input = new FileReading(level)) {
mapPersister.load(input);
}
assertTrue(load.get());
load.set(false);
mapPersister.removeListener(listener);
try (FileReading input = new FileReading(level)) {
mapPersister.load(input);
}
assertFalse(load.get());
assertTrue(level.getFile().delete());
}
Aggregations