Ticket #24924: 24924.patch
| File 24924.patch, 82.9 KB (added by , 2 weeks ago) |
|---|
-
build.xml
diff --git a/build.xml b/build.xml index acde4722de..dc1ea4375e 100644
a b 86 86 <property name="pmd.dir" location="${tools.dir}/pmd"/> 87 87 <property name="checkstyle.dir" location="${tools.dir}/checkstyle"/> 88 88 <property name="spotbugs.dir" location="${tools.dir}/spotbugs"/> 89 <property name="javacc.home" location="${tools.dir}"/>90 89 <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/> 91 90 <property name="proj-build.dir" location="${base.dir}/build2"/> 92 91 <property name="script-build.dir" location="${base.dir}/build2"/> 93 92 <property name="epsg.output" location="${resources.dir}/data/projection/custom-epsg"/> 94 <property name="commons-lang3.jar" location="${tools.dir}/commons-lang3.jar"/>95 93 <property name="dist.jar" location="${dist.dir}/josm-custom.jar"/> 96 94 <property name="dist-optimized.jar" location="${dist.dir}/josm-custom-optimized.jar"/> 97 95 <property name="dist-sources.jar" location="${dist.dir}/josm-custom-sources.jar"/> … … Build-Date: ${build.tstamp} 305 303 </macrodef> 306 304 <target name="compile" depends="init,javacc" unless="compile.notRequired" description="Compile JOSM"> 307 305 <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"/>309 306 <!-- JOSM --> 310 307 <call-javac-compile excludes="**/package-info.java,**/module-info.java,main/**" release="${java.lang.version}"/> 311 308 <!-- Java 11 specific files (2018-09 LTS) --> … … Build-Date: ${build.tstamp} 404 401 </path> 405 402 <ivy:retrieve log="download-only" pattern="${test.dir}/lib/[artifact].[ext]" conf="junit5-system-exit"/> 406 403 <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"/>408 404 <ivy:retrieve log="download-only" pattern="${tools.dir}/[conf].[ext]" conf="jacocoant"/> 409 405 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="${tools.dir}/jacocoant.jar" /> 410 406 </target> … … Build-Date: ${build.tstamp} 469 465 <junitlauncher printsummary="${junit.printsummary}" failureproperty="test.@{testfamily}@{testITsuffix}.failed"> 470 466 <classpath> 471 467 <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 --> 473 469 <pathelement path="${test.dir}/build/@{testfamily}"/> 474 470 </classpath> 475 471 <testclasses outputDir="${test.dir}/report"> … … Build-Date: ${build.tstamp} 609 605 -dontwarn com.google.errorprone.annotations.** 610 606 -dontwarn java.lang.invoke.MethodHandle 611 607 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 612 612 # These options probably are not necessary (and make processing a bit slower) 613 613 -dontskipnonpubliclibraryclasses 614 614 -dontskipnonpubliclibraryclassmembers … … Build-Date: ${build.tstamp} 1056 1056 </exec> 1057 1057 <move file="${modules.dir}/dots/summary.dot.png" tofile="${modules.dir}/josm-with-direct-dependencies.png"/> 1058 1058 <!-- All dependencies --> 1059 <jar basedir="${build.dir}" level="${clevel}" destfile="${modules.dir}/google-gdata.jar" includes="com/google/**/*.class"/>1060 1059 <path id="jar-all.files"> 1061 1060 <fileset dir="${modules.dir}" includes="*.jar"/> 1062 1061 </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=" "/> 1064 1063 <exec executable="jdeps" dir="${modules.dir}"> 1065 1064 <arg line="-dotoutput dots"/> 1066 1065 <arg line="--multi-release 11"/> … … Build-Date: ${build.tstamp} 1079 1078 <ivy:cachefileset log="download-only" setid="runtime.fileset" conf="runtime"/> 1080 1079 <ivy:cachepath log="download-only" pathid="test.path" conf="test"/> 1081 1080 </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"> 1083 1082 <unzip dest="${build.dir}"> 1084 1083 <fileset refid="runtime.fileset"/> 1085 1084 <patternset> … … Build-Date: ${build.tstamp} 1135 1134 <exclude name="org/apache/commons/compress/compressors/CompressorException*"/> 1136 1135 <exclude name="org/apache/commons/compress/compressors/FileNameUtil*"/> 1137 1136 <exclude name="org/apache/commons/compress/compressors/deflate/**"/> 1137 <exclude name="org/apache/commons/compress/compressors/deflate64/**"/> 1138 1138 <exclude name="org/apache/commons/compress/compressors/gzip/**"/> 1139 1139 <exclude name="org/apache/commons/compress/compressors/lz4/**"/> 1140 1140 <exclude name="org/apache/commons/compress/compressors/lzma/**"/> … … Build-Date: ${build.tstamp} 1156 1156 <exclude name="org/apache/commons/jcs3/log/Log4j2Factory*"/> 1157 1157 <exclude name="org/apache/commons/jcs3/log/Log4j2LogAdapter*"/> 1158 1158 <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/**"/> 1159 1165 </patternset> 1160 1166 </unzip> 1161 1167 </target> -
ivy.xml
diff --git a/ivy.xml b/ivy.xml index 297a24c938..d4c00ca6bf 100644
a b 9 9 <conf name="runtimeOnly" description="The libs shipped with JOSM that we do not need during compilation"/> 10 10 <conf name="provided" description="The libs we need during compilation but not on application start"/> 11 11 <!-- 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"/>13 12 <conf name="jmockit" description="JMockit test library"/> 14 13 <conf name="jacocoant" description="Jacoco Ant test library"/> 15 14 <conf name="junit5-system-exit" description="Everything needed for running junit5-system-exit as a javaagent"/> 16 15 <!-- Meta configurations used in build scripts --> 17 16 <conf name="runtime" description="Libraries only needed at runtime" extends="implementation,api,runtimeOnly"/> 18 17 <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"/> 20 19 <conf name="sources" description="Source code of used libraries"/> 21 20 </configurations> 22 21 <dependencies> … … 32 31 <dependency conf="api->default" org="com.adobe.xmp" name="xmpcore" rev="6.1.11"/> 33 32 <dependency conf="api->default" org="com.drewnoakes" name="metadata-extractor" rev="2.19.0" transitive="false"/> 34 33 <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"/> 36 35 <dependency conf="api->default" org="ch.poole" name="OpeningHoursParser" rev="0.29.0"/> 37 36 <!-- Don't forget to update org.openstreetmap.josm.tools.Tag2Link#PREF_SOURCE --> 38 37 <dependency conf="api->default" org="org.webjars.npm" name="tag2link" rev="2026.6.26"/> … … 42 41 <dependency conf="sources->sources" org="org.eclipse.parsson" name="parsson" rev="1.1.7"/> 43 42 <dependency conf="sources->sources" org="org.apache.commons" name="commons-jcs3-core" rev="3.2.1"/> 44 43 <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" /> 46 45 <dependency conf="sources->sources" org="org.tukaani" name="xz" rev="1.11"/> 47 46 <dependency conf="sources->sources" org="com.adobe.xmp" name="xmpcore" rev="6.1.11"/> 48 47 <dependency conf="sources->sources" org="com.drewnoakes" name="metadata-extractor" rev="2.19.0" transitive="false"/> … … 50 49 <dependency conf="sources->sources" org="org.jetbrains" name="annotations" rev="24.1.0"/> 51 50 <dependency conf="sources->sources" org="ch.poole" name="OpeningHoursParser" rev="0.29.0"/> 52 51 <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"/>55 52 <!-- jacocoant->default --> 56 53 <dependency conf="jacocoant->default" org="org.jacoco" name="org.jacoco.ant" rev="0.8.13"> 57 54 <artifact name="org.jacoco.ant" type="jar" maven:classifier="nodeps"/> … … 64 61 <dependency conf="test->default" org="io.github.classgraph" name="classgraph" rev="4.8.184"/> 65 62 <dependency conf="test->default" org="org.junit.platform" name="junit-platform-launcher" rev="1.14.2"/> 66 63 <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"/>68 64 <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-params" rev="5.14.2"/> 69 65 <dependency conf="test->default" org="org.junit.jupiter" name="junit-jupiter-api" rev="5.14.2"/> 70 66 <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"/>72 67 <dependency conf="test->default" org="net.trajano.commons" name="commons-testing" rev="2.1.0"/> 73 68 <dependency conf="test->default" org="nl.jqno.equalsverifier" name="equalsverifier" rev="${versions.equalsverifier}"/> 74 69 <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 376 376 <dependency> 377 377 <groupId>org.apache.commons</groupId> 378 378 <artifactId>commons-lang3</artifactId> 379 <version>3. 18.0</version>379 <version>3.20.0</version> 380 380 <scope>test</scope> 381 381 </dependency> 382 382 <dependency> -
pom.xml
diff --git a/pom.xml b/pom.xml index e444470c45..b1a7cb1f24 100644
a b 29 29 <spotbugs.dir>${tools.dir}/spotbugs</spotbugs.dir> 30 30 <tools.dir>${project.basedir}/tools</tools.dir> 31 31 <epsg.output>${resources.dir}/data/projection/custom-epsg</epsg.output> 32 <javacc.home>${tools.dir}</javacc.home>33 32 <dist.jar>${dist.dir}/josm-custom.jar</dist.jar> 34 33 <dist-optimized.jar>${dist.dir}/josm-custom-optimized.jar</dist-optimized.jar> 35 34 <dist-sources.jar>${dist.dir}/josm-custom-sources.jar</dist-sources.jar> … … 175 174 <artifactId>junit-platform-suite</artifactId> 176 175 <scope>test</scope> 177 176 </dependency> 178 <dependency>179 <groupId>org.junit.vintage</groupId>180 <artifactId>junit-vintage-engine</artifactId>181 <scope>test</scope>182 </dependency>183 177 <dependency> 184 178 <groupId>org.junit.jupiter</groupId> 185 179 <artifactId>junit-jupiter-params</artifactId> … … 195 189 <artifactId>junit-jupiter-engine</artifactId> 196 190 <scope>test</scope> 197 191 </dependency> 198 <dependency>199 <groupId>org.junit.jupiter</groupId>200 <artifactId>junit-jupiter-migrationsupport</artifactId>201 <scope>test</scope>202 </dependency>203 192 <dependency> 204 193 <groupId>net.trajano.commons</groupId> 205 194 <artifactId>commons-testing</artifactId> … … 714 703 <exclude>org/apache/commons/compress/compressors/CompressorException*</exclude> 715 704 <exclude>org/apache/commons/compress/compressors/FileNameUtil*</exclude> 716 705 <exclude>org/apache/commons/compress/compressors/deflate/**</exclude> 706 <exclude>org/apache/commons/compress/compressors/deflate64/**</exclude> 717 707 <exclude>org/apache/commons/compress/compressors/gzip/**</exclude> 718 708 <exclude>org/apache/commons/compress/compressors/lz4/**</exclude> 719 709 <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 2 2 org.openstreetmap.josm.testutils.annotations.BasicPreferences$BasicPreferencesExtension 3 3 org.openstreetmap.josm.testutils.annotations.HTTP$HTTPExtension 4 4 org.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 55 55 <artifactId>junit-platform-suite</artifactId> 56 56 <scope>compile</scope> 57 57 </dependency> 58 <dependency>59 <groupId>org.junit.vintage</groupId>60 <artifactId>junit-vintage-engine</artifactId>61 <scope>compile</scope>62 </dependency>63 58 <dependency> 64 59 <groupId>org.junit.jupiter</groupId> 65 60 <artifactId>junit-jupiter-params</artifactId> … … 75 70 <artifactId>junit-jupiter-engine</artifactId> 76 71 <scope>compile</scope> 77 72 </dependency> 78 <dependency>79 <groupId>org.junit.jupiter</groupId>80 <artifactId>junit-jupiter-migrationsupport</artifactId>81 <scope>compile</scope>82 </dependency>83 73 <dependency> 84 74 <groupId>net.trajano.commons</groupId> 85 75 <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; 16 16 import org.openstreetmap.josm.actions.DeleteAction; 17 17 import org.openstreetmap.josm.command.DeleteCommand; 18 18 import org.openstreetmap.josm.data.Preferences; 19 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 19 20 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 20 21 import org.openstreetmap.josm.data.preferences.JosmUrls; 21 22 import org.openstreetmap.josm.data.projection.ProjectionRegistry; … … import org.openstreetmap.josm.io.CertificateAmendment; 29 30 import org.openstreetmap.josm.io.OsmApi; 30 31 import org.openstreetmap.josm.spi.lifecycle.Lifecycle; 31 32 import org.openstreetmap.josm.spi.preferences.Config; 32 import org.openstreetmap.josm.testutils.JOSMTestRules;33 33 import org.openstreetmap.josm.tools.Http1Client; 34 34 import org.openstreetmap.josm.tools.HttpClient; 35 35 import org.openstreetmap.josm.tools.I18n; … … public class JOSMFixture { 158 158 || url.startsWith("https://www.openstreetmap.org") || url.startsWith("https://api.openstreetmap.org"); 159 159 } 160 160 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 161 177 private void setupGUI() { 162 JOSMTestRules.cleanLayerEnvironment();178 cleanLayerEnvironment(); 163 179 assertTrue(MainApplication.getLayerManager().getLayers().isEmpty()); 164 180 assertNull(MainApplication.getLayerManager().getEditLayer()); 165 181 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; 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 6 7 import java.io.File; 7 8 import java.io.IOException; 8 9 import java.net.URL; 9 10 import java.util.concurrent.ThreadPoolExecutor; … … import java.util.concurrent.atomic.AtomicInteger; 13 14 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 14 15 import org.junit.jupiter.api.Test; 15 16 import org.junit.jupiter.api.Timeout; 17 import org.junit.jupiter.api.io.TempDir; 16 18 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 17 19 import org.openstreetmap.josm.data.imagery.TileJobOptions; 18 20 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; … … class HostLimitQueueTest { 71 73 * @throws Exception in case of error 72 74 */ 73 75 @Test 74 void testSingleThreadPerHost( ) throws Exception {76 void testSingleThreadPerHost(@TempDir File tempDir) throws Exception { 75 77 ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 1); 76 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test HostLimitQueue", 3, 0, "");78 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testSingleThreadPerHost", 3, 0, tempDir.getPath()); 77 79 AtomicInteger counter = new AtomicInteger(0); 78 80 long start = System.currentTimeMillis(); 79 81 for (int i = 0; i < 10; i++) { … … class HostLimitQueueTest { 97 99 * @throws Exception in case of error 98 100 */ 99 101 @Test 100 void testMultipleThreadPerHost( ) throws Exception {102 void testMultipleThreadPerHost(@TempDir File tempDir) throws Exception { 101 103 ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 2); 102 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test HostLimitQueue", 3, 0, "");104 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testMultipleThreadPerHost", 3, 0, tempDir.getPath()); 103 105 AtomicInteger counter = new AtomicInteger(0); 104 106 long start = System.currentTimeMillis(); 105 107 for (int i = 0; i < 10; i++) { … … class HostLimitQueueTest { 122 124 * @throws Exception in case of error 123 125 */ 124 126 @Test 125 void testTwoHosts( ) throws Exception {127 void testTwoHosts(@TempDir File tempDir) throws Exception { 126 128 ThreadPoolExecutor tpe = TMSCachedTileLoader.getNewThreadPoolExecutor("test-%d", 3, 1); 127 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test HostLimitQueue", 3, 0, "");129 ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("testTwoHosts", 3, 0, tempDir.getPath()); 128 130 AtomicInteger counter = new AtomicInteger(0); 129 131 long start = System.currentTimeMillis(); 130 132 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; 12 12 import org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes; 13 13 import org.junit.jupiter.api.Test; 14 14 import org.junit.jupiter.api.Timeout; 15 import org.junit.jupiter.api.io.TempDir; 15 16 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 16 17 17 18 import net.trajano.commons.testing.UtilityClassTestUtil; … … class JCSCacheManagerTest { 36 37 * @throws IOException if any I/O error occurs 37 38 */ 38 39 @Test 39 void testLoggingAdaptor12054( ) throws IOException {40 JCSCacheManager.getCache("foobar", 1, 0, "foobar"); // cause logging adaptor to be initialized40 void testLoggingAdaptor12054(@TempDir File tempDir) throws IOException { 41 JCSCacheManager.getCache("foobar", 1, 0, tempDir.getPath()); // cause logging adaptor to be initialized 41 42 Logger.getLogger("org.apache.commons.jcs3").warning("{switch:0}"); 42 43 } 43 44 44 45 @Test 45 void testUseBigDiskFile( ) throws IOException {46 void testUseBigDiskFile(@TempDir File tempDir) throws IOException { 46 47 if (JCSCacheManager.USE_BLOCK_CACHE.get()) { 47 48 // 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"); 49 50 if (!cacheFile.exists()) { 50 51 if (!cacheFile.createNewFile()) { 51 52 System.err.println("Unable to create " + cacheFile.getAbsolutePath()); … … class JCSCacheManagerTest { 56 57 fileOutputStream.write(new byte[1024*1024*10]); // create 10MB empty file 57 58 } 58 59 59 CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, "foobar");60 CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, tempDir.getPath()); 60 61 assertEquals(10*1024, 61 62 ((BlockDiskCacheAttributes) cache.getCacheControl().getAuxCacheList().get(0).getAuxiliaryCacheAttributes()).getMaxKeySize(), 62 63 "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 { 597 597 "Viewport marker not vertically centered" 598 598 ); 599 599 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 606 600 assertTrue( 607 601 Math.abs(colMatcher.group(2).length() - (rowMatcher.group(2).length()*2.0)) < 5, 608 602 "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; 30 30 import org.openstreetmap.josm.testutils.annotations.Main; 31 31 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker; 32 32 import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; 33 import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider; 33 34 34 35 import com.github.tomakehurst.wiremock.client.WireMock; 35 36 import com.github.tomakehurst.wiremock.junit5.WireMockExtension; … … class PluginHandlerJOSMTooOldTest { 54 55 */ 55 56 @BeforeEach 56 57 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 57 62 Config.getPref().putInt("pluginmanager.version", 999); 58 63 Config.getPref().put("pluginmanager.lastupdate", "999"); 59 64 Config.getPref().putList("pluginmanager.sites", … … class PluginHandlerJOSMTooOldTest { 93 98 private File targetQuxJar; 94 99 private File targetQuxJarNew; 95 100 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; 98 103 private final String dummyPluginFailedString = "<html>Updating the following plugin has failed:<ul><li>dummy_plugin</li></ul>" 99 104 + "Please open the Preference Dialog after JOSM has started and try to update it manually.</html>"; 100 105 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 */ 101 115 private static String u202f(String s) { 102 116 return s.replace('\u202F', DecimalFormatSymbols.getInstance().getGroupingSeparator()); 103 117 } -
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 @Deprecated22 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} instance29 */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 message44 * @return the rule itself45 */46 public ExpectedRootException reportMissingExceptionWithMessage(String message) {47 rule.reportMissingExceptionWithMessage(message);48 return this;49 }50 51 @Override52 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> @Test59 * public void throwsExceptionWithSpecificType() {60 * thrown.expect(NullPointerException.class);61 * throw new NullPointerException();62 * }</pre>63 * @param type Throwable type64 * @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> @Test74 * public void throwsExceptionWhoseMessageContainsSpecificText() {75 * thrown.expectMessage("happened");76 * throw new NullPointerException("What happened?");77 * }</pre>78 * @param substring substring to expect in error message79 * @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> @Test89 * 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 cause96 * @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> @Test106 * 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 cause113 * @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; 13 13 import java.util.regex.Pattern; 14 14 import java.util.stream.Collectors; 15 15 16 import junit.framework.AssertionFailedError;16 import org.opentest4j.AssertionFailedError; 17 17 18 18 /** 19 19 * 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; 7 7 import java.io.ByteArrayInputStream; 8 8 import java.io.File; 9 9 import java.io.IOException; 10 import java.io.PrintWriter;11 import java.io.StringWriter;12 10 import java.lang.annotation.Documented; 13 11 import java.lang.annotation.ElementType; 14 12 import java.lang.annotation.Retention; 15 13 import java.lang.annotation.RetentionPolicy; 16 14 import java.lang.annotation.Target; 17 15 import java.nio.charset.StandardCharsets; 16 import java.nio.file.Files; 18 17 import java.security.GeneralSecurityException; 19 import java.text.MessageFormat;20 18 import java.util.Arrays; 21 19 import java.util.Map; 22 20 import java.util.TimeZone; … … import org.junit.jupiter.api.extension.AfterEachCallback; 30 28 import org.junit.jupiter.api.extension.BeforeAllCallback; 31 29 import org.junit.jupiter.api.extension.BeforeEachCallback; 32 30 import 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;38 31 import org.openstreetmap.josm.JOSMFixture; 39 32 import org.openstreetmap.josm.TestUtils; 40 33 import org.openstreetmap.josm.actions.DeleteAction; … … import org.openstreetmap.josm.data.SystemOfMeasurement; 44 37 import org.openstreetmap.josm.data.UserIdentityManager; 45 38 import org.openstreetmap.josm.data.Version; 46 39 import org.openstreetmap.josm.data.osm.User; 47 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;48 40 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 49 41 import org.openstreetmap.josm.data.preferences.JosmUrls; 50 42 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 51 43 import org.openstreetmap.josm.data.projection.Projections; 52 44 import org.openstreetmap.josm.gui.MainApplication; 53 45 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 54 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreferenceTestIT;55 46 import org.openstreetmap.josm.gui.util.GuiHelper; 56 47 import org.openstreetmap.josm.io.OsmApi; 57 48 import org.openstreetmap.josm.io.OsmApiInitializationException; … … import org.openstreetmap.josm.tools.I18n; 73 64 import org.openstreetmap.josm.tools.JosmRuntimeException; 74 65 import org.openstreetmap.josm.tools.Logging; 75 66 import org.openstreetmap.josm.tools.MemoryManagerTest; 76 import org.openstreetmap.josm.tools. bugreport.ReportedException;67 import org.openstreetmap.josm.tools.Utils; 77 68 import org.openstreetmap.josm.tools.date.DateUtils; 78 69 79 70 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 80 import mockit.internal.state.SavePoint;81 71 82 72 /** 83 73 * This class runs a test in an environment that resembles the one used by the JOSM main application. … … import mockit.internal.state.SavePoint; 86 76 * For example, invoking {@link #preferences()} gives you access to the (default) preferences. 87 77 * 88 78 * @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()} 89 81 */ 90 public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback { 91 private int timeout = isDebugMode() ? -1 : 10 * 1000; 92 private TemporaryFolder josmHome; 82 @Deprecated 83 public class JOSMTestRules implements AfterEachCallback, BeforeEachCallback, AfterAllCallback, BeforeAllCallback { 84 private boolean useJosmHome; 85 private File josmHome; 86 private String originalJosmHome; 93 87 private boolean usePreferences = false; 94 88 private APIType useAPI = APIType.NONE; 95 89 private String i18n = null; 96 90 private TileSourceRule tileSourceRule; 97 91 private String assumeRevisionString; 98 92 private Version originalVersion; 93 private boolean revisionOverridden; 94 private String revisionBeforeOverride; 99 95 private Runnable mapViewStateMockingRunnable; 100 96 private Runnable navigableComponentMockingRunnable; 101 97 private Runnable edtAssertionMockingRunnable; … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 109 105 private boolean territories; 110 106 private boolean metric; 111 107 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;118 108 119 109 /** 120 110 * Disable the default timeout for this test. Use with care. 121 111 * @return this instance, for easy chaining 112 * @deprecated no-op, timeouts are handled by {@link org.junit.jupiter.api.Timeout} 122 113 */ 114 @Deprecated 123 115 public JOSMTestRules noTimeout() { 124 timeout = -1;125 116 return this; 126 117 } 127 118 … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 129 120 * Set a timeout for all tests in this class. Local method timeouts may only reduce this timeout. 130 121 * @param millis The timeout duration in milliseconds. 131 122 * @return this instance, for easy chaining 132 * @ see org.junit.jupiter.api.Timeout123 * @deprecated no-op, use {@link org.junit.jupiter.api.Timeout} instead 133 124 */ 125 @Deprecated 134 126 public JOSMTestRules timeout(int millis) { 135 timeout = isDebugMode() ? -1 : millis;136 127 return this; 137 128 } 138 129 … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 153 144 * @return this instance, for easy chaining 154 145 */ 155 146 private JOSMTestRules josmHome() { 156 josmHome = new TemporaryFolder();147 useJosmHome = true; 157 148 return this; 158 149 } 159 150 … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 410 401 * @return this instance, for easy chaining 411 402 */ 412 403 public JOSMTestRules parameters() { 404 // Set up and tear down the environment immediately, as parameters are computed before anything else 413 405 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) { 421 408 Logging.error(e); 409 } finally { 410 try { 411 tearDown(); 412 } catch (ReflectiveOperationException e) { 413 Logging.error(e); 414 } 422 415 } 423 416 return this; 424 417 } … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 431 424 } 432 425 } 433 426 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 { 455 433 if (this.tileSourceRule != null) { 456 statement = this.tileSourceRule.applyRegisterLayers(statement, description);434 this.tileSourceRule.startServer(); 457 435 } 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(); 462 439 } 440 } 463 441 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 } 468 457 } 469 return statement;470 458 } 471 459 472 460 @Override 473 461 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(); 488 472 } 489 473 490 474 @Override 491 475 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 } 493 485 } 494 486 495 487 @Override … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 504 496 505 497 /** 506 498 * Set up before running a test 507 * @throws InitializationError If an error occurred while creating the required environment.508 499 * @throws ReflectiveOperationException if a reflective access error occurs 509 500 */ 510 protected void before() throws InitializationError,ReflectiveOperationException {501 protected void before() throws ReflectiveOperationException { 511 502 cleanUpFromJosmFixture(); 512 503 513 504 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 } 515 509 final Version replacementVersion = new MockVersion(this.assumeRevisionString); 516 510 TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion); 517 511 } 518 512 519 513 // Add JOSM home 520 if ( josmHome != null) {514 if (useJosmHome && josmHome == null) { 521 515 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()); 524 519 JosmBaseDirectories.getInstance().clearMemos(); 525 520 } catch (IOException e) { 526 throw new InitializationError(e);521 throw new JosmRuntimeException(e); 527 522 } 528 523 } 529 524 … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 603 598 try { 604 599 OsmApi.getOsmApi().initialize(null); 605 600 } catch (OsmTransferCanceledException | OsmApiInitializationException e) { 606 throw new InitializationError(e);601 throw new JosmRuntimeException(e); 607 602 } 608 603 } 609 604 … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 663 658 * Cleans the Layer manager and the SelectionEventManager. 664 659 * You don't need to call this during tests, the test environment will do it for you. 665 660 * @since 12070 661 * @deprecated use {@link JOSMFixture#cleanLayerEnvironment()} instead 666 662 */ 663 @Deprecated 667 664 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(); 676 666 } 677 667 678 668 /** … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 703 693 ProjectionRegistry.clearProjectionChangeListeners(); 704 694 Preferences.main().resetToInitialState(); 705 695 706 if (this. assumeRevisionString != null && this.originalVersion != null) {696 if (this.originalVersion != null) { 707 697 TestUtils.setPrivateStaticField(Version.class, "instance", this.originalVersion); 698 this.originalVersion = null; 708 699 } 709 700 710 701 Window[] windows = Window.getWindows(); … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 726 717 JosmDefaults.DefaultsExtension.memoryCleanup(); 727 718 } 728 719 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 @Override737 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, DEV754 }755 756 720 /** 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. 759 724 */ 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"); 815 733 } 734 JosmBaseDirectories.getInstance().clearMemos(); 816 735 } 817 736 } 818 737 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 822 740 } 823 741 824 742 /** … … public class JOSMTestRules implements TestRule, AfterEachCallback, BeforeEachCal 838 756 839 757 /** 840 758 * Override this test's timeout. 841 * @ see JOSMTestRules#timeout(int)759 * @deprecated no-op, use {@link org.junit.jupiter.api.Timeout} instead 842 760 */ 761 @Deprecated 843 762 @Documented 844 763 @Retention(RetentionPolicy.RUNTIME) 845 764 @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; 17 17 18 18 import javax.imageio.ImageIO; 19 19 20 import org.junit.runner.Description;21 import org.junit.runners.model.Statement;22 20 import org.openstreetmap.josm.data.imagery.ImageryInfo; 23 21 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 24 22 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 25 23 import org.openstreetmap.josm.tools.Logging; 26 24 25 import com.github.tomakehurst.wiremock.WireMockServer; 27 26 import com.github.tomakehurst.wiremock.client.MappingBuilder; 28 27 import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; 29 28 import com.github.tomakehurst.wiremock.client.WireMock; 30 import com.github.tomakehurst.wiremock.junit.WireMockRule;31 29 32 30 /** 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. 35 32 */ 36 public class TileSourceRule extends WireMock Rule{33 public class TileSourceRule extends WireMockServer { 37 34 private static class ByteArrayWrapper { 38 35 public final byte[] byteArray; 39 36 … … public class TileSourceRule extends WireMockRule { 61 58 62 59 /** 63 60 * @return a {@link MappingBuilder} representing the request matching properties of this tile source, suitable 64 * for passing to {@link WireMock Rule#stubFor}.61 * for passing to {@link WireMockServer#stubFor}. 65 62 */ 66 63 public abstract MappingBuilder getMappingBuilder(); 67 64 … … public class TileSourceRule extends WireMockRule { 167 164 protected final boolean clearSlippyMapSources; 168 165 protected final boolean registerInLayerList; 169 166 167 private List<SlippyMapBBoxChooser.TileSourceProvider> slippyMapProviders; 168 private SlippyMapBBoxChooser.TileSourceProvider slippyMapDefaultProvider; 169 private List<ImageryInfo> originalImageryInfoList; 170 private boolean layersRegistered; 171 170 172 /** 171 173 * Construct a TileSourceRule for use with a JUnit test. 172 174 * … … public class TileSourceRule extends WireMockRule { 184 186 * 185 187 * The three boolean parameters control whether to perform various steps registering the tile sources with parts 186 188 * 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. 189 190 * 190 191 * @param clearLayerList whether to clear ImageryLayerInfo's layer list of any pre-existing entries 191 192 * @param clearSlippyMapSources whether to clear SlippyMapBBoxChooser's stubborn fallback Mapnik TileSource … … public class TileSourceRule extends WireMockRule { 227 228 } 228 229 229 230 /** 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. 238 236 */ 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 } 254 257 } 255 258 256 259 /** 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. 264 265 */ 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 } 313 294 } 314 295 } 315 296 316 297 /** 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}. 319 299 */ 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 } 323 313 } 324 314 } -
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; 15 15 import org.junit.jupiter.api.extension.ExtensionContext; 16 16 import org.openstreetmap.josm.TestUtils; 17 17 import org.openstreetmap.josm.data.Version; 18 import org.openstreetmap.josm.testutils.JOSMTestRules;19 18 20 19 /** 21 20 * Override this test's assumed JOSM version (as reported by {@link Version}). 22 * @see JOSMTestRules#assumeRevision(String)23 21 */ 24 22 @Documented 25 23 @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; 23 23 import org.openstreetmap.josm.data.preferences.JosmUrls; 24 24 import org.openstreetmap.josm.spi.preferences.Config; 25 25 import org.openstreetmap.josm.spi.preferences.Setting; 26 import org.openstreetmap.josm.testutils.JOSMTestRules;27 26 28 27 /** 29 * Allow tests to use JOSM preferences (see {@link JOSMTestRules#preferences()}).28 * Allow tests to use JOSM preferences. 30 29 * This is often enough for basic tests. There are two modes: 31 30 * <ul> 32 31 * <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; 22 22 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 23 23 import org.openstreetmap.josm.gui.bbox.JosmMapViewer; 24 24 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 25 import org.openstreetmap.josm.testutils.JOSMTestRules;26 25 import org.openstreetmap.josm.testutils.TileSourceRule; 27 26 import org.openstreetmap.josm.tools.Logging; 28 27 … … import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 33 32 * Replace imagery sources with a default set of mock tile sources. 34 33 * @author Taylor Smock 35 34 * @since 18893 36 * @see JOSMTestRules#fakeImagery()37 35 */ 38 36 @Inherited 39 37 @Documented … … public @interface FakeImagery { 75 73 /** 76 74 * Construct a FakeImageryWireMockExtension for use with a JUnit test. 77 75 * <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. 81 78 * <p> 82 79 * The three boolean parameters control whether to perform various steps registering the tile sources with parts 83 80 * 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; 14 14 import org.openstreetmap.josm.data.Preferences; 15 15 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 16 16 import org.openstreetmap.josm.spi.preferences.Config; 17 import org.openstreetmap.josm.testutils.JOSMTestRules;18 17 import org.openstreetmap.josm.testutils.annotations.BasicPreferences.BasicPreferencesExtension; 19 18 20 19 /** 21 * Allow tests to use JOSM preferences with default values (see {@link JOSMTestRules#preferences()})20 * Allow tests to use JOSM preferences with default values 22 21 * @author Taylor Smock 23 22 * @see BasicPreferences (often enough for simple tests). 24 23 * @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; 15 15 import org.junit.jupiter.api.extension.ExtendWith; 16 16 import org.junit.jupiter.api.extension.ExtensionContext; 17 17 import org.openstreetmap.josm.io.CertificateAmendment; 18 import org.openstreetmap.josm.testutils.JOSMTestRules;19 18 20 19 /** 21 20 * Set up the HTTPS certificates 22 21 * @author Taylor Smock 23 22 * @since 18893 24 * @see JOSMTestRules#https()25 23 */ 26 24 @Inherited 27 25 @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; 18 18 /** 19 19 * Enables the i18n module for this test. 20 20 * @author Taylor Smock 21 * @see org.openstreetmap.josm.testutils.JOSMTestRules#i18n(String)22 21 * @since 17914 23 22 */ 24 23 @Documented … … public @interface I18n { 37 36 /** 38 37 * Enables the i18n module for this test. 39 38 * @author Taylor Smock 40 * @see org.openstreetmap.josm.testutils.JOSMTestRules#i18n(String)41 39 */ 42 40 class I18nExtension implements AfterEachCallback, BeforeEachCallback { 43 41 @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; 15 15 import org.junit.jupiter.api.extension.BeforeEachCallback; 16 16 import org.junit.jupiter.api.extension.ExtendWith; 17 17 import org.junit.jupiter.api.extension.ExtensionContext; 18 import org.openstreetmap.josm.JOSMFixture; 18 19 import org.openstreetmap.josm.actions.DeleteAction; 19 20 import org.openstreetmap.josm.command.DeleteCommand; 20 21 import org.openstreetmap.josm.data.Preferences; … … import org.openstreetmap.josm.data.osm.User; 23 24 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 24 25 import org.openstreetmap.josm.gui.util.GuiHelper; 25 26 import org.openstreetmap.josm.io.OsmConnection; 26 import org.openstreetmap.josm.testutils.JOSMTestRules;27 27 import org.openstreetmap.josm.tools.Logging; 28 28 import org.openstreetmap.josm.tools.MemoryManagerTest; 29 29 import org.openstreetmap.josm.tools.Utils; 30 30 31 31 /** 32 * Default actions taken by {@link JOSMTestRules}. Automatically registered.32 * Default actions taken for every test. Automatically registered. 33 33 * Functionality that this provides may be moved to other classes. 34 34 */ 35 35 @Target({ElementType.TYPE, ElementType.METHOD}) … … import org.openstreetmap.josm.tools.Utils; 37 37 @ExtendWith(JosmDefaults.DefaultsExtension.class) 38 38 public @interface JosmDefaults { 39 39 /** 40 * Default actions taken by {@link JOSMTestRules}. Automatically registered.40 * Default actions taken for every test. Automatically registered. 41 41 * Functionality that this provides may be moved to other classes. 42 42 */ 43 43 class DefaultsExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback, AfterEachCallback { … … public @interface JosmDefaults { 94 94 */ 95 95 private static void cleanUpFromJosmFixture() { 96 96 MemoryManagerTest.resetState(true); 97 JOSM TestRules.cleanLayerEnvironment();97 JOSMFixture.cleanLayerEnvironment(); 98 98 Preferences.main().resetToInitialState(); 99 99 Preferences.main().enableSaveOnPut(false); 100 100 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; 21 21 import org.junit.jupiter.api.extension.ExtensionContext; 22 22 import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 23 23 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 24 import org.openstreetmap.josm.testutils.JOSMTestRules;25 24 26 25 /** 27 * Use the JOSM home directory. See {@link JOSMTestRules}.26 * Use the JOSM home directory. 28 27 * Typically only used by {@link FullPreferences}. 29 28 * 30 29 * @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; 10 10 import org.junit.jupiter.api.extension.BeforeEachCallback; 11 11 import org.junit.jupiter.api.extension.ExtendWith; 12 12 import org.junit.jupiter.api.extension.ExtensionContext; 13 import org.openstreetmap.josm. testutils.JOSMTestRules;13 import org.openstreetmap.josm.JOSMFixture; 14 14 15 15 /** 16 16 * Clear the main {@link org.openstreetmap.josm.gui.layer.LayerManager} between tests. … … public @interface LayerManager { 30 30 class LayerManagerExtension implements BeforeEachCallback, AfterEachCallback { 31 31 @Override 32 32 public void afterEach(ExtensionContext context) { 33 JOSM TestRules.cleanLayerEnvironment();33 JOSMFixture.cleanLayerEnvironment(); 34 34 } 35 35 36 36 @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; 11 11 import org.junit.jupiter.api.extension.ExtendWith; 12 12 import org.junit.jupiter.api.extension.ExtensionContext; 13 13 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 14 import org.openstreetmap.josm.testutils.JOSMTestRules;15 14 16 15 /** 17 16 * Use map styles in tests. 18 17 * 19 18 * @author Taylor Smock 20 * @see JOSMTestRules#mapStyles()21 19 */ 22 20 @Documented 23 21 @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; 13 13 import org.junit.jupiter.api.extension.ExtendWith; 14 14 import org.junit.jupiter.api.extension.ExtensionContext; 15 15 import org.openstreetmap.josm.data.SystemOfMeasurement; 16 import org.openstreetmap.josm.testutils.JOSMTestRules;17 16 18 17 /** 19 18 * Set up the system of measurement 20 19 * @author Taylor Smock 21 20 * @since 18893 22 * @see JOSMTestRules#metricSystem()23 21 */ 24 22 @Inherited 25 23 @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; 10 10 import java.lang.annotation.Retention; 11 11 import java.lang.annotation.Target; 12 12 13 import org.openstreetmap.josm.testutils.JOSMTestRules;14 13 15 14 /** 16 15 * Allow the memory manager to contain items after execution of the test cases. 17 16 * @author Taylor Smock 18 17 * @since 18893 19 * @see JOSMTestRules#memoryManagerLeaks()20 18 */ 21 19 @Inherited 22 20 @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; 13 13 import org.junit.jupiter.api.extension.ExtendWith; 14 14 import org.junit.jupiter.api.extension.ExtensionContext; 15 15 import org.junit.platform.commons.support.ReflectionSupport; 16 import org.junit.runners.model.InitializationError;17 16 import org.openstreetmap.josm.io.OsmApiInitializationException; 18 17 import org.openstreetmap.josm.io.OsmTransferCanceledException; 19 18 import org.openstreetmap.josm.spi.preferences.Config; 20 19 import org.openstreetmap.josm.testutils.FakeOsmApi; 20 import org.openstreetmap.josm.tools.JosmRuntimeException; 21 21 22 22 /** 23 23 * Used for setting the desired OsmApi type … … public @interface OsmApi { 79 79 try { 80 80 org.openstreetmap.josm.io.OsmApi.getOsmApi().initialize(null); 81 81 } catch (OsmTransferCanceledException | OsmApiInitializationException e) { 82 throw new InitializationError(e);82 throw new JosmRuntimeException(e); 83 83 } 84 84 } 85 85 } -
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; 16 16 import org.junit.platform.commons.support.AnnotationSupport; 17 17 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 18 18 import org.openstreetmap.josm.data.projection.Projections; 19 import org.openstreetmap.josm.testutils.JOSMTestRules;20 19 21 20 /** 22 21 * Use projections in tests (Mercator). 23 22 * 24 23 * @author Taylor Smock 25 * @see JOSMTestRules#projection()26 24 * 27 25 */ 28 26 @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; 12 12 import org.junit.jupiter.api.extension.ExtendWith; 13 13 import org.junit.jupiter.api.extension.ExtensionContext; 14 14 import org.openstreetmap.josm.gui.MainApplication; 15 import org.openstreetmap.josm.testutils.JOSMTestRules;16 15 import org.openstreetmap.josm.tools.Utils; 17 16 18 17 /** 19 18 * Use NAD projections in tests. 20 19 * 21 20 * @author Taylor Smock 22 * @see JOSMTestRules#projectionNadGrids()23 21 * 24 22 */ 25 23 @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; 15 15 import org.junit.jupiter.api.extension.ExtendWith; 16 16 import org.junit.jupiter.api.extension.ExtensionContext; 17 17 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 18 import org.openstreetmap.josm.testutils.JOSMTestRules;19 18 20 19 /** 21 20 * Use presets in tests. 22 21 * 23 22 * @author Taylor Smock 24 * @see JOSMTestRules#presets()25 23 */ 26 24 @Documented 27 25 @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; 14 14 import org.junit.jupiter.api.extension.ExtendWith; 15 15 import org.junit.jupiter.api.extension.ExtensionContext; 16 16 import org.junit.platform.commons.support.AnnotationSupport; 17 import org.openstreetmap.josm.testutils.JOSMTestRules;18 17 19 18 /** 20 19 * Use boundaries dataset in this test. 21 20 * 22 * @see JOSMTestRules#territories()23 21 * @author Taylor Smock 24 22 * @since 18798 25 23 */ -
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; 42 42 * only the parts necessary for a particular case. 43 43 * 44 44 * The default {@link #getMockResultForMessage(Object)} will raise an 45 * {@link junit.framework.AssertionFailedError} on an activation without a matching mapping entry or if45 * {@link AssertionError} on an activation without a matching mapping entry or if 46 46 * the mapped result value is invalid for the call. 47 47 * 48 48 * 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 9 9 <conf name="pmd" description="Everything needed for running PMD"/> 10 10 <conf name="spotbugs" description="Everything needed for running SpotBugs"/> 11 11 <conf name="errorprone" description="Everything needed for running error-prone"/> 12 <conf name="errorprone_javac" description="Everything needed for running javac from error-prone"/>13 12 <conf name="animal" description="Everything needed for running Animal Sniffer"/> 14 13 </configurations> 15 14 <dependencies>
