Skip to content

Commit

Permalink
See #16567: Update to JUnit 5
Browse files Browse the repository at this point in the history
This converts most tests to use @annotations. There are also some performance
improvements as it relates to tests.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18870 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Oct 16, 2023
1 parent a7958a1 commit a9f8d35
Show file tree
Hide file tree
Showing 165 changed files with 997 additions and 1,761 deletions.
4 changes: 3 additions & 1 deletion src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ void initialize() {
Config.setUrlsProvider(JosmUrls.getInstance());
ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));

Territories.initializeInternalData();
if (Territories.getKnownIso3166Codes().isEmpty()) {
Territories.initializeInternalData();
}
OsmValidator.initialize();
MapPaintStyles.readFromPreferences();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public static void findIntersectingWay(Way w, Map<Point2D, List<WaySegment>> cel

List<Way> prims = Arrays.asList(es1.getWay(), es2.getWay());
if ((highlight = crossingWays.get(prims)) == null) {
highlight = new ArrayList<>();
highlight = new ArrayList<>(2);
highlight.add(es1);
highlight.add(es2);
crossingWays.put(prims, highlight);
Expand Down
13 changes: 2 additions & 11 deletions test/functional/org/openstreetmap/josm/data/BoundariesTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
import java.util.stream.Collectors;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.search.SearchCompiler;
import org.openstreetmap.josm.io.OsmReader;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;

/**
* Test of boundaries OSM file.
*/
@BasicPreferences
class BoundariesTestIT {

private static final List<String> RETIRED_ISO3166_1_CODES = Arrays.asList(
Expand All @@ -46,13 +44,6 @@ class BoundariesTestIT {
"US-PR", "US-RI", "US-SC", "US-SD", "US-TN", "US-TX", "US-UM", "US-UT", "US-VT", "US-VA", "US-VI", "US-WA", "US-WV", "US-WI",
"US-WY");

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

/**
* Test of boundaries OSM file.
* @throws Exception if an error occurs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@
import java.net.URL;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.tools.HttpClient;

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

/**
* Automatic test of imagery synchronization between JOSM and ELI.
* See <a href="https://josm.openstreetmap.de/wiki/ImageryCompare">JOSM wiki</a>
*/
@BasicPreferences
@Timeout(60)
class ImageryCompareTestIT {

private static final String BLACK_PREFIX = "<pre style=\"margin:3px;color:black\">";
private static final String RED_PREFIX = "<pre style=\"margin:3px;color:red\">";

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

/**
* Test of imagery entries.
* @throws Exception if an error occurs
Expand Down
28 changes: 9 additions & 19 deletions test/functional/org/openstreetmap/josm/data/osm/TaginfoTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,34 @@
import java.util.ArrayList;
import java.util.List;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.Timeout;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
import org.openstreetmap.josm.data.validation.tests.TagChecker;
import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.tools.HttpClient;
import org.xml.sax.SAXException;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;

/**
* Various integration tests with Taginfo.
*/
@BasicPreferences
@Timeout(20)
class TaginfoTestIT {

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

/**
* Checks that popular tags are known (i.e included in internal presets, or deprecated, or explicitely ignored)
* @throws SAXException if any XML parsing error occurs
* @throws IOException if any I/O error occurs
* @throws ParseException if any MapCSS parsing error occurs
*/
@Test
void testCheckPopularTags() throws SAXException, IOException, ParseException {
void testCheckPopularTags() throws IOException, ParseException {
TaggingPresets.readFromPreferences();
new TagChecker().initialize();
MapCSSTagChecker mapCssTagChecker = new MapCSSTagChecker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import javax.imageio.ImageIO;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openstreetmap.josm.TestUtils;
Expand All @@ -39,18 +38,19 @@
import org.openstreetmap.josm.data.projection.ProjectionRegistry;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.OsmReader;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.tools.ColorHelper;
import org.openstreetmap.josm.tools.Utils;

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

/**
* Test cases for {@link StyledMapRenderer} and the MapCSS classes.
* <p>
* This test uses the data and reference files stored in the test data directory {@value #TEST_DATA_BASE}
* @author Michael Zangl
*/
@BasicPreferences
@Projection
public class MapCSSRendererTest {
private static final String TEST_DATA_BASE = "/renderer/";
/**
Expand All @@ -59,13 +59,6 @@ public class MapCSSRendererTest {
private static final Bounds AREA_DEFAULT = new Bounds(0, 0, 1, 1);
private static final int IMAGE_SIZE = 256;

/**
* Minimal test rules required
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules().preferences().projection();

// development flag - set to true in order to update all reference images
private static final boolean UPDATE_ALL = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.IdentityHashMap;

import org.junit.jupiter.api.AfterAll;
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.api.Timeout;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
Expand All @@ -26,15 +28,21 @@
import org.openstreetmap.josm.gui.NavigatableComponent;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.io.Compression;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.OsmReader;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.Main;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.tools.Pair;

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

/**
* Test {@link StyleCache}.
*/
@BasicPreferences
@Main
@org.openstreetmap.josm.testutils.annotations.MapPaintStyles
@Projection
@Timeout(60)
class StyleCacheTest {

private static final int IMG_WIDTH = 1400;
Expand All @@ -46,12 +54,13 @@ class StyleCacheTest {
private static DataSet dsCity;
private static DataSet dsCity2;

/**
* The test rules used for this test.
*/
@RegisterExtension
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules test = new JOSMTestRules().main().preferences().projection().mapStyles().timeout(60000);
@BeforeAll
static void beforeAll() throws IllegalDataException, IOException {
try (InputStream in = Compression.getUncompressedFileInputStream(new File("nodist/data/neubrandenburg.osm.bz2"))) {
dsCity = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
}
dsCity2 = new DataSet(dsCity);
}

/**
* Load the test data that is required.
Expand All @@ -60,10 +69,6 @@ class StyleCacheTest {
@BeforeEach
public void load() throws Exception {
img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
try (InputStream in = Compression.getUncompressedFileInputStream(new File("nodist/data/neubrandenburg.osm.bz2"))) {
dsCity = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
}
dsCity2 = new DataSet(dsCity);
}

/**
Expand Down Expand Up @@ -96,11 +101,11 @@ public void loadGraphicComponents() {
/**
* Verifies, that the intern pool is not growing when repeatedly rendering the
* same set of primitives (and clearing the calculated styles each time).
*
* <p>
* If it grows, this is an indication that the {@code equals} and {@code hashCode}
* implementation is broken and two identical objects are not recognized as equal
* or produce different hash codes.
*
* <p>
* The opposite problem (different objects are mistaken as equal) has more visible
* consequences for the user (wrong rendering on the map) and is not recognized by
* this test.
Expand Down Expand Up @@ -134,7 +139,7 @@ void testStyleCacheInternPool() {
/**
* Verifies, that the number of {@code StyleElementList} instances stored
* for all the rendered primitives is actually low (as intended).
*
* <p>
* Two primitives with the same style should share one {@code StyleElementList}
* instance for the cached style elements. This is verified by counting all
* the instances using {@code A == B} identity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.PerformanceTestUtils;
import org.openstreetmap.josm.PerformanceTestUtils.PerformanceTestTimer;
import org.openstreetmap.josm.data.osm.OsmDataGenerator.KeyValueDataGenerator;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.Projection;

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

/**
* This test measures the performance of {@link OsmPrimitive#get(String)} and related.
* @author Michael Zangl
*/
@Projection
@Timeout(value = 15, unit = TimeUnit.MINUTES)
class KeyValuePerformanceTest {
private static final int PUT_RUNS = 10000;
Expand All @@ -38,13 +38,6 @@ class KeyValuePerformanceTest {
private final ArrayList<String> testStrings = new ArrayList<>();
private Random random;

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

/**
* See if there is a big difference between Strings that are interned and those that are not.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@

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.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.gui.NavigatableComponent;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.io.Compression;
import org.openstreetmap.josm.io.OsmReader;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.Territories;

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

/**
* Abstract superclass of {@code StyledMapRendererPerformanceTest} and {@code WireframeMapRendererPerformanceTest}.
*/
@Projection
@Territories
@Timeout(value = 15, unit = TimeUnit.MINUTES)
abstract class AbstractMapRendererPerformanceTestParent {

Expand All @@ -48,7 +51,6 @@ abstract class AbstractMapRendererPerformanceTestParent {
private static DataSet dsCity;

protected static void load() throws Exception {
JOSMFixture.createPerformanceTestFixture().init(true);
img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
g = (Graphics2D) img.getGraphics();
g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT);
Expand Down
Loading

0 comments on commit a9f8d35

Please sign in to comment.