Changeset 10467 in josm for trunk/test
- Timestamp:
- 2016-06-24T00:30:42+02:00 (8 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
r10443 r10467 12 12 import java.text.MessageFormat; 13 13 import java.util.Locale; 14 import java.util.TimeZone; 14 15 15 16 import org.openstreetmap.josm.data.projection.Projections; 16 17 import org.openstreetmap.josm.gui.MainApplication; 18 import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer; 17 19 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 18 20 import org.openstreetmap.josm.gui.util.GuiHelper; … … 88 90 } 89 91 System.setProperty("josm.home", josmHome); 92 TimeZone.setDefault(TimeZone.getTimeZone("UTC")); 90 93 Main.initApplicationPreferences(); 91 94 Main.pref.enableSaveOnPut(false); … … 96 99 Main.platform.preStartupHook(); 97 100 101 Main.logLevel = 3; 98 102 Main.pref.init(false); 99 103 I18n.set(Main.pref.get("language", "en")); … … 127 131 128 132 private void setupGUI() { 133 Main.getLayerManager().resetState(); 134 assertTrue(Main.getLayerManager().getLayers().isEmpty()); 135 assertNull(Main.getLayerManager().getEditLayer()); 136 assertNull(Main.getLayerManager().getActiveLayer()); 137 129 138 if (Main.toolbar == null) { 130 139 Main.toolbar = new ToolbarPreferences(); … … 133 142 new MainApplication().initialize(); 134 143 } 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()); 139 146 } 140 147 } -
trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java
r10447 r10467 92 92 Date fixed = cal.getTime(); 93 93 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++) { 95 96 // Only retry 2 indexes to avoid 1000*1000 disk operations 96 97 File f = task.getNewLayerFile(info, fixed, Math.max(0, i - 2)); -
trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy
r9829 r10467 37 37 " <tag key='language' value='en'/>%n" + 38 38 " <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")) 41 41 } 42 42 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
r8863 r10467 17 17 18 18 import org.junit.Before; 19 import org.junit.Rule; 19 20 import org.junit.Test; 20 import org.openstreetmap.josm.JOSMFixture;21 21 import org.openstreetmap.josm.data.osm.Tag; 22 22 import org.openstreetmap.josm.data.validation.Severity; … … 25 25 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; 26 26 import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem; 27 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 29 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 27 30 28 31 /** 29 32 * JUnit Test of "Opening hours" validation test. 33 * @see OpeningHourTest 30 34 */ 31 35 public 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; 34 44 35 45 /** … … 39 49 @Before 40 50 public void setUp() throws Exception { 41 JOSMFixture.createUnitTestFixture().init();42 OPENING_HOUR_TEST.initialize();51 openingHourTest = new OpeningHourTest(); 52 openingHourTest.initialize(); 43 53 } 44 54 … … 50 60 final String key = "opening_hours"; 51 61 // 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( 59 69 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( 61 71 key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue()); 62 72 } … … 64 74 @Test 65 75 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") 67 77 .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") 69 79 .get(0).toString().contains("Unerwartetes Zeichen")); 70 80 } … … 76 86 public void testCheckOpeningHourSyntax2() { 77 87 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"); 79 89 assertThat(errors, hasSize(2)); 80 90 assertEquals(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage()); … … 92 102 public void testCheckOpeningHourSyntax3() { 93 103 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"); 95 105 assertThat(errors, hasSize(2)); 96 106 assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage()); … … 106 116 @Test 107 117 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()); 111 121 } 112 122 … … 117 127 public void testCheckOpeningHourSyntax5() { 118 128 final String key = "opening_hours"; 119 assertThat( OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1));129 assertThat(openingHourTest.checkOpeningHourSyntax(key, "badtext"), hasSize(1)); 120 130 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)); 123 133 assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. " 124 134 + "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()); 126 136 } 127 137 … … 132 142 public void testCheckOpeningHourSyntax6() { 133 143 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()); 135 145 } 136 146 … … 141 151 public void testCheckOpeningHourSyntax7() { 142 152 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()); 146 156 } 147 157 … … 152 162 public void testCheckOpeningHourSyntaxTicket9367() { 153 163 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()); 155 165 assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. " 156 166 + "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()); 159 169 } 160 170 … … 166 176 final String key = "service_times"; 167 177 // 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", 173 183 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", 175 185 OpeningHourTest.CheckMode.BOTH), hasSize(1)); 176 186 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", 178 188 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 179 189 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", 181 191 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 182 192 } … … 189 199 final String key = "collection_times"; 190 200 // 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", 195 205 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", 197 207 OpeningHourTest.CheckMode.BOTH), hasSize(1)); 198 208 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", 200 210 OpeningHourTest.CheckMode.BOTH).get(0).getSeverity()); 201 211 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", 203 213 OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue()); 204 214 } … … 222 232 } 223 233 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()); 225 235 assertThat(t + " is valid", errors, isEmpty()); 226 236 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java
r10396 r10467 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import org.junit. BeforeClass;8 import org.junit.Rule; 9 9 import org.junit.Test; 10 import org.openstreetmap.josm.JOSMFixture;11 10 import org.openstreetmap.josm.Main; 12 11 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 14 13 import org.openstreetmap.josm.gui.layer.TMSLayer; 15 14 import org.openstreetmap.josm.gui.layer.TMSLayerTest; 15 import org.openstreetmap.josm.testutils.JOSMTestRules; 16 17 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 16 18 17 19 /** … … 19 21 */ 20 22 public class LayerVisibilityActionTest { 21 22 23 /** 23 * Setup tests24 * TMS layer needs prefs. Platform for LayerListDialog shortcuts. 24 25 */ 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(); 29 29 30 30 /** … … 34 34 public void testLayerVisibilityAction() { 35 35 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()); 41 45 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())); 46 51 47 48 49 50 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()); 51 56 52 53 57 action.opacitySlider.setRealValue(.5); 58 action.updateValues(); 54 59 55 56 60 assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15); 61 assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString()); 57 62 58 59 60 63 action.setVisibleFlag(false); 64 action.updateValues(); 65 assertFalse(layer.isVisible()); 61 66 62 63 64 67 action.setVisibleFlag(true); 68 action.updateValues(); 69 assertTrue(layer.isVisible()); 65 70 66 67 68 69 70 71 72 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); 73 78 74 75 76 77 78 79 80 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(); 81 86 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); 91 92 } 92 93 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java
r10436 r10467 11 11 import java.util.Collection; 12 12 import java.util.HashMap; 13 import java.util.TimeZone; 13 14 14 15 import javax.swing.JScrollPane; … … 171 172 new ImmutableGpxTrack(new ArrayList<Collection<WayPoint>>(), new HashMap<String, Object>()))); 172 173 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")); 173 177 assertEquals("1/3/16 12:59 PM - 1:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next())); 174 178 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java
r10397 r10467 11 11 import static org.junit.Assert.fail; 12 12 13 import java.awt.Component; 14 import java.awt.Graphics; 13 15 import java.awt.Graphics2D; 14 16 import java.lang.reflect.InvocationTargetException; … … 41 43 public class LayerManagerTest { 42 44 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() { 45 54 super("Test Layer"); 46 55 } … … 70 79 @Override 71 80 public Action[] getMenuEntries() { 72 return n ull;81 return new Action[0]; 73 82 } 74 83 … … 80 89 @Override 81 90 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 }; 83 107 } 84 108 … … 89 113 } 90 114 91 protected static class AbstractTestLayer2 extends AbstractTestLayer {}115 protected static class TestLayer2 extends TestLayer {} 92 116 93 117 /** … … 147 171 @Test 148 172 public void testAddLayer() { 149 Layer layer1 = new AbstractTestLayer() {173 Layer layer1 = new TestLayer() { 150 174 @Override 151 175 public LayerPositionStrategy getDefaultLayerPosition() { … … 158 182 } 159 183 }; 160 Layer layer2 = new AbstractTestLayer() {184 Layer layer2 = new TestLayer() { 161 185 @Override 162 186 public LayerPositionStrategy getDefaultLayerPosition() { … … 164 188 } 165 189 }; 166 Layer layer3 = new AbstractTestLayer() {190 Layer layer3 = new TestLayer() { 167 191 @Override 168 192 public LayerPositionStrategy getDefaultLayerPosition() { … … 179 203 180 204 // event 181 AbstractTestLayer layer4 = new AbstractTestLayer();205 TestLayer layer4 = new TestLayer(); 182 206 CapturingLayerChangeListener l = new CapturingLayerChangeListener(); 183 207 layerManager.addLayerChangeListener(l); … … 198 222 thrown.expectRootCause(any(IllegalArgumentException.class)); 199 223 200 AbstractTestLayer layer1 = new AbstractTestLayer();224 TestLayer layer1 = new TestLayer(); 201 225 layerManager.addLayer(layer1); 202 226 layerManager.addLayer(layer1); … … 212 236 thrown.expectRootCause(any(IndexOutOfBoundsException.class)); 213 237 214 AbstractTestLayer layer1 = new AbstractTestLayer() {238 TestLayer layer1 = new TestLayer() { 215 239 @Override 216 240 public LayerPositionStrategy getDefaultLayerPosition() { … … 231 255 @Test 232 256 public void testRemoveLayer() { 233 AbstractTestLayer layer1 = new AbstractTestLayer();234 AbstractTestLayer layer2 = new AbstractTestLayer();257 TestLayer layer1 = new TestLayer(); 258 TestLayer layer2 = new TestLayer(); 235 259 layerManager.addLayer(layer1); 236 260 layerManager.addLayer(layer2); … … 252 276 @Test 253 277 public void testMoveLayer() { 254 AbstractTestLayer layer1 = new AbstractTestLayer();255 AbstractTestLayer layer2 = new AbstractTestLayer();278 TestLayer layer1 = new TestLayer(); 279 TestLayer layer2 = new TestLayer(); 256 280 layerManager.addLayer(layer1); 257 281 layerManager.addLayer(layer2); … … 284 308 thrown.expectRootCause(any(IndexOutOfBoundsException.class)); 285 309 286 AbstractTestLayer layer1 = new AbstractTestLayer();287 AbstractTestLayer layer2 = new AbstractTestLayer();310 TestLayer layer1 = new TestLayer(); 311 TestLayer layer2 = new TestLayer(); 288 312 layerManager.addLayer(layer1); 289 313 layerManager.addLayer(layer2); … … 300 324 thrown.expectRootCause(any(IllegalArgumentException.class)); 301 325 302 AbstractTestLayer layer1 = new AbstractTestLayer();303 AbstractTestLayer layer2 = new AbstractTestLayer();326 TestLayer layer1 = new TestLayer(); 327 TestLayer layer2 = new TestLayer(); 304 328 layerManager.addLayer(layer1); 305 329 layerManager.moveLayer(layer2, 0); … … 312 336 public void testGetLayers() { 313 337 // list should be immutable 314 AbstractTestLayer layer1 = new AbstractTestLayer();315 AbstractTestLayer layer2 = new AbstractTestLayer();338 TestLayer layer1 = new TestLayer(); 339 TestLayer layer2 = new TestLayer(); 316 340 layerManager.addLayer(layer1); 317 341 layerManager.addLayer(layer2); … … 324 348 @Test 325 349 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)); 333 357 } 334 358 … … 338 362 @Test 339 363 public void testContainsLayer() { 340 AbstractTestLayer layer = new AbstractTestLayer();364 TestLayer layer = new TestLayer(); 341 365 layerManager.addLayer(layer); 342 layerManager.addLayer(new AbstractTestLayer());366 layerManager.addLayer(new TestLayer()); 343 367 344 368 assertTrue(layerManager.containsLayer(layer)); 345 assertFalse(layerManager.containsLayer(new AbstractTestLayer()));369 assertFalse(layerManager.containsLayer(new TestLayer())); 346 370 } 347 371 … … 374 398 public void testAddLayerChangeListenerFire() { 375 399 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(); 378 402 layerManager.addLayer(layer1); 379 403 layerManager.addLayer(layer2); … … 405 429 CapturingLayerChangeListener l = new CapturingLayerChangeListener(); 406 430 layerManager.addLayerChangeListener(l); 407 layerManager.addLayer(new AbstractTestLayer());431 layerManager.addLayer(new TestLayer()); 408 432 layerManager.removeLayerChangeListener(l); 409 layerManager.addLayer(new AbstractTestLayer());433 layerManager.addLayer(new TestLayer()); 410 434 // threw exception when fired twice. 411 435 assertNotNull(l.layerAdded); … … 429 453 public void testRemoveLayerChangeListenerFire() { 430 454 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(); 433 457 layerManager.addLayer(layer1); 434 458 layerManager.addLayer(layer2); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java
r10332 r10467 68 68 @Test 69 69 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(); 73 73 assertNull(layerManagerWithActive.getActiveLayer()); 74 74 assertNull(layerManagerWithActive.getEditLayer()); … … 86 86 @Test 87 87 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(); 91 91 AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer(); 92 92 layerManagerWithActive.addLayer(layer1); … … 116 116 @Test 117 117 public void testAddActiveLayerChangeListener() { 118 AbstractTestLayer layer1 = new AbstractTestLayer();118 TestLayer layer1 = new TestLayer(); 119 119 AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer(); 120 120 layerManagerWithActive.addLayer(layer1); … … 154 154 @Test 155 155 public void testRemoveActiveLayerChangeListener() { 156 AbstractTestLayer layer1 = new AbstractTestLayer();156 TestLayer layer1 = new TestLayer(); 157 157 AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer(); 158 158 layerManagerWithActive.addLayer(layer1); … … 182 182 @Test 183 183 public void testSetGetActiveLayer() { 184 AbstractTestLayer layer1 = new AbstractTestLayer();185 AbstractTestLayer layer2 = new AbstractTestLayer();184 TestLayer layer1 = new TestLayer(); 185 TestLayer layer2 = new TestLayer(); 186 186 layerManagerWithActive.addLayer(layer1); 187 187 layerManagerWithActive.addLayer(layer2); … … 200 200 public void testGetEditDataSet() { 201 201 assertNull(layerManagerWithActive.getEditDataSet()); 202 AbstractTestLayer layer0 = new AbstractTestLayer();202 TestLayer layer0 = new TestLayer(); 203 203 layerManagerWithActive.addLayer(layer0); 204 204 assertNull(layerManagerWithActive.getEditDataSet()); … … 223 223 AbstractTestOsmLayer layer1 = new AbstractTestOsmLayer(); 224 224 AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer(); 225 AbstractTestLayer layer3 = new AbstractTestLayer();225 TestLayer layer3 = new TestLayer(); 226 226 layer3.setVisible(false); 227 227 AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer(); 228 AbstractTestLayer layer5 = new AbstractTestLayer();228 TestLayer layer5 = new TestLayer(); 229 229 AbstractTestOsmLayer layer6 = new AbstractTestOsmLayer(); 230 230 AbstractTestOsmLayer layer7 = new AbstractTestOsmLayer(); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java
r10436 r10467 10 10 import java.util.List; 11 11 12 import org.junit. BeforeClass;12 import org.junit.Rule; 13 13 import org.junit.Test; 14 import org.openstreetmap.josm.JOSMFixture;15 14 import org.openstreetmap.josm.Main; 16 15 import org.openstreetmap.josm.TestUtils; … … 18 17 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader; 19 18 import org.openstreetmap.josm.io.GpxReader; 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 20 22 21 23 /** … … 23 25 */ 24 26 public 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(); 25 33 26 /**27 * Setup test.28 */29 @BeforeClass30 public static void setUpBeforeClass() {31 JOSMFixture.createUnitTestFixture().init(true);32 }33 34 34 35 /** … … 42 43 assertTrue(reader.parse(true)); 43 44 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()); 66 57 } 67 58 } -
trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java
r9958 r10467 8 8 import java.util.ArrayList; 9 9 import java.util.List; 10 import java.util.TimeZone; 10 11 11 12 import org.junit.Test; … … 40 41 assertEquals(0, in.getParserMalformed()); 41 42 43 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); 42 44 final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints()); 43 45 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 4 4 import java.io.File; 5 5 import java.io.IOException; 6 import java.util.TimeZone; 6 7 7 8 import org.junit.rules.DisableOnDebug; … … 163 164 // Tests are running headless by default. 164 165 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; 165 170 166 171 // Set up i18n
Note:
See TracChangeset
for help on using the changeset viewer.