Skip to content

Commit

Permalink
Fix #16567: Upgrade to JUnit 5
Browse files Browse the repository at this point in the history
JOSMTestRules and JOSMTestFixture can reset the default JOSM profile, which can
be unexpected for new contributors. This updates all tests to use JUnit 5 ''and''
the new JUnit 5 annotations.

This also renames MapCSSStyleSourceFilterTest to MapCSSStyleSourceFilterPerformanceTest
to match the naming convention for performance tests and fixes some lint issues.

This was tested by running all tests individually and together.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18893 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Nov 2, 2023
1 parent 3dee2d3 commit 4a3f6c3
Show file tree
Hide file tree
Showing 36 changed files with 563 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Locale;
Expand All @@ -25,7 +25,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.APIDataSet;
import org.openstreetmap.josm.data.coor.LatLon;
Expand All @@ -42,6 +41,8 @@
import org.openstreetmap.josm.data.projection.Projections;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.annotations.TestUser;
import org.openstreetmap.josm.tools.JosmRuntimeException;
import org.openstreetmap.josm.tools.Logging;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -51,6 +52,8 @@
* @since 1806
*/
@SuppressFBWarnings(value = "CRLF_INJECTION_LOGS")
@org.openstreetmap.josm.testutils.annotations.OsmApi(org.openstreetmap.josm.testutils.annotations.OsmApi.APIType.DEV)
@TestUser
class OsmServerBackreferenceReaderTest {
private static final Logger logger = Logger.getLogger(OsmServerBackreferenceReader.class.getName());

Expand All @@ -75,7 +78,7 @@ protected static Relation lookupRelation(DataSet ds, int i) {
if (("relation-" + i).equals(r.get("name"))) return r;
}
fail("Cannot find relation "+i);
return null;
throw new JosmRuntimeException("Cannot reach this point due to fail() above");
}

protected static void populateTestDataSetWithNodes(DataSet ds) {
Expand Down Expand Up @@ -165,8 +168,6 @@ public static void setUpBeforeClass() throws OsmTransferException, CyclicUploadD
}
logger.info("initializing ...");

JOSMFixture.createFunctionalTestFixture().init();

Config.getPref().put("osm-server.auth-method", "basic");

// don't use atomic upload, the test API server can't cope with large diff uploads
Expand Down Expand Up @@ -196,7 +197,7 @@ public static void setUpBeforeClass() throws OsmTransferException, CyclicUploadD

try (
PrintWriter pw = new PrintWriter(
new OutputStreamWriter(new FileOutputStream(dataSetCacheOutputFile), StandardCharsets.UTF_8)
new OutputStreamWriter(Files.newOutputStream(dataSetCacheOutputFile.toPath()), StandardCharsets.UTF_8)
)) {
logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
try (OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Projection
@Timeout(value = 15, unit = TimeUnit.MINUTES)
class MapCSSStyleSourceFilterTest {
class MapCSSStyleSourceFilterPerformanceTest {

private static final int TEST_RULE_COUNT = 10000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,17 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.HTTPS;

import com.github.tomakehurst.wiremock.WireMockServer;

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

/**
* Superclass of {@link DownloadGpsTaskTest}, {@link DownloadOsmTaskTest} and {@link DownloadNotesTaskTest}.
*/
@BasicWiremock
@HTTPS
public abstract class AbstractDownloadTaskTestParent {

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

/**
* HTTP mock.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.data.gpx.GpxData;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;

/**
* Unit tests for class {@link DownloadGpsTask}.
*/
@BasicWiremock
class DownloadGpsTaskTest extends AbstractDownloadTaskTestParent {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.data.osm.NoteData;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;

/**
* Unit tests for class {@link DownloadNotesTask}.
*/
@BasicWiremock
class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;

/**
* Unit tests for class {@link DownloadOsmTask}.
*/
@BasicWiremock
class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,21 @@
import java.util.Collections;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.Preferences;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.plugins.PluginDownloadTask;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.AssumeRevision;
import org.openstreetmap.josm.tools.Utils;

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

/**
* Unit tests for class {@link PluginDownloadTask}.
*/
@BasicWiremock
@BasicPreferences
@AssumeRevision("Revision: 8000\n")
class PluginDownloadTaskTest extends AbstractDownloadTaskTestParent {
protected String pluginPath;

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules testRule = new JOSMTestRules().https().assumeRevision(
"Revision: 8000\n"
);

@Override
protected String getRemoteContentType() {
return "application/java-archive";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,20 @@
import java.net.URL;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpRequest;
import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpResponse;
import org.openstreetmap.josm.data.oauth.SignpostAdapters.OAuthConsumer;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.HTTPS;
import org.openstreetmap.josm.tools.HttpClient;

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

/**
* Unit tests for class {@link SignpostAdapters}.
*/
@HTTPS
class SignpostAdaptersTest {

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

private static HttpClient newClient() throws MalformedURLException {
return HttpClient.create(new URL("https://www.openstreetmap.org"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.HTTPS;
import org.openstreetmap.josm.tools.Logging;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -57,15 +56,8 @@
*
* @version $Revision: 1723861 $
*/
@HTTPS
class DomainValidatorTestIT {

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

/**
* Download and process local copy of http://data.iana.org/TLD/tlds-alpha-by-domain.txt
* Check if the internal TLD table is up to date
Expand Down
28 changes: 14 additions & 14 deletions test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;

import mockit.Mock;
import mockit.MockUp;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.actions.OpenLocationAction;
Expand All @@ -56,26 +54,28 @@
import org.openstreetmap.josm.plugins.PluginListParseException;
import org.openstreetmap.josm.plugins.PluginListParser;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.HTTPS;
import org.openstreetmap.josm.testutils.annotations.Main;
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.PlatformManager;
import org.openstreetmap.josm.tools.Shortcut;
import org.openstreetmap.josm.tools.bugreport.BugReportQueue;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.openstreetmap.josm.tools.bugreport.BugReportQueue;
import mockit.Mock;
import mockit.MockUp;

/**
* Unit tests of {@link MainApplication} class.
*/
@HTTPS
@Main
@OsmApi(OsmApi.APIType.DEV)
@Projection
@Timeout(20)
public class MainApplicationTest {

/**
* Setup test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules().main().projection().https().devAPI().timeout(20000);

/**
* Make sure {@link MainApplication#contentPanePrivate} is initialized.
*/
Expand Down Expand Up @@ -248,7 +248,7 @@ private static PluginInformation newPluginInformation(String plugin) throws Plug
@Test
void testPostConstructorProcessCmdLineEmpty() {
// Check the method accepts no arguments
MainApplication.postConstructorProcessCmdLine(new ProgramArguments());
assertDoesNotThrow(() -> MainApplication.postConstructorProcessCmdLine(new ProgramArguments()));
}

private static void doTestPostConstructorProcessCmdLine(String download, String downloadGps, boolean gpx) {
Expand Down
Loading

0 comments on commit 4a3f6c3

Please sign in to comment.