Skip to content

Commit

Permalink
See #16567: Update to JUnit 5
Browse files Browse the repository at this point in the history
This removes `new JOSMTestRules()` with no additional setup and most
`JOSMFixture` calls.

Removing the bare JOSMTestRules speeds up the test suite since there are two
fewer `System.gc()` calls per test.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18853 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Oct 3, 2023
1 parent f7f588b commit 963e99b
Show file tree
Hide file tree
Showing 187 changed files with 143 additions and 2,228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@

import java.io.IOException;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.openstreetmap.josm.JOSMFixture;
import org.junit.jupiter.api.Test;

/**
* Tests the {@link GettingStarted} class.
*/
class GettingStartedTest {

/**
* Setup test.
*/
@BeforeAll
public static void init() {
JOSMFixture.createFunctionalTestFixture().init();
}

/**
* Tests that image links are replaced.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import javax.swing.JFrame;

import org.junit.jupiter.api.BeforeAll;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
Expand All @@ -18,11 +17,6 @@

class HistoryBrowserTestFT extends JFrame {

@BeforeAll
public static void init() {
JOSMFixture.createFunctionalTestFixture().init();
}

private HistoryBrowser browser;

protected void build() {
Expand Down Expand Up @@ -56,7 +50,7 @@ protected void populate(OsmPrimitiveType type, long id) {
}

public static void main(String[] args) {
HistoryBrowserTestFT.init();
JOSMFixture.createFunctionalTestFixture().init();
new HistoryBrowserTestFT().setVisible(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,25 @@

import javax.swing.ImageIcon;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
import org.openstreetmap.josm.gui.tagging.presets.items.Key;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.xml.sax.SAXException;

import com.kitfox.svg.SVGConst;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Unit tests of {@link ImageProvider} class.
*/
class ImageProviderTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

private static final class LogHandler14319 extends Handler {
boolean failed;

Expand All @@ -75,14 +62,6 @@ public void close() throws SecurityException {
}
}

/**
* Setup test.
*/
@BeforeAll
public static void setUp() {
JOSMFixture.createUnitTestFixture().init();
}

@BeforeEach
public void resetPixelDensity() {
GuiSizesHelper.setPixelDensity(1.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Integration tests of {@link ImageProvider} class.
*/
class ImageProviderTestIT {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Test fetching an image using {@code wiki://} protocol.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,18 @@
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.junit.jupiter.api.Test;

/**
* Unit tests of {@link ImageProvider} class for manual execution.
*/
class ImageProviderTestManual {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Test getting a cursor
* @throws InterruptedException in case of thread interruption
*/
@Disabled("manual execution only, as the look of the cursor cannot be checked automatedly")
@Disabled("manual execution only, as the look of the cursor cannot be checked automatically")
@Test
void testGetCursor() throws InterruptedException {
JFrame frame = new JFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.PerformanceTestUtils;
import org.openstreetmap.josm.PerformanceTestUtils.PerformanceTestTimer;
import org.openstreetmap.josm.data.osm.DataSet;
Expand All @@ -30,14 +28,6 @@
class OsmReaderPerformanceTest {
private static final int TIMES = 4;

/**
* Prepare the test.
*/
@BeforeAll
public static void createJOSMFixture() {
JOSMFixture.createPerformanceTestFixture().init(true);
}

/**
* Simulates a plain read of a .osm.bz2 file (from memory)
* @throws Exception if an error occurs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.io;

import org.junit.jupiter.api.BeforeAll;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.PerformanceTestUtils;
import org.openstreetmap.josm.PerformanceTestUtils.PerformanceTestTimer;
import org.openstreetmap.josm.data.osm.DataSet;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;

/**
* This test tests how fast we are at writing an OSM file.
* <p>
Expand All @@ -24,14 +22,6 @@ class OsmWriterPerformanceTest {
private static final int TIMES = 4;
private DataSet neubrandenburgDataSet;

/**
* Prepare the test.
*/
@BeforeAll
public static void createJOSMFixture() {
JOSMFixture.createPerformanceTestFixture().init(true);
}

/**
* Setup test
* @throws Exception if an error occurs
Expand Down
11 changes: 0 additions & 11 deletions test/unit/org/openstreetmap/josm/actions/CombineWayActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.osm.DataSet;
Expand All @@ -23,23 +22,13 @@
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.OsmReader;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import nl.jqno.equalsverifier.EqualsVerifier;

/**
* Unit tests for class {@link CombineWayAction}.
*/
class CombineWayActionTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Non-regression test for bug #11957.
* @throws IOException if any I/O error occurs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.data.osm.Tag;
import org.openstreetmap.josm.data.osm.Tagged;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Unit tests of {@link ReverseWayNoTagCorrector} class.
*/
class ReverseWayNoTagCorrectorTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Tests the {@link ReverseWayNoTagCorrector#getDirectionalTags} function
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,19 @@
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.data.correction.TagCorrection;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.OsmUtils;
import org.openstreetmap.josm.data.osm.Tag;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.trajano.commons.testing.UtilityClassTestUtil;

/**
* Unit tests of {@link ReverseWayTagCorrector} class.
*/
class ReverseWayTagCorrectorTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Tests that {@code ReverseWayTagCorrector.TagSwitcher} satisfies utility class criteria.
* @throws ReflectiveOperationException if an error occurs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.actions.downloadtasks;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.awt.Component;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Unit tests for class {@link ChangesetContentDownloadTask}.
*/
class ChangesetContentDownloadTaskTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules();

/**
* Unit test of {@code ChangesetContentDownloadTask#ChangesetContentDownloadTask}.
*/
Expand All @@ -33,9 +22,9 @@ void testChangesetContentDownloadTask() {
Component parent = new Component() {
// empty component
};
assertNotNull(new ChangesetContentDownloadTask(parent, 1));
assertNotNull(new ChangesetContentDownloadTask(parent, Arrays.asList(1, 2)));
assertNotNull(new ChangesetContentDownloadTask(parent, null));
assertDoesNotThrow(() -> new ChangesetContentDownloadTask(parent, 1));
assertDoesNotThrow(() -> new ChangesetContentDownloadTask(parent, Arrays.asList(1, 2)));
assertDoesNotThrow(() -> new ChangesetContentDownloadTask(parent, null));
}

/**
Expand All @@ -59,6 +48,7 @@ void testChangesetContentDownloadTaskNullParent1() {
*/
@Test
void testChangesetContentDownloadTaskNullParent2() {
assertThrows(IllegalArgumentException.class, () -> new ChangesetContentDownloadTask(Arrays.asList(1, 2)));
final List<Integer> toDownload = Arrays.asList(1, 2);
assertThrows(IllegalArgumentException.class, () -> new ChangesetContentDownloadTask(toDownload));
}
}
Loading

0 comments on commit 963e99b

Please sign in to comment.