source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/DuplicateActionTest.java

Last change on this file was 18690, checked in by taylor.smock, 16 months ago

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.layer;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotEquals;
6import static org.junit.jupiter.api.Assertions.assertNotNull;
7import static org.junit.jupiter.api.Assertions.assertNull;
8
9import java.io.InputStream;
10
11import org.openstreetmap.josm.TestUtils;
12import org.openstreetmap.josm.gui.MainApplication;
13import org.openstreetmap.josm.gui.layer.OsmDataLayer;
14import org.openstreetmap.josm.io.OsmReader;
15import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
16
17import org.junit.jupiter.api.Test;
18
19/**
20 * Unit tests of {@link DuplicateAction} class.
21 */
22// TMS layer needs prefs. Platform for LayerListDialog shortcuts.
23@BasicPreferences
24class DuplicateActionTest {
25 /**
26 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/4539">#4539</a>.
27 * @throws Exception if an error occurs
28 */
29 @Test
30 void testTicket4539() throws Exception {
31 try (InputStream is = TestUtils.getRegressionDataStream(4539, "josm_error_#4539.osm.zip")) {
32 OsmDataLayer layer = new OsmDataLayer(OsmReader.parseDataSet(is, null), null, null);
33 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
34 assertNull(editLayer);
35 try {
36 new DuplicateAction(layer, null).actionPerformed(null);
37 editLayer = MainApplication.getLayerManager().getEditLayer();
38 assertNotNull(editLayer);
39 assertNotEquals(layer, editLayer);
40 assertEquals(layer.data.getNodes().size(), editLayer.data.getNodes().size());
41 assertEquals(layer.data.getWays().size(), editLayer.data.getWays().size());
42 assertEquals(layer.data.getRelations().size(), editLayer.data.getRelations().size());
43 } finally {
44 // Ensure we clean the place before leaving, even if test fails.
45 if (editLayer != null) {
46 MainApplication.getLayerManager().removeLayer(editLayer);
47 }
48 }
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.