Changeset 10467 in josm for trunk/test/unit/org


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

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

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • 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.