Changeset 10467 in josm


Ignore:
Timestamp:
2016-06-24T00:30:42+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #13037 - Small fixes for unit tests (patch by michael2402) - gsoc-core

Location:
trunk
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r10382 r10467  
    6666        Main.main.undoRedo.add(new AddCommand(nnew));
    6767        getLayerManager().getEditDataSet().setSelected(nnew);
    68         if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
    69             Main.map.mapView.repaint();
    70         } else {
    71             AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     68        if (Main.map.mapView != null) {
     69            if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
     70                Main.map.mapView.repaint();
     71            } else {
     72                AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     73            }
    7274        }
    7375    }
  • trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r10383 r10467  
    284284
    285285        Main.main.undoRedo.add(new SequenceCommand(tr("Align Nodes in Circle"), cmds));
    286         Main.map.repaint();
    287286    }
    288287
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r10463 r10467  
    205205            // Do it!
    206206            Main.main.undoRedo.add(cmd);
    207             Main.map.repaint();
    208207
    209208        } catch (InvalidSelection except) {
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r10409 r10467  
    241241
    242242        Main.main.undoRedo.add(new SequenceCommand(tr("Create Circle"), cmds));
    243         Main.map.repaint();
    244243    }
    245244
  • trunk/src/org/openstreetmap/josm/actions/DistributeAction.java

    r10409 r10467  
    9898        // Do it!
    9999        Main.main.undoRedo.add(new SequenceCommand(tr("Distribute Nodes"), cmds));
    100         Main.map.repaint();
    101100    }
    102101
  • trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java

    r10292 r10467  
    137137            }
    138138            kev.consume();
    139             Main.map.repaint();
    140139        }
    141140    }
     
    164163            offsetDialog.updateOffset();
    165164        }
    166         Main.map.repaint();
    167165        prevEastNorth = eastNorth;
    168166    }
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r10409 r10467  
    160160        if (cmds.isEmpty()) return;
    161161        Main.main.undoRedo.add(new SequenceCommand(getValue(NAME).toString(), cmds));
    162         Main.map.repaint();
    163162    }
    164163
  • trunk/src/org/openstreetmap/josm/actions/MirrorAction.java

    r10409 r10467  
    8181
    8282        Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds));
    83         Main.map.repaint();
    8483    }
    8584
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r10463 r10467  
    113113                if (!commands.isEmpty()) {
    114114                    Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize / Undo"), commands));
    115                     Main.map.repaint();
    116115                } else {
    117116                    throw new InvalidUserInputException("Commands are empty");
     
    153152            final SequenceCommand command = orthogonalize(sel);
    154153            Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), command));
    155             Main.map.repaint();
    156154        } catch (InvalidUserInputException ex) {
    157155            Main.debug(ex);
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r10463 r10467  
    103103        }
    104104        Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
     105        // FIXME: This should be handled by undoRedo.
    105106        if (propertiesUpdated) {
    106107            ds.fireSelectionChanged();
    107108        }
    108         Main.map.repaint();
    109109    }
    110110
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r10409 r10467  
    124124            ds.endUpdate();
    125125        }
    126         Main.map.repaint();
    127126    }
    128127
  • trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java

    r10409 r10467  
    9191        // I'm sure there's a better way to handle this
    9292        Main.main.undoRedo.add(new RemoveNodesCommand(selectedWay, selectedNodes));
    93         Main.map.repaint();
    9493    }
    9594
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r10306 r10467  
    122122                    public void run() {
    123123                        targetLayer.onPostDownloadFromServer();
    124                         if (Main.map != null)
    125                             Main.map.mapView.repaint();
    126124                    }
    127125                }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r10448 r10467  
    134134     */
    135135    public static void doActionPerformed(ActionEvent e) {
    136         if (!Main.map.mapView.isActiveLayerDrawable())
    137             return;
     136        MainLayerManager lm = Main.getLayerManager();
     137        OsmDataLayer editLayer = lm.getEditLayer();
     138        if (editLayer == null) {
     139            return;
     140        }
     141
    138142        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    139143        boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0;
    140144
    141         MainLayerManager lm = Main.getLayerManager();
    142145        Command c;
    143146        if (ctrl) {
    144             c = DeleteCommand.deleteWithReferences(lm.getEditLayer(), lm.getEditDataSet().getSelected());
     147            c = DeleteCommand.deleteWithReferences(editLayer, lm.getEditDataSet().getSelected());
    145148        } else {
    146             c = DeleteCommand.delete(lm.getEditLayer(), lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
     149            c = DeleteCommand.delete(editLayer, lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
    147150        }
    148151        // if c is null, an error occurred or the user aborted. Don't do anything in that case.
    149152        if (c != null) {
    150153            Main.main.undoRedo.add(c);
     154            //FIXME: This should not be required, DeleteCommand should update the selection, otherwise undo/redo won't work.
    151155            lm.getEditDataSet().setSelected();
    152             Main.map.repaint();
    153156        }
    154157    }
     
    213216    private void repaintIfRequired(Set<OsmPrimitive> newHighlights, WaySegment newHighlightedWaySegment) {
    214217        boolean needsRepaint = false;
    215         DataSet ds = getLayerManager().getEditDataSet();
     218        OsmDataLayer editLayer = getLayerManager().getEditLayer();
    216219
    217220        if (newHighlightedWaySegment == null && oldHighlightedWaySegment != null) {
    218             if (ds != null) {
    219                 ds.clearHighlightedWaySegments();
     221            if (editLayer != null) {
     222                editLayer.data.clearHighlightedWaySegments();
    220223                needsRepaint = true;
    221224            }
    222225            oldHighlightedWaySegment = null;
    223226        } else if (newHighlightedWaySegment != null && !newHighlightedWaySegment.equals(oldHighlightedWaySegment)) {
    224             if (ds != null) {
    225                 ds.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
     227            if (editLayer != null) {
     228                editLayer.data.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
    226229                needsRepaint = true;
    227230            }
     
    229232        }
    230233        needsRepaint |= highlightHelper.highlightOnly(newHighlights);
    231         if (needsRepaint) {
    232             Main.map.mapView.repaint();
     234        if (needsRepaint && editLayer != null) {
     235            editLayer.invalidate();
    233236        }
    234237    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r10446 r10467  
    185185
    186186        // update selection to reflect which way being modified
    187         DataSet currentDataSet = getLayerManager().getEditDataSet();
    188         if (getCurrentBaseNode() != null && currentDataSet != null && !currentDataSet.selectionEmpty()) {
     187        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     188        if (getCurrentBaseNode() != null && editLayer != null && !editLayer.data.selectionEmpty()) {
     189            DataSet currentDataSet = editLayer.data;
    189190            Way continueFrom = getWayForNode(getCurrentBaseNode());
    190191            if (alt && continueFrom != null && (!getCurrentBaseNode().isSelected() || continueFrom.isSelected())) {
     
    197198        }
    198199
    199         if (needsRepaint) {
    200             Main.map.mapView.repaint();
     200        if (needsRepaint && editLayer != null) {
     201            editLayer.invalidate();
    201202        }
    202203        return needsRepaint;
     
    917918    @Override
    918919    public void mouseExited(MouseEvent e) {
    919         if (!Main.map.mapView.isActiveLayerDrawable())
     920        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
     921        if (editLayer == null)
    920922            return;
    921923        mousePos = e.getPoint();
     
    925927        // caused one already, don’t do it again.
    926928        if (!repaintIssued) {
    927             Main.map.mapView.repaint();
     929            editLayer.invalidate();
    928930        }
    929931    }
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r9371 r10467  
    5959    @Override
    6060    public boolean executeCommand() {
    61         getLayer().data.addPrimitive(osm);
     61        getAffectedDataSet().addPrimitive(osm);
    6262        osm.setModified(true);
    6363        checkNodeStyles(osm);
     
    6767    @Override
    6868    public void undoCommand() {
    69         getLayer().data.removePrimitive(osm);
     69        getAffectedDataSet().removePrimitive(osm);
    7070        checkNodeStyles(osm);
    7171    }
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r9371 r10467  
    7878
    7979            for (PrimitiveData pd : data) {
    80                 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd);
     80                OsmPrimitive primitive = getAffectedDataSet().getPrimitiveById(pd);
    8181                boolean created = primitive == null;
    8282                if (created) {
     
    8787                }
    8888                if (created) {
    89                     getLayer().data.addPrimitive(primitive);
     89                    getAffectedDataSet().addPrimitive(primitive);
    9090                }
    9191                newPrimitives.add(primitive);
     
    115115
    116116    @Override public void undoCommand() {
    117         DataSet ds = getLayer().data;
     117        DataSet ds = getAffectedDataSet();
    118118
    119119        if (createdPrimitives == null) {
     
    167167        Collection<OsmPrimitive> prims = new HashSet<>();
    168168        for (PrimitiveData d : data) {
    169             OsmPrimitive osm = getLayer().data.getPrimitiveById(d);
     169            OsmPrimitive osm = getAffectedDataSet().getPrimitiveById(d);
    170170            if (osm == null)
    171171                throw new RuntimeException();
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r10452 r10467  
    1717import org.openstreetmap.josm.data.coor.EastNorth;
    1818import org.openstreetmap.josm.data.coor.LatLon;
     19import org.openstreetmap.josm.data.osm.DataSet;
    1920import org.openstreetmap.josm.data.osm.Node;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    210211    protected OsmDataLayer getLayer() {
    211212        return layer;
     213    }
     214
     215    /**
     216     * Gets the data set this command affects.
     217     * @return The data set. May be <code>null</code> if no layer was set and no edit layer was found.
     218     * @since 10467
     219     */
     220    public DataSet getAffectedDataSet() {
     221        return layer == null ? null : layer.data;
    212222    }
    213223
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r9371 r10467  
    5959        //
    6060        for (Node n:mergedNodeList) {
    61             if (!getLayer().data.getNodes().contains(n)) {
     61            if (!getAffectedDataSet().getNodes().contains(n)) {
    6262                Main.warn(tr("Main dataset does not include node {0}", n.toString()));
    6363            }
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r10452 r10467  
    7474     */
    7575    public synchronized void add(final Command c) {
    76         DataSet ds = Main.getLayerManager().getEditDataSet();
    77         Collection<? extends OsmPrimitive> oldSelection = ds.getSelected();
     76        DataSet ds = c.getAffectedDataSet();
     77        if (ds == null) {
     78            // old, legacy behaviour
     79            ds = Main.getLayerManager().getEditDataSet();
     80        }
     81        Collection<? extends OsmPrimitive> oldSelection = null;
     82        if (ds != null) {
     83            oldSelection = ds.getSelected();
     84        }
    7885        addNoRedraw(c);
    7986        afterAdd();
    8087
    8188        // the command may have changed the selection so tell the listeners about the current situation
    82         fireIfSelectionChanged(ds, oldSelection);
     89        if (ds != null) {
     90            fireIfSelectionChanged(ds, oldSelection);
     91        }
    8392    }
    8493
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r10001 r10467  
    203203                    if (pnt.compareTo(earliest) < 0) {
    204204                        earliest = pnt;
    205                     } else {
     205                    } else if (pnt.compareTo(latest) > 0) {
    206206                        latest = pnt;
    207207                    }
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r10212 r10467  
    1919
    2020    /**
    21      * The seconds (not milliseconds!) since 1970-01-01.
     21     * The seconds (not milliseconds!) since 1970-01-01 00:00 UTC
    2222     */
    2323    public double time;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r10444 r10467  
    101101    @Override
    102102    protected void initializeMainWindow() {
     103        mainPanel.reAddListeners();
    103104        if (mainFrame != null) {
    104105            mainFrame.initialize();
     
    410411        final MainFrame mainFrame = new MainFrame(contentPanePrivate, mainPanel, geometry);
    411412        Main.parent = mainFrame;
    412         mainPanel.reAddListeners();
    413413
    414414        if (args.containsKey(Option.LOAD_PREFERENCES)) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10432 r10467  
    175175     * Creates a layer list and attach it to the given mapView.
    176176     * @param layerManager The layer manager this list is for
    177      */
    178     private LayerListDialog(MainLayerManager layerManager) {
     177     * @since 10467
     178     */
     179    public LayerListDialog(MainLayerManager layerManager) {
    179180        super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."),
    180181                Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L,
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r10428 r10467  
    257257        Main.pref.addPreferenceChangeListener(this);
    258258
     259        registerInWindowMenu();
     260    }
     261
     262    /**
     263     * Registers this dialog in the window menu. Called in the constructor.
     264     * @since 10467
     265     */
     266    protected void registerInWindowMenu() {
    259267        windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu,
    260268                (JosmAction) getToggleAction(),
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r10420 r10467  
    117117    }
    118118
     119    /**
     120     * Sets the displacement offset of this layer. The layer is automatically invalidated.
     121     * @param dx The x offset
     122     * @param dy The y offset
     123     */
    119124    public void setOffset(double dx, double dy) {
    120125        this.dx = dx;
    121126        this.dy = dy;
     127        invalidate();
    122128    }
    123129
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java

    r10458 r10467  
    77import java.util.concurrent.CopyOnWriteArrayList;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.gui.util.GuiHelper;
    1011import org.openstreetmap.josm.tools.Utils;
     
    175176        insertLayerAt(layer, position);
    176177        fireLayerAdded(layer);
    177         layer.hookUpMapView(); // needs to be after fireLayerAdded
     178        if (Main.map != null) {
     179            layer.hookUpMapView(); // needs to be after fireLayerAdded
     180        }
    178181    }
    179182
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r10436 r10467  
    878878        setRequiresSaveToFile(false);
    879879        setRequiresUploadToServer(isModified());
     880        invalidate();
    880881    }
    881882
     
    886887        setRequiresSaveToFile(true);
    887888        setRequiresUploadToServer(isModified());
     889        invalidate();
    888890    }
    889891
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r10443 r10467  
    1212import java.text.MessageFormat;
    1313import java.util.Locale;
     14import java.util.TimeZone;
    1415
    1516import org.openstreetmap.josm.data.projection.Projections;
    1617import org.openstreetmap.josm.gui.MainApplication;
     18import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer;
    1719import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
    1820import org.openstreetmap.josm.gui.util.GuiHelper;
     
    8890        }
    8991        System.setProperty("josm.home", josmHome);
     92        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    9093        Main.initApplicationPreferences();
    9194        Main.pref.enableSaveOnPut(false);
     
    9699        Main.platform.preStartupHook();
    97100
     101        Main.logLevel = 3;
    98102        Main.pref.init(false);
    99103        I18n.set(Main.pref.get("language", "en"));
     
    127131
    128132    private void setupGUI() {
     133        Main.getLayerManager().resetState();
     134        assertTrue(Main.getLayerManager().getLayers().isEmpty());
     135        assertNull(Main.getLayerManager().getEditLayer());
     136        assertNull(Main.getLayerManager().getActiveLayer());
     137
    129138        if (Main.toolbar == null) {
    130139            Main.toolbar = new ToolbarPreferences();
     
    133142            new MainApplication().initialize();
    134143        }
    135         Main.getLayerManager().resetState();
    136         assertTrue(Main.getLayerManager().getLayers().isEmpty());
    137         assertNull(Main.getLayerManager().getEditLayer());
    138         assertNull(Main.getLayerManager().getActiveLayer());
     144        // Add a test layer to the layer manager to get the MapFrame
     145        Main.getLayerManager().addLayer(new TestLayer());
    139146    }
    140147}
  • trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java

    r10447 r10467  
    9292        Date fixed = cal.getTime();
    9393
    94         for (int i = 0; i <= AutosaveTask.PROP_INDEX_LIMIT.get() + 1; i++) {
     94        AutosaveTask.PROP_INDEX_LIMIT.put(5);
     95        for (int i = 0; i <= AutosaveTask.PROP_INDEX_LIMIT.get() + 2; i++) {
    9596            // Only retry 2 indexes to avoid 1000*1000 disk operations
    9697            File f = task.getNewLayerFile(info, fixed, Math.max(0, i - 2));
  • trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy

    r9829 r10467  
    3737            "  <tag key='language' value='en'/>%n" +
    3838            "  <tag key='osm-server.url' value='http://api06.dev.openstreetmap.org/api'/>%n" +
    39             "  <tag key='osm-server.username' value='josm_test'/>%n" +
    40             "</preferences>%n", Version.getInstance().getVersion())
     39            "  <tag key='osm-server.username' value='%s'/>%n" +
     40            "</preferences>%n", Version.getInstance().getVersion(), Main.pref.get("osm-server.username"))
    4141    }
    4242}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r8863 r10467  
    1717
    1818import org.junit.Before;
     19import org.junit.Rule;
    1920import org.junit.Test;
    20 import org.openstreetmap.josm.JOSMFixture;
    2121import org.openstreetmap.josm.data.osm.Tag;
    2222import org.openstreetmap.josm.data.validation.Severity;
     
    2525import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    2626import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
     27import org.openstreetmap.josm.testutils.JOSMTestRules;
     28
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2730
    2831/**
    2932 * JUnit Test of "Opening hours" validation test.
     33 * @see OpeningHourTest
    3034 */
    3135public class OpeningHourTestTest {
    32 
    33     private static final OpeningHourTest OPENING_HOUR_TEST = new OpeningHourTest();
     36    /**
     37     * We need prefs for this. We check strings so we need i18n.
     38     */
     39    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     41    public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
     42
     43    private OpeningHourTest openingHourTest;
    3444
    3545    /**
     
    3949    @Before
    4050    public void setUp() throws Exception {
    41         JOSMFixture.createUnitTestFixture().init();
    42         OPENING_HOUR_TEST.initialize();
     51        openingHourTest = new OpeningHourTest();
     52        openingHourTest.initialize();
    4353    }
    4454
     
    5060        final String key = "opening_hours";
    5161        // frequently used tags according to https://taginfo.openstreetmap.org/keys/opening_hours#values
    52         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "24/7"), isEmpty());
    53         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty());
    54         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr sunrise-sunset"), isEmpty());
    55         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty());
    56         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
    57         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
    58         assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(
     62        assertThat(openingHourTest.checkOpeningHourSyntax(key, "24/7"), isEmpty());
     63        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty());
     64        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr sunrise-sunset"), isEmpty());
     65        assertThat(openingHourTest.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty());
     66        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
     67        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
     68        assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(
    5969                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity());
    60         assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", OPENING_HOUR_TEST.checkOpeningHourSyntax(
     70        assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", openingHourTest.checkOpeningHourSyntax(
    6171                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue());
    6272    }
     
    6474    @Test
    6575    public void testI18n() {
    66         assertTrue(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de")
     76        assertTrue(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de")
    6777                .get(0).toString().contains("Unerwartetes Zeichen"));
    68         assertFalse(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "en")
     78        assertFalse(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "en")
    6979                .get(0).toString().contains("Unerwartetes Zeichen"));
    7080    }
     
    7686    public void testCheckOpeningHourSyntax2() {
    7787        final String key = "opening_hours";
    78         final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue");
     88        final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Mo-Tue");
    7989        assertThat(errors, hasSize(2));
    8090        assertEquals(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage());
     
    92102    public void testCheckOpeningHourSyntax3() {
    93103        final String key = "opening_hours";
    94         final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
     104        final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
    95105        assertThat(errors, hasSize(2));
    96106        assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage());
     
    106116    @Test
    107117    public void testCheckOpeningHourSyntax4() {
    108         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, null), isEmpty());
    109         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, ""), isEmpty());
    110         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, " "), isEmpty());
     118        assertThat(openingHourTest.checkOpeningHourSyntax(null, null), isEmpty());
     119        assertThat(openingHourTest.checkOpeningHourSyntax(null, ""), isEmpty());
     120        assertThat(openingHourTest.checkOpeningHourSyntax(null, " "), isEmpty());
    111121    }
    112122
     
    117127    public void testCheckOpeningHourSyntax5() {
    118128        final String key = "opening_hours";
    119         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
     129        assertThat(openingHourTest.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
    120130        assertEquals(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)",
    121                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage());
    122         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
     131                openingHourTest.checkOpeningHourSyntax(key, "badtext").get(0).getMessage());
     132        assertThat(openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
    123133        assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. "
    124134                + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)",
    125                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage());
     135                openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage());
    126136    }
    127137
     
    132142    public void testCheckOpeningHourSyntax6() {
    133143        final String key = "opening_hours";
    134         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty());
     144        assertThat(openingHourTest.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty());
    135145    }
    136146
     
    141151    public void testCheckOpeningHourSyntax7() {
    142152        final String key = "opening_hours";
    143         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
    144         assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity());
    145         assertEquals("09:00-18:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue());
     153        assertThat(openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
     154        assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity());
     155        assertEquals("09:00-18:00", openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue());
    146156    }
    147157
     
    152162    public void testCheckOpeningHourSyntaxTicket9367() {
    153163        final String key = "opening_hours";
    154         assertEquals(Severity.WARNING, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity());
     164        assertEquals(Severity.WARNING, openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity());
    155165        assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. "
    156166                + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)",
    157                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage());
    158         assertEquals("Mo,Tu 04:00-17:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());
     167                openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage());
     168        assertEquals("Mo,Tu 04:00-17:00", openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());
    159169    }
    160170
     
    166176        final String key = "service_times";
    167177        // frequently used tags according to https://taginfo.openstreetmap.org/keys/service_times#values
    168         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    169         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    170         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    171         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty());
    172         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
     178        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     179        assertThat(openingHourTest.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     180        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     181        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty());
     182        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    173183                OpeningHourTest.CheckMode.BOTH), isEmpty());
    174         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     184        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    175185                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    176186        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    177                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     187                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    178188                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    179189        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    180                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     190                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    181191                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    182192    }
     
    189199        final String key = "collection_times";
    190200        // frequently used tags according to https://taginfo.openstreetmap.org/keys/collection_times#values
    191         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    192         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    193         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    194         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
     201        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     202        assertThat(openingHourTest.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     203        assertThat(openingHourTest.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     204        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
    195205                OpeningHourTest.CheckMode.BOTH), isEmpty());
    196         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     206        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    197207                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    198208        assertEquals(Severity.OTHER,
    199                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     209                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    200210                OpeningHourTest.CheckMode.BOTH).get(0).getSeverity());
    201211        assertEquals("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
    202                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     212                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    203213                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    204214    }
     
    222232        }
    223233        for (final Tag t : values) {
    224             final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(t.getKey(), t.getValue());
     234            final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(t.getKey(), t.getValue());
    225235            assertThat(t + " is valid", errors, isEmpty());
    226236        }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java

    r10396 r10467  
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.BeforeClass;
     8import org.junit.Rule;
    99import org.junit.Test;
    10 import org.openstreetmap.josm.JOSMFixture;
    1110import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     
    1413import org.openstreetmap.josm.gui.layer.TMSLayer;
    1514import org.openstreetmap.josm.gui.layer.TMSLayerTest;
     15import org.openstreetmap.josm.testutils.JOSMTestRules;
     16
     17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1618
    1719/**
     
    1921 */
    2022public class LayerVisibilityActionTest {
    21 
    2223    /**
    23      * Setup tests
     24     * TMS layer needs prefs. Platform for LayerListDialog shortcuts.
    2425     */
    25     @BeforeClass
    26     public static void setUpBeforeClass() {
    27         JOSMFixture.createUnitTestFixture().init(true);
    28     }
     26    @Rule
     27    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     28    public JOSMTestRules test = new JOSMTestRules().preferences().projection().platform();
    2929
    3030    /**
     
    3434    public void testLayerVisibilityAction() {
    3535        TMSLayer layer = TMSLayerTest.createTmsLayer();
    36         try {
    37             LayerListModel model = LayerListDialog.getInstance().getModel();
    38             LayerVisibilityAction action = new LayerVisibilityAction(model);
    39             action.updateEnabledState();
    40             assertFalse(action.isEnabled());
     36        LayerListModel model = new LayerListDialog(Main.getLayerManager()) {
     37            @Override
     38            protected void registerInWindowMenu() {
     39                // ignore
     40            }
     41        }.getModel();
     42        LayerVisibilityAction action = new LayerVisibilityAction(model);
     43        action.updateEnabledState();
     44        assertFalse(action.isEnabled());
    4145
    42             Main.getLayerManager().addLayer(layer);
    43             action.updateEnabledState();
    44             assertTrue(action.isEnabled());
    45             assertTrue(action.supportLayers(model.getSelectedLayers()));
     46        Main.getLayerManager().addLayer(layer);
     47        model.setSelectedLayer(layer);
     48        action.updateEnabledState();
     49        assertTrue(action.isEnabled());
     50        assertTrue(action.supportLayers(model.getSelectedLayers()));
    4651
    47             // now check values
    48             action.updateValues();
    49             assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
    50             assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
     52        // now check values
     53        action.updateValues();
     54        assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
     55        assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
    5156
    52             action.opacitySlider.setRealValue(.5);
    53             action.updateValues();
     57        action.opacitySlider.setRealValue(.5);
     58        action.updateValues();
    5459
    55             assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
    56             assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
     60        assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
     61        assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
    5762
    58             action.setVisibleFlag(false);
    59             action.updateValues();
    60             assertFalse(layer.isVisible());
     63        action.setVisibleFlag(false);
     64        action.updateValues();
     65        assertFalse(layer.isVisible());
    6166
    62             action.setVisibleFlag(true);
    63             action.updateValues();
    64             assertTrue(layer.isVisible());
     67        action.setVisibleFlag(true);
     68        action.updateValues();
     69        assertTrue(layer.isVisible());
    6570
    66             // layer stays visible during adjust
    67             action.opacitySlider.setValueIsAdjusting(true);
    68             action.opacitySlider.setRealValue(0);
    69             assertEquals(0, layer.getOpacity(), 1e-15);
    70             layer.setOpacity(.1); // to make layer.isVisible work
    71             assertTrue(layer.isVisible());
    72             layer.setOpacity(0);
     71        // layer stays visible during adjust
     72        action.opacitySlider.setValueIsAdjusting(true);
     73        action.opacitySlider.setRealValue(0);
     74        assertEquals(0, layer.getOpacity(), 1e-15);
     75        layer.setOpacity(.1); // to make layer.isVisible work
     76        assertTrue(layer.isVisible());
     77        layer.setOpacity(0);
    7378
    74             action.opacitySlider.setValueIsAdjusting(false);
    75             action.opacitySlider.setRealValue(0);
    76             assertEquals(0, layer.getOpacity(), 1e-15);
    77             layer.setOpacity(.1); // to make layer.isVisible work
    78             assertFalse(layer.isVisible());
    79             layer.setOpacity(0);
    80             action.updateValues();
     79        action.opacitySlider.setValueIsAdjusting(false);
     80        action.opacitySlider.setRealValue(0);
     81        assertEquals(0, layer.getOpacity(), 1e-15);
     82        layer.setOpacity(.1); // to make layer.isVisible work
     83        assertFalse(layer.isVisible());
     84        layer.setOpacity(0);
     85        action.updateValues();
    8186
    82             // Opacity reset when it was 0 and user set layer to visible.
    83             action.setVisibleFlag(true);
    84             action.updateValues();
    85             assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
    86             assertEquals(1.0, layer.getOpacity(), 1e-15);
    87 
    88         } finally {
    89             Main.getLayerManager().removeLayer(layer);
    90         }
     87        // Opacity reset when it was 0 and user set layer to visible.
     88        action.setVisibleFlag(true);
     89        action.updateValues();
     90        assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
     91        assertEquals(1.0, layer.getOpacity(), 1e-15);
    9192    }
    9293}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java

    r10436 r10467  
    1111import java.util.Collection;
    1212import java.util.HashMap;
     13import java.util.TimeZone;
    1314
    1415import javax.swing.JScrollPane;
     
    171172                new ImmutableGpxTrack(new ArrayList<Collection<WayPoint>>(), new HashMap<String, Object>())));
    172173
     174        assertEquals("1/3/16 11:59 AM - 12:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next()));
     175
     176        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    173177        assertEquals("1/3/16 12:59 PM - 1:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next()));
    174178    }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java

    r10397 r10467  
    1111import static org.junit.Assert.fail;
    1212
     13import java.awt.Component;
     14import java.awt.Graphics;
    1315import java.awt.Graphics2D;
    1416import java.lang.reflect.InvocationTargetException;
     
    4143public class LayerManagerTest {
    4244
    43     protected static class AbstractTestLayer extends Layer {
    44         protected AbstractTestLayer() {
     45    /**
     46     * This is a layer that can be used in tests. It does not do anything and provides a simple, fake implementation.
     47     * @author Michael Zangl
     48     */
     49    public static class TestLayer extends Layer {
     50        /**
     51         * Create a new test layer.
     52         */
     53        public TestLayer() {
    4554            super("Test Layer");
    4655        }
     
    7079        @Override
    7180        public Action[] getMenuEntries() {
    72             return null;
     81            return new Action[0];
    7382        }
    7483
     
    8089        @Override
    8190        public Icon getIcon() {
    82             return null;
     91            return new Icon() {
     92                @Override
     93                public void paintIcon(Component c, Graphics g, int x, int y) {
     94                    // nop
     95                }
     96
     97                @Override
     98                public int getIconWidth() {
     99                    return 10;
     100                }
     101
     102                @Override
     103                public int getIconHeight() {
     104                    return 10;
     105                }
     106            };
    83107        }
    84108
     
    89113    }
    90114
    91     protected static class AbstractTestLayer2 extends AbstractTestLayer {}
     115    protected static class TestLayer2 extends TestLayer {}
    92116
    93117    /**
     
    147171    @Test
    148172    public void testAddLayer() {
    149         Layer layer1 = new AbstractTestLayer() {
     173        Layer layer1 = new TestLayer() {
    150174            @Override
    151175            public LayerPositionStrategy getDefaultLayerPosition() {
     
    158182            }
    159183        };
    160         Layer layer2 = new AbstractTestLayer() {
     184        Layer layer2 = new TestLayer() {
    161185            @Override
    162186            public LayerPositionStrategy getDefaultLayerPosition() {
     
    164188            }
    165189        };
    166         Layer layer3 = new AbstractTestLayer() {
     190        Layer layer3 = new TestLayer() {
    167191            @Override
    168192            public LayerPositionStrategy getDefaultLayerPosition() {
     
    179203
    180204        // event
    181         AbstractTestLayer layer4 = new AbstractTestLayer();
     205        TestLayer layer4 = new TestLayer();
    182206        CapturingLayerChangeListener l = new CapturingLayerChangeListener();
    183207        layerManager.addLayerChangeListener(l);
     
    198222        thrown.expectRootCause(any(IllegalArgumentException.class));
    199223
    200         AbstractTestLayer layer1 = new AbstractTestLayer();
     224        TestLayer layer1 = new TestLayer();
    201225        layerManager.addLayer(layer1);
    202226        layerManager.addLayer(layer1);
     
    212236        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    213237
    214         AbstractTestLayer layer1 = new AbstractTestLayer() {
     238        TestLayer layer1 = new TestLayer() {
    215239            @Override
    216240            public LayerPositionStrategy getDefaultLayerPosition() {
     
    231255    @Test
    232256    public void testRemoveLayer() {
    233         AbstractTestLayer layer1 = new AbstractTestLayer();
    234         AbstractTestLayer layer2 = new AbstractTestLayer();
     257        TestLayer layer1 = new TestLayer();
     258        TestLayer layer2 = new TestLayer();
    235259        layerManager.addLayer(layer1);
    236260        layerManager.addLayer(layer2);
     
    252276    @Test
    253277    public void testMoveLayer() {
    254         AbstractTestLayer layer1 = new AbstractTestLayer();
    255         AbstractTestLayer layer2 = new AbstractTestLayer();
     278        TestLayer layer1 = new TestLayer();
     279        TestLayer layer2 = new TestLayer();
    256280        layerManager.addLayer(layer1);
    257281        layerManager.addLayer(layer2);
     
    284308        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    285309
    286         AbstractTestLayer layer1 = new AbstractTestLayer();
    287         AbstractTestLayer layer2 = new AbstractTestLayer();
     310        TestLayer layer1 = new TestLayer();
     311        TestLayer layer2 = new TestLayer();
    288312        layerManager.addLayer(layer1);
    289313        layerManager.addLayer(layer2);
     
    300324        thrown.expectRootCause(any(IllegalArgumentException.class));
    301325
    302         AbstractTestLayer layer1 = new AbstractTestLayer();
    303         AbstractTestLayer layer2 = new AbstractTestLayer();
     326        TestLayer layer1 = new TestLayer();
     327        TestLayer layer2 = new TestLayer();
    304328        layerManager.addLayer(layer1);
    305329        layerManager.moveLayer(layer2, 0);
     
    312336    public void testGetLayers() {
    313337        // list should be immutable
    314         AbstractTestLayer layer1 = new AbstractTestLayer();
    315         AbstractTestLayer layer2 = new AbstractTestLayer();
     338        TestLayer layer1 = new TestLayer();
     339        TestLayer layer2 = new TestLayer();
    316340        layerManager.addLayer(layer1);
    317341        layerManager.addLayer(layer2);
     
    324348    @Test
    325349    public void testGetLayersOfType() {
    326         AbstractTestLayer2 layer1 = new AbstractTestLayer2();
    327         AbstractTestLayer2 layer2 = new AbstractTestLayer2();
    328         layerManager.addLayer(layer1);
    329         layerManager.addLayer(new AbstractTestLayer());
    330         layerManager.addLayer(layer2);
    331 
    332         assertEquals(layerManager.getLayersOfType(AbstractTestLayer2.class), Arrays.asList(layer1, layer2));
     350        TestLayer2 layer1 = new TestLayer2();
     351        TestLayer2 layer2 = new TestLayer2();
     352        layerManager.addLayer(layer1);
     353        layerManager.addLayer(new TestLayer());
     354        layerManager.addLayer(layer2);
     355
     356        assertEquals(layerManager.getLayersOfType(TestLayer2.class), Arrays.asList(layer1, layer2));
    333357    }
    334358
     
    338362    @Test
    339363    public void testContainsLayer() {
    340         AbstractTestLayer layer = new AbstractTestLayer();
     364        TestLayer layer = new TestLayer();
    341365        layerManager.addLayer(layer);
    342         layerManager.addLayer(new AbstractTestLayer());
     366        layerManager.addLayer(new TestLayer());
    343367
    344368        assertTrue(layerManager.containsLayer(layer));
    345         assertFalse(layerManager.containsLayer(new AbstractTestLayer()));
     369        assertFalse(layerManager.containsLayer(new TestLayer()));
    346370    }
    347371
     
    374398    public void testAddLayerChangeListenerFire() {
    375399        final ArrayList<Layer> fired = new ArrayList<>();
    376         AbstractTestLayer layer1 = new AbstractTestLayer();
    377         AbstractTestLayer layer2 = new AbstractTestLayer();
     400        TestLayer layer1 = new TestLayer();
     401        TestLayer layer2 = new TestLayer();
    378402        layerManager.addLayer(layer1);
    379403        layerManager.addLayer(layer2);
     
    405429        CapturingLayerChangeListener l = new CapturingLayerChangeListener();
    406430        layerManager.addLayerChangeListener(l);
    407         layerManager.addLayer(new AbstractTestLayer());
     431        layerManager.addLayer(new TestLayer());
    408432        layerManager.removeLayerChangeListener(l);
    409         layerManager.addLayer(new AbstractTestLayer());
     433        layerManager.addLayer(new TestLayer());
    410434        // threw exception when fired twice.
    411435        assertNotNull(l.layerAdded);
     
    429453    public void testRemoveLayerChangeListenerFire() {
    430454        final ArrayList<Layer> fired = new ArrayList<>();
    431         AbstractTestLayer layer1 = new AbstractTestLayer();
    432         AbstractTestLayer layer2 = new AbstractTestLayer();
     455        TestLayer layer1 = new TestLayer();
     456        TestLayer layer2 = new TestLayer();
    433457        layerManager.addLayer(layer1);
    434458        layerManager.addLayer(layer2);
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java

    r10332 r10467  
    6868    @Test
    6969    public void testAddLayerSetsActiveLayer() {
    70         AbstractTestLayer layer1 = new AbstractTestLayer();
    71         AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    72         AbstractTestLayer layer3 = new AbstractTestLayer();
     70        TestLayer layer1 = new TestLayer();
     71        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
     72        TestLayer layer3 = new TestLayer();
    7373        assertNull(layerManagerWithActive.getActiveLayer());
    7474        assertNull(layerManagerWithActive.getEditLayer());
     
    8686    @Test
    8787    public void testRemoveLayerUnsetsActiveLayer() {
    88         AbstractTestLayer layer1 = new AbstractTestLayer();
    89         AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    90         AbstractTestLayer layer3 = new AbstractTestLayer();
     88        TestLayer layer1 = new TestLayer();
     89        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
     90        TestLayer layer3 = new TestLayer();
    9191        AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer();
    9292        layerManagerWithActive.addLayer(layer1);
     
    116116    @Test
    117117    public void testAddActiveLayerChangeListener() {
    118         AbstractTestLayer layer1 = new AbstractTestLayer();
     118        TestLayer layer1 = new TestLayer();
    119119        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    120120        layerManagerWithActive.addLayer(layer1);
     
    154154    @Test
    155155    public void testRemoveActiveLayerChangeListener() {
    156         AbstractTestLayer layer1 = new AbstractTestLayer();
     156        TestLayer layer1 = new TestLayer();
    157157        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    158158        layerManagerWithActive.addLayer(layer1);
     
    182182    @Test
    183183    public void testSetGetActiveLayer() {
    184         AbstractTestLayer layer1 = new AbstractTestLayer();
    185         AbstractTestLayer layer2 = new AbstractTestLayer();
     184        TestLayer layer1 = new TestLayer();
     185        TestLayer layer2 = new TestLayer();
    186186        layerManagerWithActive.addLayer(layer1);
    187187        layerManagerWithActive.addLayer(layer2);
     
    200200    public void testGetEditDataSet() {
    201201        assertNull(layerManagerWithActive.getEditDataSet());
    202         AbstractTestLayer layer0 = new AbstractTestLayer();
     202        TestLayer layer0 = new TestLayer();
    203203        layerManagerWithActive.addLayer(layer0);
    204204        assertNull(layerManagerWithActive.getEditDataSet());
     
    223223        AbstractTestOsmLayer layer1 = new AbstractTestOsmLayer();
    224224        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    225         AbstractTestLayer layer3 = new AbstractTestLayer();
     225        TestLayer layer3 = new TestLayer();
    226226        layer3.setVisible(false);
    227227        AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer();
    228         AbstractTestLayer layer5 = new AbstractTestLayer();
     228        TestLayer layer5 = new TestLayer();
    229229        AbstractTestOsmLayer layer6 = new AbstractTestOsmLayer();
    230230        AbstractTestOsmLayer layer7 = new AbstractTestOsmLayer();
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    r10436 r10467  
    1010import java.util.List;
    1111
    12 import org.junit.BeforeClass;
     12import org.junit.Rule;
    1313import org.junit.Test;
    14 import org.openstreetmap.josm.JOSMFixture;
    1514import org.openstreetmap.josm.Main;
    1615import org.openstreetmap.josm.TestUtils;
     
    1817import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader;
    1918import org.openstreetmap.josm.io.GpxReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
     
    2325 */
    2426public class GeoImageLayerTest {
     27    /**
     28     * We need prefs for this.
     29     */
     30    @Rule
     31    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     32    public JOSMTestRules test = new JOSMTestRules().preferences();
    2533
    26     /**
    27      * Setup test.
    28      */
    29     @BeforeClass
    30     public static void setUpBeforeClass() {
    31         JOSMFixture.createUnitTestFixture().init(true);
    32     }
    3334
    3435    /**
     
    4243            assertTrue(reader.parse(true));
    4344            GpxLayer gpxLayer = new GpxLayer(reader.getGpxData());
    44             try {
    45                 Main.getLayerManager().addLayer(gpxLayer);
    46                 assertEquals(1, Main.getLayerManager().getLayers().size());
    47                 new Loader(
    48                         Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
    49                         gpxLayer).run();
    50                 assertEquals(2, Main.getLayerManager().getLayers().size());
    51                 GeoImageLayer layer = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).iterator().next();
    52                 try {
    53                     assertEquals(gpxLayer, layer.getGpxLayer());
    54                     List<ImageEntry> images = layer.getImages();
    55                     assertEquals(1, images.size());
    56                     assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
    57                     assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
    58                 } finally {
    59                     // Ensure we clean the place before leaving, even if test fails.
    60                     Main.getLayerManager().removeLayer(layer);
    61                 }
    62             } finally {
    63                 // Ensure we clean the place before leaving, even if test fails.
    64                 Main.getLayerManager().removeLayer(gpxLayer);
    65             }
     45            Main.getLayerManager().addLayer(gpxLayer);
     46            assertEquals(1, Main.getLayerManager().getLayers().size());
     47            new Loader(
     48                    Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
     49                    gpxLayer).run();
     50            assertEquals(2, Main.getLayerManager().getLayers().size());
     51            GeoImageLayer layer = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).iterator().next();
     52            assertEquals(gpxLayer, layer.getGpxLayer());
     53            List<ImageEntry> images = layer.getImages();
     54            assertEquals(1, images.size());
     55            assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
     56            assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
    6657        }
    6758    }
  • trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java

    r9958 r10467  
    88import java.util.ArrayList;
    99import java.util.List;
     10import java.util.TimeZone;
    1011
    1112import org.junit.Test;
     
    4041        assertEquals(0, in.getParserMalformed());
    4142
     43        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    4244        final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
    4345        assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r10445 r10467  
    44import java.io.File;
    55import java.io.IOException;
     6import java.util.TimeZone;
    67
    78import org.junit.rules.DisableOnDebug;
     
    163164        // Tests are running headless by default.
    164165        System.setProperty("java.awt.headless", "true");
     166        // All tests use the same timezone.
     167        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     168        // Set log level to info
     169        Main.logLevel = 3;
    165170
    166171        // Set up i18n
Note: See TracChangeset for help on using the changeset viewer.