Ticket #24924: 24924.patch

File 24924.patch, 82.9 KB (added by gaben, 2 weeks ago)
  • build.xml

    diff --git a/build.xml b/build.xml
    index acde4722de..dc1ea4375e 100644
    a b  
    8686        <property name="pmd.dir" location="${tools.dir}/pmd"/>
    8787        <property name="checkstyle.dir" location="${tools.dir}/checkstyle"/>
    8888        <property name="spotbugs.dir" location="${tools.dir}/spotbugs"/>
    89         <property name="javacc.home" location="${tools.dir}"/>
    9089        <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
    9190        <property name="proj-build.dir" location="${base.dir}/build2"/>
    9291        <property name="script-build.dir" location="${base.dir}/build2"/>
    9392        <property name="epsg.output" location="${resources.dir}/data/projection/custom-epsg"/>
    94         <property name="commons-lang3.jar" location="${tools.dir}/commons-lang3.jar"/>
    9593        <property name="dist.jar" location="${dist.dir}/josm-custom.jar"/>
    9694        <property name="dist-optimized.jar" location="${dist.dir}/josm-custom-optimized.jar"/>
    9795        <property name="dist-sources.jar" location="${dist.dir}/josm-custom-sources.jar"/>
    … … Build-Date: ${build.tstamp}  
    305303    </macrodef>
    306304    <target name="compile" depends="init,javacc" unless="compile.notRequired" description="Compile JOSM">
    307305        <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="errorprone.classpath" conf="errorprone"/>
    308         <ivy:cachepath log="download-only" file="${tools.ivy}" pathid="errorprone_javac.classpath" conf="errorprone_javac"/>
    309306        <!-- JOSM -->
    310307        <call-javac-compile excludes="**/package-info.java,**/module-info.java,main/**" release="${java.lang.version}"/>
    311308        <!-- Java 11 specific files (2018-09 LTS) -->
    … … Build-Date: ${build.tstamp}  
    404401        </path>
    405402        <ivy:retrieve log="download-only" pattern="${test.dir}/lib/[artifact].[ext]" conf="junit5-system-exit"/>
    406403        <ivy:retrieve log="download-only" pattern="${test.dir}/lib/[artifact].[ext]" conf="jmockit"/>
    407         <ivy:retrieve log="download-only" pattern="${tools.dir}/[artifact].[ext]" conf="commonslang"/>
    408404        <ivy:retrieve log="download-only" pattern="${tools.dir}/[conf].[ext]" conf="jacocoant"/>
    409405        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="${tools.dir}/jacocoant.jar" />
    410406    </target>
    … … Build-Date: ${build.tstamp}  
    469465            <junitlauncher printsummary="${junit.printsummary}" failureproperty="test.@{testfamily}@{testITsuffix}.failed">
    470466                <classpath>
    471467                    <path refid="test.classpath"/>
    472                     <pathelement path="${test.dir}/build/unit"/> <!-- required for functional/etc to have JOSMTestRules -->
     468                    <pathelement path="${test.dir}/build/unit"/> <!-- required for functional/etc to have the shared test utilities -->
    473469                    <pathelement path="${test.dir}/build/@{testfamily}"/>
    474470                </classpath>
    475471                <testclasses outputDir="${test.dir}/report">
    … … Build-Date: ${build.tstamp}  
    609605        -dontwarn com.google.errorprone.annotations.**
    610606        -dontwarn java.lang.invoke.MethodHandle
    611607
     608        # commons-lang3 is left out of the jar (see extract-libraries); CompressException still refers to it
     609        # from a method none of the shipped classes call.
     610        -dontwarn org.apache.commons.lang3.**
     611
    612612        # These options probably are not necessary (and make processing a bit slower)
    613613        -dontskipnonpubliclibraryclasses
    614614        -dontskipnonpubliclibraryclassmembers
    … … Build-Date: ${build.tstamp}  
    10561056        </exec>
    10571057        <move file="${modules.dir}/dots/summary.dot.png" tofile="${modules.dir}/josm-with-direct-dependencies.png"/>
    10581058        <!-- All dependencies -->
    1059         <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/google-gdata.jar" includes="com/google/**/*.class"/>
    10601059        <path id="jar-all.files">
    10611060            <fileset dir="${modules.dir}" includes="*.jar"/>
    10621061        </path>
    1063         <pathconvert property="jar-all.files.string" refid="jar-direct.files" pathsep=" "/>
     1062        <pathconvert property="jar-all.files.string" refid="jar-all.files" pathsep=" "/>
    10641063        <exec executable="jdeps" dir="${modules.dir}">
    10651064            <arg line="-dotoutput dots"/>
    10661065            <arg line="--multi-release 11"/>
    … … Build-Date: ${build.tstamp}  
    10791078        <ivy:cachefileset log="download-only" setid="runtime.fileset" conf="runtime"/>
    10801079        <ivy:cachepath log="download-only" pathid="test.path" conf="test"/>
    10811080    </target>
    1082     <target name="extract-libraries" depends="resolve" description="Extract libraries to build dir">
     1081    <target name="extract-libraries" depends="init-properties,resolve" description="Extract libraries to build dir">
    10831082        <unzip dest="${build.dir}">
    10841083            <fileset refid="runtime.fileset"/>
    10851084            <patternset>
    … … Build-Date: ${build.tstamp}  
    11351134                <exclude name="org/apache/commons/compress/compressors/CompressorException*"/>
    11361135                <exclude name="org/apache/commons/compress/compressors/FileNameUtil*"/>
    11371136                <exclude name="org/apache/commons/compress/compressors/deflate/**"/>
     1137                <exclude name="org/apache/commons/compress/compressors/deflate64/**"/>
    11381138                <exclude name="org/apache/commons/compress/compressors/gzip/**"/>
    11391139                <exclude name="org/apache/commons/compress/compressors/lz4/**"/>
    11401140                <exclude name="org/apache/commons/compress/compressors/lzma/**"/>
    … … Build-Date: ${build.tstamp}  
    11561156                <exclude name="org/apache/commons/jcs3/log/Log4j2Factory*"/>
    11571157                <exclude name="org/apache/commons/jcs3/log/Log4j2LogAdapter*"/>
    11581158                <exclude name="org/apache/commons/jcs3/utils/servlet/**"/>
     1159                <!-- commons-lang3 comes in transitively via commons-compress, but nothing we ship
     1160                     calls into it: the only two references are CompressException.requireNonNull()
     1161                     (never invoked by the classes left after the excludes above) and the deflate64
     1162                     decompressor (excluded). The Maven build leaves it out too, by declaring
     1163                     commons-lang3 as test-scoped in nodist/pom.xml. -->
     1164                <exclude name="org/apache/commons/lang3/**"/>
    11591165            </patternset>
    11601166        </unzip>
    11611167    </target>
  • ivy.xml

    diff --git a/ivy.xml b/ivy.xml
    index 297a24c938..d4c00ca6bf 100644
    a b  
    99        <conf name="runtimeOnly" description="The libs shipped with JOSM that we do not need during compilation"/>
    1010        <conf name="provided" description="The libs we need during compilation but not on application start"/>
    1111        <!-- Special configurations used to retrieve jar files of test lib/tools referred by file path -->
    12         <conf name="commonslang" description="Apache Commons Lang test library"/>
    1312        <conf name="jmockit" description="JMockit test library"/>
    1413        <conf name="jacocoant" description="Jacoco Ant test library"/>
    1514        <conf name="junit5-system-exit" description="Everything needed for running junit5-system-exit as a javaagent"/>
    1615        <!--  Meta configurations used in build scripts -->
    1716        <conf name="runtime" description="Libraries only needed at runtime" extends="implementation,api,runtimeOnly"/>
    1817        <conf name="compile" description="Libraries needed only for compilation" extends="implementation,api,provided"/>
    19         <conf name="test" description="Libraries only needed for testing" extends="compile,runtime,commonslang,jmockit,junit5-system-exit"/>
     18        <conf name="test" description="Libraries only needed for testing" extends="compile,runtime,jmockit,junit5-system-exit"/>
    2019        <conf name="sources" description="Source code of used libraries"/>
    2120    </configurations>
    2221    <dependencies>
    … …  
    3231        <dependency conf="api->default" org="com.adobe.xmp" name="xmpcore" rev="6.1.11"/>
    3332        <dependency conf="api->default" org="com.drewnoakes" name="metadata-extractor" rev="2.19.0" transitive="false"/>
    3433        <dependency conf="api->default" org="com.github.weisj" name="jsvg" rev="2.1.0"/>
    35         <dependency conf="api->default" org="org.jetbrains" name="annotations" rev="24.1.0"/>
     34        <dependency conf="provided->default" org="org.jetbrains" name="annotations" rev="24.1.0"/>
    3635        <dependency conf="api->default" org="ch.poole" name="OpeningHoursParser" rev="0.29.0"/>
    3736        <!-- Don't forget to update org.openstreetmap.josm.tools.Tag2Link#PREF_SOURCE -->
    3837        <dependency conf="api->default" org="org.webjars.npm" name="tag2link" rev="2026.6.26"/>
    … …  
    4241        <dependency conf="sources->sources" org="org.eclipse.parsson" name="parsson" rev="1.1.7"/>
    4342        <dependency conf="sources->sources" org="org.apache.commons" name="commons-jcs3-core" rev="3.2.1"/>
    4443        <dependency conf="sources->sources" org="org.apache.commons" name="commons-compress" rev="1.28.0"/>
    45         <dependency conf="sources->sources" org="jakarta.annotation" name="jakarta.annotation-api" rev="2.1.1" />
     44        <dependency conf="sources->sources" org="jakarta.annotation" name="jakarta.annotation-api" rev="3.0.0" />
    4645        <dependency conf="sources->sources" org="org.tukaani" name="xz" rev="1.11"/>
    4746        <dependency conf="sources->sources" org="com.adobe.xmp" name="xmpcore" rev="6.1.11"/>
    4847        <dependency conf="sources->sources" org="com.drewnoakes" name="metadata-extractor" rev="2.19.0" transitive="false"/>
    … …  
    5049        <dependency conf="sources->sources" org="org.jetbrains" name="annotations" rev="24.1.0"/>
    5150        <dependency conf="sources->sources" org="ch.poole" name="OpeningHoursParser" rev="0.29.0"/>
    5251        <dependency conf="sources->default" org="org.webjars.npm" name="tag2link" rev="2026.6.26"/><!-- sources->default sic! (tag2link-sources.jar is empty, see #19335) -->
    53         <!-- commonslang->default -->
    54         <dependency conf="commonslang->default" org="org.apache.commons" name="commons-lang3" rev="3.18.0"/>
    5552        <!-- jacocoant->default -->
    5653        <dependency conf="jacocoant->default" org="org.jacoco" name="org.jacoco.ant" rev="0.8.13">
    5754            <artifact name="org.jacoco.ant" type="jar" maven:classifier="nodeps"/>
    … …  
    6461        <dependency conf="test->default" org="io.github.classgraph" name="classgraph" rev="4.8.184"/>
    6562        <dependency conf="test->default" org="org.junit.platform" name="junit-platform-launcher" rev="1.14.2"/>
    6663        <dependency conf="test->default" org="org.junit.platform" name="junit-platform-suite" rev="1.14.2"/>
    67         <dependency conf="test->default" org="org.junit.vintage" name="junit-vintage-engine" rev="5.14.2"/>
    6864        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-params" rev="5.14.2"/>
    6965        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-api" rev="5.14.2"/>
    7066        <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-engine" rev="5.14.2"/>
    71         <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-migrationsupport" rev="5.14.2"/>
    7267        <dependency conf="test->default" org="net.trajano.commons" name="commons-testing" rev="2.1.0"/>
    7368        <dependency conf="test->default" org="nl.jqno.equalsverifier" name="equalsverifier" rev="${versions.equalsverifier}"/>
    7469        <dependency conf="test->default" org="org.apache.commons" name="commons-lang3" rev="3.20.0"/>
  • nodist/pom.xml

    diff --git a/nodist/pom.xml b/nodist/pom.xml
    index d2f732f38a..af7c94c71d 100644
    a b  
    376376            <dependency>
    377377                <groupId>org.apache.commons</groupId>
    378378                <artifactId>commons-lang3</artifactId>
    379                 <version>3.18.0</version>
     379                <version>3.20.0</version>
    380380                <scope>test</scope>
    381381            </dependency>
    382382            <dependency>
  • pom.xml

    diff --git a/pom.xml b/pom.xml
    index e444470c45..b1a7cb1f24 100644
    a b  
    2929    <spotbugs.dir>${tools.dir}/spotbugs</spotbugs.dir>
    3030    <tools.dir>${project.basedir}/tools</tools.dir>
    3131    <epsg.output>${resources.dir}/data/projection/custom-epsg</epsg.output>
    32     <javacc.home>${tools.dir}</javacc.home>
    3332    <dist.jar>${dist.dir}/josm-custom.jar</dist.jar>
    3433    <dist-optimized.jar>${dist.dir}/josm-custom-optimized.jar</dist-optimized.jar>
    3534    <dist-sources.jar>${dist.dir}/josm-custom-sources.jar</dist-sources.jar>
    … …  
    175174      <artifactId>junit-platform-suite</artifactId>
    176175      <scope>test</scope>
    177176    </dependency>
    178     <dependency>
    179       <groupId>org.junit.vintage</groupId>
    180       <artifactId>junit-vintage-engine</artifactId>
    181       <scope>test</scope>
    182     </dependency>
    183177    <dependency>
    184178      <groupId>org.junit.jupiter</groupId>
    185179      <artifactId>junit-jupiter-params</artifactId>
    … …  
    195189      <artifactId>junit-jupiter-engine</artifactId>
    196190      <scope>test</scope>
    197191    </dependency>
    198     <dependency>
    199       <groupId>org.junit.jupiter</groupId>
    200       <artifactId>junit-jupiter-migrationsupport</artifactId>
    201       <scope>test</scope>
    202     </dependency>
    203192    <dependency>
    204193      <groupId>net.trajano.commons</groupId>
    205194      <artifactId>commons-testing</artifactId>
    … …  
    714703                    <exclude>org/apache/commons/compress/compressors/CompressorException*</exclude>
    715704                    <exclude>org/apache/commons/compress/compressors/FileNameUtil*</exclude>
    716705                    <exclude>org/apache/commons/compress/compressors/deflate/**</exclude>
     706                    <exclude>org/apache/commons/compress/compressors/deflate64/**</exclude>
    717707                    <exclude>org/apache/commons/compress/compressors/gzip/**</exclude>
    718708                    <exclude>org/apache/commons/compress/compressors/lz4/**</exclude>
    719709                    <exclude>org/apache/commons/compress/compressors/lzma/**</exclude>
  • test/data/META-INF/services/org.junit.jupiter.api.extension.Extension

    diff --git a/test/data/META-INF/services/org.junit.jupiter.api.extension.Extension b/test/data/META-INF/services/org.junit.jupiter.api.extension.Extension
    index 7750cfa442..a754258446 100644
    a b  
    1 # These are the default extensions to run (all tests with JOSMTestRules would have done these by default)
     1# These are the default extensions to run for every test
    22org.openstreetmap.josm.testutils.annotations.BasicPreferences$BasicPreferencesExtension
    33org.openstreetmap.josm.testutils.annotations.HTTP$HTTPExtension
    44org.openstreetmap.josm.testutils.annotations.I18n$I18nExtension
  • test/pom.xml

    diff --git a/test/pom.xml b/test/pom.xml
    index cb0a356603..07ee885731 100644
    a b  
    5555            <artifactId>junit-platform-suite</artifactId>
    5656            <scope>compile</scope>
    5757        </dependency>
    58         <dependency>
    59             <groupId>org.junit.vintage</groupId>
    60             <artifactId>junit-vintage-engine</artifactId>
    61             <scope>compile</scope>
    62         </dependency>
    6358        <dependency>
    6459            <groupId>org.junit.jupiter</groupId>
    6560            <artifactId>junit-jupiter-params</artifactId>
    … …  
    7570            <artifactId>junit-jupiter-engine</artifactId>
    7671            <scope>compile</scope>
    7772        </dependency>
    78         <dependency>
    79             <groupId>org.junit.jupiter</groupId>
    80             <artifactId>junit-jupiter-migrationsupport</artifactId>
    81             <scope>compile</scope>
    82         </dependency>
    8373        <dependency>
    8474            <groupId>net.trajano.commons</groupId>
    8575            <artifactId>commons-testing</artifactId>
  • test/unit/org/openstreetmap/josm/JOSMFixture.java

    diff --git a/test/unit/org/openstreetmap/josm/JOSMFixture.java b/test/unit/org/openstreetmap/josm/JOSMFixture.java
    index 5344ed5c99..368fcbb034 100644
    a b import java.util.TimeZone;  
    1616import org.openstreetmap.josm.actions.DeleteAction;
    1717import org.openstreetmap.josm.command.DeleteCommand;
    1818import org.openstreetmap.josm.data.Preferences;
     19import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    1920import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    2021import org.openstreetmap.josm.data.preferences.JosmUrls;
    2122import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    … … import org.openstreetmap.josm.io.CertificateAmendment;  
    2930import org.openstreetmap.josm.io.OsmApi;
    3031import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
    3132import org.openstreetmap.josm.spi.preferences.Config;
    32 import org.openstreetmap.josm.testutils.JOSMTestRules;
    3333import org.openstreetmap.josm.tools.Http1Client;
    3434import org.openstreetmap.josm.tools.HttpClient;
    3535import org.openstreetmap.josm.tools.I18n;
    … … public class JOSMFixture {  
    158158            || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org");
    159159    }
    160160
     161    /**
     162     * Cleans the Layer manager and the SelectionEventManager.
     163     * You don't need to call this during tests, the test environment will do it for you.
     164     * @since 12070
     165     */
     166    public static void cleanLayerEnvironment() {
     167        // Get the instance before cleaning - this ensures that it is initialized.
     168        SelectionEventManager eventManager = SelectionEventManager.getInstance();
     169        MainApplication.getLayerManager().resetState();
     170        try {
     171            eventManager.resetState();
     172        } catch (IllegalArgumentException e) {
     173            Logging.trace(e);
     174        }
     175    }
     176
    161177    private void setupGUI() {
    162         JOSMTestRules.cleanLayerEnvironment();
     178        cleanLayerEnvironment();
    163179        assertTrue(MainApplication.getLayerManager().getLayers().isEmpty());
    164180        assertNull(MainApplication.getLayerManager().getEditLayer());
    165181        assertNull(MainApplication.getLayerManager().getActiveLayer());
  • test/unit/org/openstreetmap/josm/data/cache/HostLimitQueueTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/cache/HostLimitQueueTest.java b/test/unit/org/openstreetmap/josm/data/cache/HostLimitQueueTest.java
    index a3478870ee..8e61a167a1 100644
    a b package org.openstreetmap.josm.data.cache;  
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    55import static org.junit.jupiter.api.Assertions.assertTrue;
    66
     7import java.io.File;
    78import java.io.IOException;
    89import java.net.URL;
    910import java.util.concurrent.ThreadPoolExecutor;
    … … import java.util.concurrent.atomic.AtomicInteger;  
    1314import org.apache.commons.jcs3.access.behavior.ICacheAccess;
    1415import org.junit.jupiter.api.Test;
    1516import org.junit.jupiter.api.Timeout;
     17import org.junit.jupiter.api.io.TempDir;
    1618import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
    1719import org.openstreetmap.josm.data.imagery.TileJobOptions;
    1820import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    … … class HostLimitQueueTest {  
    7173     * @throws Exception in case of error
    7274     */
    7375    @Test
    74     void testSingleThreadPerHost() throws Exception {
     76    void testSingleThreadPerHost(@TempDir File tempDir) throws Exception {
    7577        ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 1);
    76         ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testHostLimitQueue", 3, 0, "");
     78        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testSingleThreadPerHost", 3, 0, tempDir.getPath());
    7779        AtomicInteger counter = new AtomicInteger(0);
    7880        long start = System.currentTimeMillis();
    7981        for (int i = 0; i < 10; i++) {
    … … class HostLimitQueueTest {  
    9799     * @throws Exception in case of error
    98100     */
    99101    @Test
    100     void testMultipleThreadPerHost() throws Exception {
     102    void testMultipleThreadPerHost(@TempDir File tempDir) throws Exception {
    101103        ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 2);
    102         ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testHostLimitQueue", 3, 0, "");
     104        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testMultipleThreadPerHost", 3, 0, tempDir.getPath());
    103105        AtomicInteger counter = new AtomicInteger(0);
    104106        long start = System.currentTimeMillis();
    105107        for (int i = 0; i < 10; i++) {
    … … class HostLimitQueueTest {  
    122124     * @throws Exception in case of error
    123125     */
    124126    @Test
    125     void testTwoHosts() throws Exception {
     127    void testTwoHosts(@TempDir File tempDir) throws Exception {
    126128        ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 1);
    127         ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testHostLimitQueue", 3, 0, "");
     129        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testTwoHosts", 3, 0, tempDir.getPath());
    128130        AtomicInteger counter = new AtomicInteger(0);
    129131        long start = System.currentTimeMillis();
    130132        for (int i = 0; i < 10; i++) {
  • test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java b/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java
    index b5c97d907a..118d64b139 100644
    a b import org.apache.commons.jcs3.access.CacheAccess;  
    1212import org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes;
    1313import org.junit.jupiter.api.Test;
    1414import org.junit.jupiter.api.Timeout;
     15import org.junit.jupiter.api.io.TempDir;
    1516import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1617
    1718import net.trajano.commons.testing.UtilityClassTestUtil;
    … … class JCSCacheManagerTest {  
    3637     * @throws IOException if any I/O error occurs
    3738     */
    3839    @Test
    39     void testLoggingAdaptor12054() throws IOException {
    40         JCSCacheManager.getCache("foobar", 1, 0, "foobar"); // cause logging adaptor to be initialized
     40    void testLoggingAdaptor12054(@TempDir File tempDir) throws IOException {
     41        JCSCacheManager.getCache("foobar", 1, 0, tempDir.getPath()); // cause logging adaptor to be initialized
    4142        Logger.getLogger("org.apache.commons.jcs3").warning("{switch:0}");
    4243    }
    4344
    4445    @Test
    45     void testUseBigDiskFile() throws IOException {
     46    void testUseBigDiskFile(@TempDir File tempDir) throws IOException {
    4647        if (JCSCacheManager.USE_BLOCK_CACHE.get()) {
    4748            // test only when using block cache
    48             File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data");
     49            File cacheFile = new File(tempDir, "testUseBigDiskFile_BLOCK_v2.data");
    4950            if (!cacheFile.exists()) {
    5051                if (!cacheFile.createNewFile()) {
    5152                    System.err.println("Unable to create " + cacheFile.getAbsolutePath());
    … … class JCSCacheManagerTest {  
    5657                fileOutputStream.write(new byte[1024*1024*10]); // create 10MB empty file
    5758            }
    5859
    59             CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, "foobar");
     60            CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, tempDir.getPath());
    6061            assertEquals(10*1024,
    6162                    ((BlockDiskCacheAttributes) cache.getCacheControl().getAuxCacheList().get(0).getAuxiliaryCacheAttributes()).getMaxKeySize(),
    6263                    "BlockDiskCache use file size to calculate its size");
  • test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java
    index 8805877ca0..7913474fdb 100644
    a b class MinimapDialogTest {  
    597597                "Viewport marker not vertically centered"
    598598                );
    599599
    600         try {
    601             javax.imageio.ImageIO.write(paintedSlippyMap, "png", new java.io.File("failed.png"));
    602         } catch (java.io.IOException ioe) {
    603             System.err.println("Failed writing image");
    604         }
    605 
    606600        assertTrue(
    607601                Math.abs(colMatcher.group(2).length() - (rowMatcher.group(2).length()*2.0)) < 5,
    608602                "Viewport marker not 2:1 aspect ratio"
  • test/unit/org/openstreetmap/josm/plugins/PluginHandlerJOSMTooOldTest.java

    diff --git a/test/unit/org/openstreetmap/josm/plugins/PluginHandlerJOSMTooOldTest.java b/test/unit/org/openstreetmap/josm/plugins/PluginHandlerJOSMTooOldTest.java
    index 53fe63a3aa..bab01fcd41 100644
    a b import org.openstreetmap.josm.testutils.annotations.FullPreferences;  
    3030import org.openstreetmap.josm.testutils.annotations.Main;
    3131import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    3232import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     33import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider;
    3334
    3435import com.github.tomakehurst.wiremock.client.WireMock;
    3536import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
    … … class PluginHandlerJOSMTooOldTest {  
    5455     */
    5556    @BeforeEach
    5657    public void setUp() {
     58        // not in a field initializer: those run before the extensions have switched the locale over to english
     59        this.bazPluginVersionReqString = u202f("JOSM version 8\u202F001 required for plugin baz_plugin.");
     60        this.dummyPluginVersionReqString = u202f("JOSM version 7\u202F001 required for plugin dummy_plugin.");
     61
    5762        Config.getPref().putInt("pluginmanager.version", 999);
    5863        Config.getPref().put("pluginmanager.lastupdate", "999");
    5964        Config.getPref().putList("pluginmanager.sites",
    … … class PluginHandlerJOSMTooOldTest {  
    9398    private File targetQuxJar;
    9499    private File targetQuxJarNew;
    95100
    96     private final String bazPluginVersionReqString = u202f("JOSM version 8\u202F001 required for plugin baz_plugin.");
    97     private final String dummyPluginVersionReqString = u202f("JOSM version 7\u202F001 required for plugin dummy_plugin.");
     101    private String bazPluginVersionReqString;
     102    private String dummyPluginVersionReqString;
    98103    private final String dummyPluginFailedString = "<html>Updating the following plugin has failed:<ul><li>dummy_plugin</li></ul>"
    99104        + "Please open the Preference Dialog after JOSM has started and try to update it manually.</html>";
    100105
     106    /**
     107     * Replace the digit group separator of {@link JosmDecimalFormatSymbolsProvider} with the one actually in effect.
     108     * <p>
     109     * This must not be called before the locale has been set up for the test: the provider only covers the locales
     110     * listed in {@link JosmDecimalFormatSymbolsProvider#getAvailableLocales}, so on a machine whose default locale
     111     * is not one of them (say {@code hu_HU}) it would answer with the platform separator instead.
     112     * @param s the expected message, using {@code U+202F} as the digit group separator
     113     * @return {@code s} with the digit group separator in effect substituted
     114     */
    101115    private static String u202f(String s) {
    102116        return s.replace('\u202F', DecimalFormatSymbols.getInstance().getGroupingSeparator());
    103117    }
  • deleted file test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java b/test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java
    deleted file mode 100644
    index 21516d6787..0000000000
    + -  
    1 // License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.testutils;
    3 
    4 import static org.openstreetmap.josm.testutils.ThrowableRootCauseMatcher.hasRootCause;
    5 
    6 import org.hamcrest.Matcher;
    7 import org.junit.rules.ExpectedException;
    8 import org.junit.rules.TestRule;
    9 import org.junit.runner.Description;
    10 import org.junit.runners.model.Statement;
    11 
    12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    13 
    14 /**
    15  * The {@code ExpectedRootException} behaves exactly as JUnit's {@link ExpectedException} rule.
    16  * This class is needed to add {@link #expectRootCause} method, which has been rejected by JUnit developers,
    17  * and {@code ExpectedException} cannot be extended because it has a private constructor.
    18  * @see <a href="https://github.com/junit-team/junit4/pull/778">Github pull request</a>
    19  * @deprecated Use matchers instead with the return from {@link org.junit.jupiter.api.Assertions#assertThrows}
    20  */
    21 @Deprecated
    22 public final class ExpectedRootException implements TestRule {
    23 
    24     private final ExpectedException rule = ExpectedException.none();
    25 
    26     /**
    27      * Returns a {@linkplain TestRule rule} that expects no exception to be thrown (identical to behavior without this rule).
    28      * @return {@code ExpectedRootException} instance
    29      */
    30     @SuppressFBWarnings("NM_CLASS_NOT_EXCEPTION")
    31     public static ExpectedRootException none() {
    32         return new ExpectedRootException();
    33     }
    34 
    35     private ExpectedRootException() {
    36     }
    37 
    38     /**
    39      * Specifies the failure message for tests that are expected to throw an exception but do not throw any.
    40      * You can use a {@code %s} placeholder for the description of the expected exception.
    41      * E.g. "Test doesn't throw %s." will fail with the error message "Test doesn't throw an instance of foo.".
    42      *
    43      * @param message exception detail message
    44      * @return the rule itself
    45      */
    46     public ExpectedRootException reportMissingExceptionWithMessage(String message) {
    47         rule.reportMissingExceptionWithMessage(message);
    48         return this;
    49     }
    50 
    51     @Override
    52     public Statement apply(Statement base, Description description) {
    53         return rule.apply(base, description);
    54     }
    55 
    56     /**
    57      * Verify that your code throws an exception that is an instance of specific {@code type}.
    58      * <pre> &#064;Test
    59      * public void throwsExceptionWithSpecificType() {
    60      *     thrown.expect(NullPointerException.class);
    61      *     throw new NullPointerException();
    62      * }</pre>
    63      * @param type Throwable type
    64      * @return {@code this}
    65      */
    66     public ExpectedRootException expect(Class<? extends Throwable> type) {
    67         rule.expect(type);
    68         return this;
    69     }
    70 
    71     /**
    72      * Verify that your code throws an exception whose message contains a specific text.
    73      * <pre> &#064;Test
    74      * public void throwsExceptionWhoseMessageContainsSpecificText() {
    75      *     thrown.expectMessage(&quot;happened&quot;);
    76      *     throw new NullPointerException(&quot;What happened?&quot;);
    77      * }</pre>
    78      * @param substring substring to expect in error message
    79      * @return {@code this}
    80      */
    81     public ExpectedRootException expectMessage(String substring) {
    82         rule.expectMessage(substring);
    83         return this;
    84     }
    85 
    86     /**
    87      * Verify that your code throws an exception whose immediate cause is matched by the given Hamcrest matcher.
    88      * <pre> &#064;Test
    89      * public void throwsExceptionWhoseCauseCompliesWithMatcher() {
    90      *     NullPointerException rootCause = new NullPointerException();
    91      *     IllegalStateException immediateCause = new IllegalStateException(rootCause);
    92      *     thrown.expectCause(isA(NullPointerException.class));
    93      *     throw new IllegalArgumentException(immediateCause);
    94      * }</pre>
    95      * @param expectedCause expected cause
    96      * @return {@code this}
    97      */
    98     public ExpectedRootException expectCause(Matcher<? extends Throwable> expectedCause) {
    99         rule.expectCause(expectedCause);
    100         return this;
    101     }
    102 
    103     /**
    104      * Verify that you code throws an exception whose root cause is matched by the given Hamcrest matcher.
    105      * <pre> &#064;Test
    106      * public void throwsExceptionWhoseRootCauseCompliesWithMatcher() {
    107      *     NullPointerException rootCause = new NullPointerException();
    108      *     IllegalStateException immediateCause = new IllegalStateException(rootCause);
    109      *     thrown.expectRootCause(isA(NullPointerException.class));
    110      *     throw new IllegalArgumentException(immediateCause);
    111      * }</pre>
    112      * @param expectedRootCause expected root cause
    113      * @return {@code this}
    114      */
    115     public ExpectedRootException expectRootCause(Matcher<? extends Throwable> expectedRootCause) {
    116         rule.expect(hasRootCause(expectedRootCause));
    117         return this;
    118     }
    119 }
  • test/unit/org/openstreetmap/josm/testutils/ImagePatternMatching.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/ImagePatternMatching.java b/test/unit/org/openstreetmap/josm/testutils/ImagePatternMatching.java
    index 8d4f589744..cdc0263346 100644
    a b import java.util.regex.Matcher;  
    1313import java.util.regex.Pattern;
    1414import java.util.stream.Collectors;
    1515
    16 import junit.framework.AssertionFailedError;
     16import org.opentest4j.AssertionFailedError;
    1717
    1818/**
    1919 * Utilities to aid in making assertions about images using regular expressions.
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index f33894ff38..76b2b4f521 100644
    a b import java.awt.event.WindowEvent;  
    77import java.io.ByteArrayInputStream;
    88import java.io.File;
    99import java.io.IOException;
    10 import java.io.PrintWriter;
    11 import java.io.StringWriter;
    1210import java.lang.annotation.Documented;
    1311import java.lang.annotation.ElementType;
    1412import java.lang.annotation.Retention;
    1513import java.lang.annotation.RetentionPolicy;
    1614import java.lang.annotation.Target;
    1715import java.nio.charset.StandardCharsets;
     16import java.nio.file.Files;
    1817import java.security.GeneralSecurityException;
    19 import java.text.MessageFormat;
    2018import java.util.Arrays;
    2119import java.util.Map;
    2220import java.util.TimeZone;
    … … import org.junit.jupiter.api.extension.AfterEachCallback;  
    3028import org.junit.jupiter.api.extension.BeforeAllCallback;
    3129import org.junit.jupiter.api.extension.BeforeEachCallback;
    3230import org.junit.jupiter.api.extension.ExtensionContext;
    33 import org.junit.rules.TemporaryFolder;
    34 import org.junit.rules.TestRule;
    35 import org.junit.runner.Description;
    36 import org.junit.runners.model.InitializationError;
    37 import org.junit.runners.model.Statement;
    3831import org.openstreetmap.josm.JOSMFixture;
    3932import org.openstreetmap.josm.TestUtils;
    4033import org.openstreetmap.josm.actions.DeleteAction;
    … … import org.openstreetmap.josm.data.SystemOfMeasurement;  
    4437import org.openstreetmap.josm.data.UserIdentityManager;
    4538import org.openstreetmap.josm.data.Version;
    4639import org.openstreetmap.josm.data.osm.User;
    47 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    4840import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    4941import org.openstreetmap.josm.data.preferences.JosmUrls;
    5042import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    5143import org.openstreetmap.josm.data.projection.Projections;
    5244import org.openstreetmap.josm.gui.MainApplication;
    5345import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
    54 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreferenceTestIT;
    5546import org.openstreetmap.josm.gui.util.GuiHelper;
    5647import org.openstreetmap.josm.io.OsmApi;
    5748import org.openstreetmap.josm.io.OsmApiInitializationException;
    … … import org.openstreetmap.josm.tools.I18n;  
    7364import org.openstreetmap.josm.tools.JosmRuntimeException;
    7465import org.openstreetmap.josm.tools.Logging;
    7566import org.openstreetmap.josm.tools.MemoryManagerTest;
    76 import org.openstreetmap.josm.tools.bugreport.ReportedException;
     67import org.openstreetmap.josm.tools.Utils;
    7768import org.openstreetmap.josm.tools.date.DateUtils;
    7869
    7970import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    80 import mockit.internal.state.SavePoint;
    8171
    8272/**
    8373 * This class runs a test in an environment that resembles the one used by the JOSM main application.
    … … import mockit.internal.state.SavePoint;  
    8676 * For example, invoking {@link #preferences()} gives you access to the (default) preferences.
    8777 *
    8878 * @author Michael Zangl
     79 * @deprecated use the JUnit 5 annotations in {@link org.openstreetmap.josm.testutils.annotations} instead,
     80 * e.g. {@link org.openstreetmap.josm.testutils.annotations.BasicPreferences} instead of {@link #preferences()}
    8981 */
    90 public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback {
    91     private int timeout = isDebugMode() ? -1 : 10 * 1000;
    92     private TemporaryFolder josmHome;
     82@Deprecated
     83public class JOSMTestRules implements AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback {
     84    private boolean useJosmHome;
     85    private File josmHome;
     86    private String originalJosmHome;
    9387    private boolean usePreferences = false;
    9488    private APIType useAPI = APIType.NONE;
    9589    private String i18n = null;
    9690    private TileSourceRule tileSourceRule;
    9791    private String assumeRevisionString;
    9892    private Version originalVersion;
     93    private boolean revisionOverridden;
     94    private String revisionBeforeOverride;
    9995    private Runnable mapViewStateMockingRunnable;
    10096    private Runnable navigableComponentMockingRunnable;
    10197    private Runnable edtAssertionMockingRunnable;
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    109105    private boolean territories;
    110106    private boolean metric;
    111107    private boolean main;
    112     /**
    113      * This boolean is only used to indicate if JUnit5 is used in a test. If it is,
    114      * we must not call after in {@link JOSMTestRules.CreateJosmEnvironment#evaluate}.
    115      * TODO: Remove JUnit4 as a whole sometime after 2021-01-01 (~6 month lead time for plugins)
    116      */
    117     private boolean junit5;
    118108
    119109    /**
    120110     * Disable the default timeout for this test. Use with care.
    121111     * @return this instance, for easy chaining
     112     * @deprecated no-op, timeouts are handled by {@link org.junit.jupiter.api.Timeout}
    122113     */
     114    @Deprecated
    123115    public JOSMTestRules noTimeout() {
    124         timeout = -1;
    125116        return this;
    126117    }
    127118
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    129120     * Set a timeout for all tests in this class. Local method timeouts may only reduce this timeout.
    130121     * @param millis The timeout duration in milliseconds.
    131122     * @return this instance, for easy chaining
    132      * @see org.junit.jupiter.api.Timeout
     123     * @deprecated no-op, use {@link org.junit.jupiter.api.Timeout} instead
    133124     */
     125    @Deprecated
    134126    public JOSMTestRules timeout(int millis) {
    135         timeout = isDebugMode() ? -1 : millis;
    136127        return this;
    137128    }
    138129
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    153144     * @return this instance, for easy chaining
    154145     */
    155146    private JOSMTestRules josmHome() {
    156         josmHome = new TemporaryFolder();
     147        useJosmHome = true;
    157148        return this;
    158149    }
    159150
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    410401     * @return this instance, for easy chaining
    411402     */
    412403    public JOSMTestRules parameters() {
     404        // Set up and tear down the environment immediately, as parameters are computed before anything else
    413405        try {
    414             apply(new Statement() {
    415                 @Override
    416                 public void evaluate() throws Throwable {
    417                     // Do nothing. Hack needed because @Parameters are computed before anything else
    418                 }
    419             }, Description.createSuiteDescription(ImageryPreferenceTestIT.class)).evaluate();
    420         } catch (Throwable e) {
     406            setUp();
     407        } catch (ReflectiveOperationException e) {
    421408            Logging.error(e);
     409        } finally {
     410            try {
     411                tearDown();
     412            } catch (ReflectiveOperationException e) {
     413                Logging.error(e);
     414            }
    422415        }
    423416        return this;
    424417    }
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    431424        }
    432425    }
    433426
    434     @Override
    435     public Statement apply(Statement base, Description description) {
    436         // First process any Override* annotations for per-test overrides.
    437         // The following only work because "option" methods modify JOSMTestRules in-place
    438         final OverrideAssumeRevision overrideAssumeRevision = description.getAnnotation(OverrideAssumeRevision.class);
    439         if (overrideAssumeRevision != null) {
    440             this.assumeRevision(overrideAssumeRevision.value());
    441         }
    442         final OverrideTimeout overrideTimeout = description.getAnnotation(OverrideTimeout.class);
    443         if (overrideTimeout != null) {
    444             this.timeout(overrideTimeout.value());
    445         }
    446         Statement statement = base;
    447         // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to
    448         // be added into the chain *before* that one, so that it ends up on the "inside".
    449         if (timeout > 0) {
    450             // TODO: new DisableOnDebug(timeout)
    451             statement = new FailOnTimeoutStatement(statement, timeout);
    452         }
    453 
    454         // this half of TileSourceRule's initialization must happen after josm is set up
     427    /**
     428     * Build the test environment. The mock tile server, if any, is started first so that it can be initializing in
     429     * parallel with the rest of the setup; registering its layers has to wait until josm itself has been set up.
     430     * @throws ReflectiveOperationException if a reflective access error occurs
     431     */
     432    private void setUp() throws ReflectiveOperationException {
    455433        if (this.tileSourceRule != null) {
    456             statement = this.tileSourceRule.applyRegisterLayers(statement, description);
     434            this.tileSourceRule.startServer();
    457435        }
    458 
    459         statement = new CreateJosmEnvironment(statement);
    460         if (josmHome != null) {
    461             statement = josmHome.apply(statement, description);
     436        before();
     437        if (this.tileSourceRule != null) {
     438            this.tileSourceRule.registerLayers();
    462439        }
     440    }
    463441
    464         // run mock tile server as the outermost Statement (started first) so it can hopefully be initializing in
    465         // parallel with other setup
    466         if (this.tileSourceRule != null) {
    467             statement = this.tileSourceRule.applyRunServer(statement, description);
     442    /**
     443     * Tear the test environment down again, in the reverse order of {@link #setUp}.
     444     * @throws ReflectiveOperationException if a reflective access error occurs
     445     */
     446    private void tearDown() throws ReflectiveOperationException {
     447        try {
     448            if (this.tileSourceRule != null) {
     449                this.tileSourceRule.unregisterLayers();
     450            }
     451            after();
     452        } finally {
     453            restoreJosmHome();
     454            if (this.tileSourceRule != null) {
     455                this.tileSourceRule.stopServer();
     456            }
    468457        }
    469         return statement;
    470458    }
    471459
    472460    @Override
    473461    public void beforeEach(ExtensionContext context) throws Exception {
    474         this.junit5 = true;
    475         Statement temporaryStatement = new Statement() {
    476             @Override
    477             public void evaluate() throws Throwable {
    478                 // do nothing
    479             }
    480         };
    481         try {
    482             this.apply(temporaryStatement,
    483                     Description.createTestDescription(this.getClass(), "JOSMTestRules JUnit5 Compatibility"))
    484                     .evaluate();
    485         } catch (Throwable e) {
    486             throw new Exception(e);
    487         }
     462        // First process any Override* annotations for per-test overrides.
     463        // The following only works because "option" methods modify JOSMTestRules in-place
     464        context.getTestMethod()
     465               .map(method -> method.getAnnotation(OverrideAssumeRevision.class))
     466               .ifPresent(annotation -> {
     467                   this.revisionOverridden = true;
     468                   this.revisionBeforeOverride = this.assumeRevisionString;
     469                   this.assumeRevision(annotation.value());
     470               });
     471        setUp();
    488472    }
    489473
    490474    @Override
    491475    public void afterEach(ExtensionContext context) throws Exception {
    492         after();
     476        try {
     477            tearDown();
     478        } finally {
     479            // the override only applies to the annotated test, not to the ones run after it with the same instance
     480            if (this.revisionOverridden) {
     481                this.assumeRevisionString = this.revisionBeforeOverride;
     482                this.revisionOverridden = false;
     483            }
     484        }
    493485    }
    494486
    495487    @Override
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    504496
    505497    /**
    506498     * Set up before running a test
    507      * @throws InitializationError If an error occurred while creating the required environment.
    508499     * @throws ReflectiveOperationException if a reflective access error occurs
    509500     */
    510     protected void before() throws InitializationError, ReflectiveOperationException {
     501    protected void before() throws ReflectiveOperationException {
    511502        cleanUpFromJosmFixture();
    512503
    513504        if (this.assumeRevisionString != null) {
    514             this.originalVersion = Version.getInstance();
     505            // as a static extension, before() runs again for each test without after() in between
     506            if (this.originalVersion == null) {
     507                this.originalVersion = Version.getInstance();
     508            }
    515509            final Version replacementVersion = new MockVersion(this.assumeRevisionString);
    516510            TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion);
    517511        }
    518512
    519513        // Add JOSM home
    520         if (josmHome != null) {
     514        if (useJosmHome && josmHome == null) {
    521515            try {
    522                 File home = josmHome.newFolder();
    523                 System.setProperty("josm.home", home.getAbsolutePath());
     516                originalJosmHome = System.getProperty("josm.home");
     517                josmHome = Files.createTempDirectory("josm-test-home").toFile();
     518                System.setProperty("josm.home", josmHome.getAbsolutePath());
    524519                JosmBaseDirectories.getInstance().clearMemos();
    525520            } catch (IOException e) {
    526                 throw new InitializationError(e);
     521                throw new JosmRuntimeException(e);
    527522            }
    528523        }
    529524
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    603598            try {
    604599                OsmApi.getOsmApi().initialize(null);
    605600            } catch (OsmTransferCanceledException | OsmApiInitializationException e) {
    606                 throw new InitializationError(e);
     601                throw new JosmRuntimeException(e);
    607602            }
    608603        }
    609604
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    663658     * Cleans the Layer manager and the SelectionEventManager.
    664659     * You don't need to call this during tests, the test environment will do it for you.
    665660     * @since 12070
     661     * @deprecated use {@link JOSMFixture#cleanLayerEnvironment()} instead
    666662     */
     663    @Deprecated
    667664    public static void cleanLayerEnvironment() {
    668         // Get the instance before cleaning - this ensures that it is initialized.
    669         SelectionEventManager eventManager = SelectionEventManager.getInstance();
    670         MainApplication.getLayerManager().resetState();
    671         try {
    672             eventManager.resetState();
    673         } catch (IllegalArgumentException e) {
    674             Logging.trace(e);
    675         }
     665        JOSMFixture.cleanLayerEnvironment();
    676666    }
    677667
    678668    /**
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    703693        ProjectionRegistry.clearProjectionChangeListeners();
    704694        Preferences.main().resetToInitialState();
    705695
    706         if (this.assumeRevisionString != null && this.originalVersion != null) {
     696        if (this.originalVersion != null) {
    707697            TestUtils.setPrivateStaticField(Version.class, "instance", this.originalVersion);
     698            this.originalVersion = null;
    708699        }
    709700
    710701        Window[] windows = Window.getWindows();
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    726717        JosmDefaults.DefaultsExtension.memoryCleanup();
    727718    }
    728719
    729     private final class CreateJosmEnvironment extends Statement {
    730         private final Statement base;
    731 
    732         private CreateJosmEnvironment(Statement base) {
    733             this.base = base;
    734         }
    735 
    736         @Override
    737         public void evaluate() throws Throwable {
    738             // Needed since JMockit doesn't clean up JUnit4 vintage tests. We really shouldn't have to touch JMockit internal classes. :(
    739             SavePoint savePoint = new SavePoint();
    740             before();
    741             try {
    742                 base.evaluate();
    743             } finally {
    744                 if (!junit5) {
    745                     after();
    746                     savePoint.rollback();
    747                 }
    748             }
    749         }
    750     }
    751 
    752     enum APIType {
    753         NONE, FAKE, DEV
    754     }
    755 
    756720    /**
    757      * The junit timeout statement has problems when switching timezones. This one does not.
    758      * @author Michael Zangl
     721     * Delete the temporary josm home created by {@link #before}, if any, and switch {@code josm.home} back.
     722     * Called by {@link #tearDown} even when {@link #after} fails part way, so that the next test does not inherit
     723     * this one's home.
    759724     */
    760     private static class FailOnTimeoutStatement extends Statement {
    761 
    762         private final int timeout;
    763         private final Statement original;
    764 
    765         FailOnTimeoutStatement(Statement original, int timeout) {
    766             this.original = original;
    767             this.timeout = timeout;
    768         }
    769 
    770         @Override
    771         public void evaluate() throws Throwable {
    772             TimeoutThread thread = new TimeoutThread(original);
    773             thread.setDaemon(true);
    774             thread.start();
    775             thread.join(timeout);
    776             thread.interrupt();
    777             if (!thread.isDone) {
    778                 Throwable exception = thread.getExecutionException();
    779                 if (exception != null) {
    780                     throw exception;
    781                 } else {
    782                     if (Logging.isLoggingEnabled(Logging.LEVEL_DEBUG)) {
    783                         // i.e. skip expensive formatting of stack trace if it won't be shown
    784                         final StringWriter sw = new StringWriter();
    785                         new ReportedException(exception).printReportThreadsTo(new PrintWriter(sw));
    786                         Logging.debug("Thread state at timeout: {0}", sw);
    787                     }
    788                     throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout));
    789                 }
    790             }
    791         }
    792     }
    793 
    794     private static final class TimeoutThread extends Thread {
    795         public boolean isDone;
    796         private final Statement original;
    797         private Throwable exceptionCaught;
    798 
    799         private TimeoutThread(Statement original) {
    800             super("Timeout runner");
    801             this.original = original;
    802         }
    803 
    804         public Throwable getExecutionException() {
    805             return exceptionCaught;
    806         }
    807 
    808         @Override
    809         public void run() {
    810             try {
    811                 original.evaluate();
    812                 isDone = true;
    813             } catch (Throwable e) {
    814                 exceptionCaught = e;
     725    private void restoreJosmHome() {
     726        if (josmHome != null) {
     727            Utils.deleteDirectory(josmHome);
     728            josmHome = null;
     729            if (originalJosmHome != null) {
     730                System.setProperty("josm.home", originalJosmHome);
     731            } else {
     732                System.clearProperty("josm.home");
    815733            }
     734            JosmBaseDirectories.getInstance().clearMemos();
    816735        }
    817736    }
    818737
    819     private boolean isDebugMode() {
    820         return java.lang.management.ManagementFactory.getRuntimeMXBean().
    821                 getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
     738    enum APIType {
     739        NONE, FAKE, DEV
    822740    }
    823741
    824742    /**
    … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal  
    838756
    839757    /**
    840758     * Override this test's timeout.
    841      * @see JOSMTestRules#timeout(int)
     759     * @deprecated no-op, use {@link org.junit.jupiter.api.Timeout} instead
    842760     */
     761    @Deprecated
    843762    @Documented
    844763    @Retention(RetentionPolicy.RUNTIME)
    845764    @Target(ElementType.METHOD)
  • test/unit/org/openstreetmap/josm/testutils/TileSourceRule.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/TileSourceRule.java b/test/unit/org/openstreetmap/josm/testutils/TileSourceRule.java
    index c55dc43906..bccd887b21 100644
    a b import java.util.Objects;  
    1717
    1818import javax.imageio.ImageIO;
    1919
    20 import org.junit.runner.Description;
    21 import org.junit.runners.model.Statement;
    2220import org.openstreetmap.josm.data.imagery.ImageryInfo;
    2321import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    2422import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    2523import org.openstreetmap.josm.tools.Logging;
    2624
     25import com.github.tomakehurst.wiremock.WireMockServer;
    2726import com.github.tomakehurst.wiremock.client.MappingBuilder;
    2827import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
    2928import com.github.tomakehurst.wiremock.client.WireMock;
    30 import com.github.tomakehurst.wiremock.junit.WireMockRule;
    3129
    3230/**
    33  * A JUnit rule, based on {@link WireMockRule} to provide a test with a simple mock tile server serving multiple tile
    34  * sources.
     31 * A {@link WireMockServer} providing a test with a simple mock tile server serving multiple tile sources.
    3532 */
    36 public class TileSourceRule extends WireMockRule {
     33public class TileSourceRule extends WireMockServer {
    3734    private static class ByteArrayWrapper {
    3835        public final byte[] byteArray;
    3936
    … … public class TileSourceRule extends WireMockRule {  
    6158
    6259        /**
    6360         * @return a {@link MappingBuilder} representing the request matching properties of this tile source, suitable
    64          * for passing to {@link WireMockRule#stubFor}.
     61         * for passing to {@link WireMockServer#stubFor}.
    6562         */
    6663        public abstract MappingBuilder getMappingBuilder();
    6764
    … … public class TileSourceRule extends WireMockRule {  
    167164    protected final boolean clearSlippyMapSources;
    168165    protected final boolean registerInLayerList;
    169166
     167    private List<SlippyMapBBoxChooser.TileSourceProvider> slippyMapProviders;
     168    private SlippyMapBBoxChooser.TileSourceProvider slippyMapDefaultProvider;
     169    private List<ImageryInfo> originalImageryInfoList;
     170    private boolean layersRegistered;
     171
    170172    /**
    171173     * Construct a TileSourceRule for use with a JUnit test.
    172174     *
    … … public class TileSourceRule extends WireMockRule {  
    184186     *
    185187     * The three boolean parameters control whether to perform various steps registering the tile sources with parts
    186188     * of JOSM's internals as part of the setup process. It is advised to only enable any of these if it can be ensured
    187      * that this rule will have its setup routine executed *after* the relevant parts of JOSM have been set up, e.g.
    188      * when handled by {@link org.openstreetmap.josm.testutils.JOSMTestRules#fakeImagery}.
     189     * that this rule will have its setup routine executed *after* the relevant parts of JOSM have been set up.
    189190     *
    190191     * @param clearLayerList whether to clear ImageryLayerInfo's layer list of any pre-existing entries
    191192     * @param clearSlippyMapSources whether to clear SlippyMapBBoxChooser's stubborn fallback Mapnik TileSource
    … … public class TileSourceRule extends WireMockRule {  
    227228    }
    228229
    229230    /**
    230      * A junit-rule {@code apply} method exposed separately to allow a chaining rule to put this much earlier in
    231      * the test's initialization routine. The idea being to allow WireMock's web server to be starting up while other
    232      * necessary initialization is taking place.
    233      * See {@link org.junit.rules.TestRule#apply} for arguments.
    234      * @param base The {@link Statement} to be modified
    235      * @param description A {@link Description} of the test implemented in {@code base}
    236      * @return a new statement, which may be the same as {@code base},
    237      *         a wrapper around {@code base}, or a completely new Statement.
     231     * Start the mock web server.
     232     *
     233     * Exposed separately from {@link #registerLayers} to allow a caller to put this much earlier in the test's
     234     * initialization routine. The idea being to allow WireMock's web server to be starting up while other necessary
     235     * initialization is taking place.
    238236     */
    239     public Statement applyRunServer(Statement base, Description description) {
    240         return super.apply(new Statement() {
    241             @Override
    242             public void evaluate() throws Throwable {
    243                 try {
    244                     // a hack to circumvent a WireMock bug concerning delayed server startup. sending an early request
    245                     // to the mock server seems to prompt it to start earlier (though this request itself is not
    246                     // expected to succeed). see https://github.com/tomakehurst/wiremock/issues/97
    247                     new java.net.URL(TileSourceRule.this.url("/_poke")).getContent();
    248                 } catch (IOException e) {
    249                     Logging.trace(e);
    250                 }
    251                 base.evaluate();
    252             }
    253         }, description);
     237    public void startServer() {
     238        start();
     239        WireMock.configureFor("localhost", port());
     240        try {
     241            // a hack to circumvent a WireMock bug concerning delayed server startup. sending an early request
     242            // to the mock server seems to prompt it to start earlier (though this request itself is not
     243            // expected to succeed). see https://github.com/tomakehurst/wiremock/issues/97
     244            new java.net.URL(this.url("/_poke")).getContent();
     245        } catch (IOException e) {
     246            Logging.trace(e);
     247        }
     248    }
     249
     250    /**
     251     * Stop the mock web server, if it is running.
     252     */
     253    public void stopServer() {
     254        if (isRunning()) {
     255            stop();
     256        }
    254257    }
    255258
    256259    /**
    257      * A junit-rule {@code apply} method exposed separately, containing initialization steps which can only be performed
    258      * once more of josm's environment has been set up.
    259      * See {@link org.junit.rules.TestRule#apply} for arguments.
    260      * @param base The {@link Statement} to be modified
    261      * @param description A {@link Description} of the test implemented in {@code base}
    262      * @return a new statement, which may be the same as {@code base},
    263      *         a wrapper around {@code base}, or a completely new Statement.
     260     * Register the mock tile sources with JOSM's internals, as requested by the constructor's boolean flags.
     261     *
     262     * These are initialization steps which can only be performed once more of josm's environment has been set up,
     263     * hence they are kept separate from {@link #startServer}. Must be paired with a call to {@link #unregisterLayers}.
     264     * Calling it again before that is a no-op, so the state saved by the first call is kept.
    264265     */
    265     public Statement applyRegisterLayers(Statement base, Description description) {
    266         if (this.registerInLayerList || this.clearLayerList) {
    267             return new Statement() {
    268                 @Override
    269                 @SuppressWarnings("unchecked")
    270                 public void evaluate() throws Throwable {
    271                     List<SlippyMapBBoxChooser.TileSourceProvider> slippyMapProviders = null;
    272                     SlippyMapBBoxChooser.TileSourceProvider slippyMapDefaultProvider = null;
    273                     List<ImageryInfo> originalImageryInfoList = null;
    274                     if (TileSourceRule.this.clearSlippyMapSources) {
    275                         try {
    276                             slippyMapProviders = (List<SlippyMapBBoxChooser.TileSourceProvider>) getPrivateStaticField(
    277                                 SlippyMapBBoxChooser.class,
    278                                 "providers"
    279                             );
    280                             // pop this off the beginning of the list, keep for later
    281                             slippyMapDefaultProvider = slippyMapProviders.remove(0);
    282                         } catch (ReflectiveOperationException e) {
    283                             Logging.warn("Failed to remove default SlippyMapBBoxChooser TileSourceProvider");
    284                         }
    285                     }
    286 
    287                     if (TileSourceRule.this.clearLayerList) {
    288                         originalImageryInfoList = ImageryLayerInfo.instance.getLayers();
    289                         ImageryLayerInfo.instance.clear();
    290                     }
    291                     if (TileSourceRule.this.registerInLayerList) {
    292                         for (ConstSource source : TileSourceRule.this.sourcesList) {
    293                             ImageryLayerInfo.addLayer(source.getImageryInfo(TileSourceRule.this.port()));
    294                         }
    295                     }
    296 
    297                     try {
    298                         base.evaluate();
    299                     } finally {
    300                         // clean up to original state
    301                         if (slippyMapDefaultProvider != null && slippyMapProviders != null) {
    302                             slippyMapProviders.add(0, slippyMapDefaultProvider);
    303                         }
    304                         if (originalImageryInfoList != null) {
    305                             ImageryLayerInfo.instance.clear();
    306                             ImageryLayerInfo.addLayers(originalImageryInfoList);
    307                         }
    308                     }
    309                 }
    310             };
    311         } else {
    312             return base;
     266    @SuppressWarnings("unchecked")
     267    public void registerLayers() {
     268        if (this.layersRegistered || !(this.registerInLayerList || this.clearLayerList)) {
     269            return;
     270        }
     271        this.layersRegistered = true;
     272        if (this.clearSlippyMapSources) {
     273            try {
     274                this.slippyMapProviders = (List<SlippyMapBBoxChooser.TileSourceProvider>) getPrivateStaticField(
     275                    SlippyMapBBoxChooser.class,
     276                    "providers"
     277                );
     278                // pop this off the beginning of the list, keep for later
     279                this.slippyMapDefaultProvider = this.slippyMapProviders.remove(0);
     280            } catch (ReflectiveOperationException e) {
     281                Logging.warn("Failed to remove default SlippyMapBBoxChooser TileSourceProvider");
     282            }
     283        }
     284
     285        if (this.clearLayerList) {
     286            // getLayers() hands out a live view of the internal list, so it has to be copied before clearing
     287            this.originalImageryInfoList = List.copyOf(ImageryLayerInfo.instance.getLayers());
     288            ImageryLayerInfo.instance.clear();
     289        }
     290        if (this.registerInLayerList) {
     291            for (ConstSource source : this.sourcesList) {
     292                ImageryLayerInfo.addLayer(source.getImageryInfo(this.port()));
     293            }
    313294        }
    314295    }
    315296
    316297    /**
    317      * A standard implementation of apply which simply calls both sub- {@code apply} methods, {@link #applyRunServer}
    318      * and {@link #applyRegisterLayers}. Called when used as a standard junit rule.
     298     * Restore the state which was saved away by {@link #registerLayers}.
    319299     */
    320     @Override
    321     public Statement apply(Statement base, Description description) {
    322         return applyRunServer(applyRegisterLayers(base, description), description);
     300    public void unregisterLayers() {
     301        this.layersRegistered = false;
     302        if (this.slippyMapDefaultProvider != null && this.slippyMapProviders != null) {
     303            this.slippyMapProviders.add(0, this.slippyMapDefaultProvider);
     304        }
     305        this.slippyMapProviders = null;
     306        this.slippyMapDefaultProvider = null;
     307
     308        if (this.originalImageryInfoList != null) {
     309            ImageryLayerInfo.instance.clear();
     310            ImageryLayerInfo.addLayers(this.originalImageryInfoList);
     311            this.originalImageryInfoList = null;
     312        }
    323313    }
    324314}
  • test/unit/org/openstreetmap/josm/testutils/annotations/AssumeRevision.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/AssumeRevision.java b/test/unit/org/openstreetmap/josm/testutils/annotations/AssumeRevision.java
    index ad074a93bb..391f46f265 100644
    a b import org.junit.jupiter.api.extension.ExtendWith;  
    1515import org.junit.jupiter.api.extension.ExtensionContext;
    1616import org.openstreetmap.josm.TestUtils;
    1717import org.openstreetmap.josm.data.Version;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1918
    2019/**
    2120 * Override this test's assumed JOSM version (as reported by {@link Version}).
    22  * @see JOSMTestRules#assumeRevision(String)
    2321 */
    2422@Documented
    2523@Retention(RetentionPolicy.RUNTIME)
  • test/unit/org/openstreetmap/josm/testutils/annotations/BasicPreferences.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/BasicPreferences.java b/test/unit/org/openstreetmap/josm/testutils/annotations/BasicPreferences.java
    index b08c971e99..be15e7245f 100644
    a b import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;  
    2323import org.openstreetmap.josm.data.preferences.JosmUrls;
    2424import org.openstreetmap.josm.spi.preferences.Config;
    2525import org.openstreetmap.josm.spi.preferences.Setting;
    26 import org.openstreetmap.josm.testutils.JOSMTestRules;
    2726
    2827/**
    29  * Allow tests to use JOSM preferences (see {@link JOSMTestRules#preferences()}).
     28 * Allow tests to use JOSM preferences.
    3029 * This is often enough for basic tests. There are two modes:
    3130 * <ul>
    3231 *     <li>Between test classes (usually enough) if annotated at the class level ({@link ElementType#TYPE})</li>
  • test/unit/org/openstreetmap/josm/testutils/annotations/FakeImagery.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/FakeImagery.java b/test/unit/org/openstreetmap/josm/testutils/annotations/FakeImagery.java
    index bc15410274..10f1d2ce7b 100644
    a b import org.openstreetmap.josm.data.imagery.ImageryInfo;  
    2222import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    2323import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
    2424import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    25 import org.openstreetmap.josm.testutils.JOSMTestRules;
    2625import org.openstreetmap.josm.testutils.TileSourceRule;
    2726import org.openstreetmap.josm.tools.Logging;
    2827
    … … import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;  
    3332 * Replace imagery sources with a default set of mock tile sources.
    3433 * @author Taylor Smock
    3534 * @since 18893
    36  * @see JOSMTestRules#fakeImagery()
    3735 */
    3836@Inherited
    3937@Documented
    … … public @interface FakeImagery {  
    7573        /**
    7674         * Construct a FakeImageryWireMockExtension for use with a JUnit test.
    7775         * <p>
    78          * This is hidden for now, since all internal used {@link JOSMTestRules#fakeImagery()} instead of
    79          * {@link JOSMTestRules#fakeImagery(TileSourceRule)}. Before making this public, we'll probably want to move
    80          * {@link TileSourceRule.ConstSource} and it's subclasses around.
     76         * This is hidden for now. Before making this public, we'll probably want to move
     77         * {@link TileSourceRule.ConstSource} and its subclasses around.
    8178         * <p>
    8279         * The three boolean parameters control whether to perform various steps registering the tile sources with parts
    8380         * of JOSM's internals as part of the setup process. It is advised to only enable any of these if it can be ensured
  • test/unit/org/openstreetmap/josm/testutils/annotations/FullPreferences.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/FullPreferences.java b/test/unit/org/openstreetmap/josm/testutils/annotations/FullPreferences.java
    index 384befe9cd..7791ca0439 100644
    a b import org.junit.jupiter.api.extension.ExtensionContext.Namespace;  
    1414import org.openstreetmap.josm.data.Preferences;
    1515import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    1616import org.openstreetmap.josm.spi.preferences.Config;
    17 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1817import org.openstreetmap.josm.testutils.annotations.BasicPreferences.BasicPreferencesExtension;
    1918
    2019/**
    21  * Allow tests to use JOSM preferences with default values (see {@link JOSMTestRules#preferences()})
     20 * Allow tests to use JOSM preferences with default values
    2221 * @author Taylor Smock
    2322 * @see BasicPreferences (often enough for simple tests).
    2423 * @since 18037
  • test/unit/org/openstreetmap/josm/testutils/annotations/HTTPS.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/HTTPS.java b/test/unit/org/openstreetmap/josm/testutils/annotations/HTTPS.java
    index 579e1fa861..9e9bddf8db 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1515import org.junit.jupiter.api.extension.ExtendWith;
    1616import org.junit.jupiter.api.extension.ExtensionContext;
    1717import org.openstreetmap.josm.io.CertificateAmendment;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1918
    2019/**
    2120 * Set up the HTTPS certificates
    2221 * @author Taylor Smock
    2322 * @since 18893
    24  * @see JOSMTestRules#https()
    2523 */
    2624@Inherited
    2725@Documented
  • test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java b/test/unit/org/openstreetmap/josm/testutils/annotations/I18n.java
    index ae515470e5..9fdeef0c56 100644
    a b import org.openstreetmap.josm.tools.LanguageInfo;  
    1818/**
    1919 * Enables the i18n module for this test.
    2020 * @author Taylor Smock
    21  * @see org.openstreetmap.josm.testutils.JOSMTestRules#i18n(String)
    2221 * @since 17914
    2322 */
    2423@Documented
    … … public @interface I18n {  
    3736    /**
    3837     * Enables the i18n module for this test.
    3938     * @author Taylor Smock
    40      * @see org.openstreetmap.josm.testutils.JOSMTestRules#i18n(String)
    4139     */
    4240    class I18nExtension implements AfterEachCallback, BeforeEachCallback {
    4341        @Override
  • test/unit/org/openstreetmap/josm/testutils/annotations/JosmDefaults.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/JosmDefaults.java b/test/unit/org/openstreetmap/josm/testutils/annotations/JosmDefaults.java
    index 4146eb450f..18e5eaf88a 100644
    a b import org.junit.jupiter.api.extension.BeforeAllCallback;  
    1515import org.junit.jupiter.api.extension.BeforeEachCallback;
    1616import org.junit.jupiter.api.extension.ExtendWith;
    1717import org.junit.jupiter.api.extension.ExtensionContext;
     18import org.openstreetmap.josm.JOSMFixture;
    1819import org.openstreetmap.josm.actions.DeleteAction;
    1920import org.openstreetmap.josm.command.DeleteCommand;
    2021import org.openstreetmap.josm.data.Preferences;
    … … import org.openstreetmap.josm.data.osm.User;  
    2324import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard;
    2425import org.openstreetmap.josm.gui.util.GuiHelper;
    2526import org.openstreetmap.josm.io.OsmConnection;
    26 import org.openstreetmap.josm.testutils.JOSMTestRules;
    2727import org.openstreetmap.josm.tools.Logging;
    2828import org.openstreetmap.josm.tools.MemoryManagerTest;
    2929import org.openstreetmap.josm.tools.Utils;
    3030
    3131/**
    32  * Default actions taken by {@link JOSMTestRules}. Automatically registered.
     32 * Default actions taken for every test. Automatically registered.
    3333 * Functionality that this provides may be moved to other classes.
    3434 */
    3535@Target({ElementType.TYPE, ElementType.METHOD})
    … … import org.openstreetmap.josm.tools.Utils;  
    3737@ExtendWith(JosmDefaults.DefaultsExtension.class)
    3838public @interface JosmDefaults {
    3939    /**
    40      * Default actions taken by {@link JOSMTestRules}. Automatically registered.
     40     * Default actions taken for every test. Automatically registered.
    4141     * Functionality that this provides may be moved to other classes.
    4242     */
    4343    class DefaultsExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback, AfterEachCallback {
    … … public @interface JosmDefaults {  
    9494         */
    9595        private static void cleanUpFromJosmFixture() {
    9696            MemoryManagerTest.resetState(true);
    97             JOSMTestRules.cleanLayerEnvironment();
     97            JOSMFixture.cleanLayerEnvironment();
    9898            Preferences.main().resetToInitialState();
    9999            Preferences.main().enableSaveOnPut(false);
    100100            memoryCleanup();
  • test/unit/org/openstreetmap/josm/testutils/annotations/JosmHome.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/JosmHome.java b/test/unit/org/openstreetmap/josm/testutils/annotations/JosmHome.java
    index 36493a6368..c065ffbbe7 100644
    a b import org.junit.jupiter.api.extension.ExtendWith;  
    2121import org.junit.jupiter.api.extension.ExtensionContext;
    2222import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
    2323import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    24 import org.openstreetmap.josm.testutils.JOSMTestRules;
    2524
    2625/**
    27  * Use the JOSM home directory. See {@link JOSMTestRules}.
     26 * Use the JOSM home directory.
    2827 * Typically only used by {@link FullPreferences}.
    2928 *
    3029 * @author Taylor Smock
  • test/unit/org/openstreetmap/josm/testutils/annotations/LayerManager.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/LayerManager.java b/test/unit/org/openstreetmap/josm/testutils/annotations/LayerManager.java
    index ea208fc022..c44c5b392a 100644
    a b import org.junit.jupiter.api.extension.AfterEachCallback;  
    1010import org.junit.jupiter.api.extension.BeforeEachCallback;
    1111import org.junit.jupiter.api.extension.ExtendWith;
    1212import org.junit.jupiter.api.extension.ExtensionContext;
    13 import org.openstreetmap.josm.testutils.JOSMTestRules;
     13import org.openstreetmap.josm.JOSMFixture;
    1414
    1515/**
    1616 * Clear the main {@link org.openstreetmap.josm.gui.layer.LayerManager} between tests.
    … … public @interface LayerManager {  
    3030    class LayerManagerExtension implements BeforeEachCallback, AfterEachCallback {
    3131        @Override
    3232        public void afterEach(ExtensionContext context) {
    33             JOSMTestRules.cleanLayerEnvironment();
     33            JOSMFixture.cleanLayerEnvironment();
    3434        }
    3535
    3636        @Override
  • test/unit/org/openstreetmap/josm/testutils/annotations/MapPaintStyles.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/MapPaintStyles.java b/test/unit/org/openstreetmap/josm/testutils/annotations/MapPaintStyles.java
    index 7d696d29c5..70d2d14be8 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1111import org.junit.jupiter.api.extension.ExtendWith;
    1212import org.junit.jupiter.api.extension.ExtensionContext;
    1313import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    14 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1514
    1615/**
    1716 * Use map styles in tests.
    1817 *
    1918 * @author Taylor Smock
    20  * @see JOSMTestRules#mapStyles()
    2119 */
    2220@Documented
    2321@Retention(RetentionPolicy.RUNTIME)
  • test/unit/org/openstreetmap/josm/testutils/annotations/MeasurementSystem.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/MeasurementSystem.java b/test/unit/org/openstreetmap/josm/testutils/annotations/MeasurementSystem.java
    index 563545f7c7..e6171f8f0a 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1313import org.junit.jupiter.api.extension.ExtendWith;
    1414import org.junit.jupiter.api.extension.ExtensionContext;
    1515import org.openstreetmap.josm.data.SystemOfMeasurement;
    16 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1716
    1817/**
    1918 * Set up the system of measurement
    2019 * @author Taylor Smock
    2120 * @since 18893
    22  * @see JOSMTestRules#metricSystem()
    2321 */
    2422@Inherited
    2523@Documented
  • test/unit/org/openstreetmap/josm/testutils/annotations/MemoryManagerLeaks.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/MemoryManagerLeaks.java b/test/unit/org/openstreetmap/josm/testutils/annotations/MemoryManagerLeaks.java
    index cddda690b0..a837ed3303 100644
    a b import java.lang.annotation.Inherited;  
    1010import java.lang.annotation.Retention;
    1111import java.lang.annotation.Target;
    1212
    13 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1413
    1514/**
    1615 * Allow the memory manager to contain items after execution of the test cases.
    1716 * @author Taylor Smock
    1817 * @since 18893
    19  * @see JOSMTestRules#memoryManagerLeaks()
    2018 */
    2119@Inherited
    2220@Documented
  • test/unit/org/openstreetmap/josm/testutils/annotations/OsmApi.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/OsmApi.java b/test/unit/org/openstreetmap/josm/testutils/annotations/OsmApi.java
    index b2df8a0e16..dd85bda419 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1313import org.junit.jupiter.api.extension.ExtendWith;
    1414import org.junit.jupiter.api.extension.ExtensionContext;
    1515import org.junit.platform.commons.support.ReflectionSupport;
    16 import org.junit.runners.model.InitializationError;
    1716import org.openstreetmap.josm.io.OsmApiInitializationException;
    1817import org.openstreetmap.josm.io.OsmTransferCanceledException;
    1918import org.openstreetmap.josm.spi.preferences.Config;
    2019import org.openstreetmap.josm.testutils.FakeOsmApi;
     20import org.openstreetmap.josm.tools.JosmRuntimeException;
    2121
    2222/**
    2323 * Used for setting the desired OsmApi type
    … … public @interface OsmApi {  
    7979                try {
    8080                    org.openstreetmap.josm.io.OsmApi.getOsmApi().initialize(null);
    8181                } catch (OsmTransferCanceledException | OsmApiInitializationException e) {
    82                     throw new InitializationError(e);
     82                    throw new JosmRuntimeException(e);
    8383                }
    8484            }
    8585        }
  • test/unit/org/openstreetmap/josm/testutils/annotations/Projection.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/Projection.java b/test/unit/org/openstreetmap/josm/testutils/annotations/Projection.java
    index 20c24cfc92..587a792a74 100644
    a b import org.junit.jupiter.api.extension.ExtensionContext;  
    1616import org.junit.platform.commons.support.AnnotationSupport;
    1717import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1818import org.openstreetmap.josm.data.projection.Projections;
    19 import org.openstreetmap.josm.testutils.JOSMTestRules;
    2019
    2120/**
    2221 * Use projections in tests (Mercator).
    2322 *
    2423 * @author Taylor Smock
    25  * @see JOSMTestRules#projection()
    2624 *
    2725 */
    2826@Documented
  • test/unit/org/openstreetmap/josm/testutils/annotations/ProjectionNadGrids.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/ProjectionNadGrids.java b/test/unit/org/openstreetmap/josm/testutils/annotations/ProjectionNadGrids.java
    index 2722e0fa82..f06e0b6362 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1212import org.junit.jupiter.api.extension.ExtendWith;
    1313import org.junit.jupiter.api.extension.ExtensionContext;
    1414import org.openstreetmap.josm.gui.MainApplication;
    15 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1615import org.openstreetmap.josm.tools.Utils;
    1716
    1817/**
    1918 * Use NAD projections in tests.
    2019 *
    2120 * @author Taylor Smock
    22  * @see JOSMTestRules#projectionNadGrids()
    2321 *
    2422 */
    2523@Documented
  • test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java b/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java
    index 4407cd69dd..7a89f31d60 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1515import org.junit.jupiter.api.extension.ExtendWith;
    1616import org.junit.jupiter.api.extension.ExtensionContext;
    1717import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1918
    2019/**
    2120 * Use presets in tests.
    2221 *
    2322 * @author Taylor Smock
    24  * @see JOSMTestRules#presets()
    2523 */
    2624@Documented
    2725@Retention(RetentionPolicy.RUNTIME)
  • test/unit/org/openstreetmap/josm/testutils/annotations/Territories.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/annotations/Territories.java b/test/unit/org/openstreetmap/josm/testutils/annotations/Territories.java
    index 7e6e93f912..642dd6d55a 100644
    a b import org.junit.jupiter.api.extension.BeforeEachCallback;  
    1414import org.junit.jupiter.api.extension.ExtendWith;
    1515import org.junit.jupiter.api.extension.ExtensionContext;
    1616import org.junit.platform.commons.support.AnnotationSupport;
    17 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1817
    1918/**
    2019 * Use boundaries dataset in this test.
    2120 *
    22  * @see JOSMTestRules#territories()
    2321 * @author Taylor Smock
    2422 * @since 18798
    2523 */
  • test/unit/org/openstreetmap/josm/testutils/mockers/JOptionPaneSimpleMocker.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/mockers/JOptionPaneSimpleMocker.java b/test/unit/org/openstreetmap/josm/testutils/mockers/JOptionPaneSimpleMocker.java
    index 929c6a02f3..730b59b4e5 100644
    a b import mockit.MockUp;  
    4242 * only the parts necessary for a particular case.
    4343 *
    4444 * The default {@link #getMockResultForMessage(Object)} will raise an
    45  * {@link junit.framework.AssertionFailedError} on an activation without a matching mapping entry or if
     45 * {@link AssertionError} on an activation without a matching mapping entry or if
    4646 * the mapped result value is invalid for the call.
    4747 *
    4848 * The public {@link #getMockResultMap()} method returns the modifiable result map to allow for situations
  • tools/ivy.xml

    diff --git a/tools/ivy.xml b/tools/ivy.xml
    index 8a5e203cdb..e23b561aa7 100644
    a b  
    99        <conf name="pmd" description="Everything needed for running PMD"/>
    1010        <conf name="spotbugs" description="Everything needed for running SpotBugs"/>
    1111        <conf name="errorprone" description="Everything needed for running error-prone"/>
    12         <conf name="errorprone_javac" description="Everything needed for running javac from error-prone"/>
    1312        <conf name="animal" description="Everything needed for running Animal Sniffer"/>
    1413    </configurations>
    1514    <dependencies>