Ignore:
Timestamp:
2016-09-10T16:13:02+02:00 (8 years ago)
Author:
Don-vip
Message:

improve plugin integration test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java

    r10986 r10988  
    1313import java.util.Map;
    1414import java.util.Set;
     15import java.util.function.Consumer;
    1516import java.util.stream.Collectors;
    1617
     
    2324import org.openstreetmap.josm.JOSMFixture;
    2425import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.data.gpx.GpxData;
    2527import org.openstreetmap.josm.data.osm.DataSet;
     28import org.openstreetmap.josm.gui.layer.GpxLayer;
     29import org.openstreetmap.josm.gui.layer.Layer;
    2630import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2731import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     
    9094                .collect(Collectors.toMap(e -> e.getKey(), e -> ExceptionUtils.getRootCause(e.getValue())));
    9195
    92         // Add/remove a data layer twice to test basic plugin good behaviour
     96        // Add/remove layers twice to test basic plugin good behaviour
    9397        Map<String, Throwable> layerExceptions = new HashMap<>();
    9498        List<PluginInformation> loadedPlugins = PluginHandler.getPlugins();
    9599        for (int i = 0; i < 2; i++) {
    96100            OsmDataLayer layer = new OsmDataLayer(new DataSet(), "Layer "+i, null);
    97             try {
    98                 Main.getLayerManager().addLayer(layer);
    99             } catch (Exception | LinkageError t) {
    100                 Throwable root = ExceptionUtils.getRootCause(t);
    101                 layerExceptions.put(findFaultyPlugin(loadedPlugins, root), root);
    102             }
    103             try {
    104                 Main.getLayerManager().removeLayer(layer);
    105             } catch (Exception | LinkageError t) {
    106                 Throwable root = ExceptionUtils.getRootCause(t);
    107                 layerExceptions.put(findFaultyPlugin(loadedPlugins, root), root);
    108             }
     101            testPlugin(Main.getLayerManager()::addLayer, layer, layerExceptions, loadedPlugins);
     102            testPlugin(Main.getLayerManager()::removeLayer, layer, layerExceptions, loadedPlugins);
     103        }
     104        for (int i = 0; i < 2; i++) {
     105            GpxLayer layer = new GpxLayer(new GpxData());
     106            testPlugin(Main.getLayerManager()::addLayer, layer, layerExceptions, loadedPlugins);
     107            testPlugin(Main.getLayerManager()::removeLayer, layer, layerExceptions, loadedPlugins);
    109108        }
    110109
     
    114113                     Arrays.toString(layerExceptions.entrySet().toArray());
    115114        assertTrue(msg, loadingExceptions.isEmpty() && layerExceptions.isEmpty());
     115    }
     116
     117    void testPlugin(Consumer<Layer> consumer, Layer layer,
     118            Map<String, Throwable> layerExceptions, Collection<PluginInformation> loadedPlugins) {
     119        try {
     120            consumer.accept(layer);
     121        } catch (Exception | LinkageError t) {
     122            Throwable root = ExceptionUtils.getRootCause(t);
     123            root.printStackTrace();
     124            layerExceptions.put(findFaultyPlugin(loadedPlugins, root), root);
     125        }
    116126    }
    117127
Note: See TracChangeset for help on using the changeset viewer.