Changeset 19056 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2024-04-24T20:02:57+02:00 (8 months ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r18991 r19056 592 592 ) { 593 593 assertArrayEquals( 594 Utils.readBytesFromStream(streamA),595 Utils.readBytesFromStream(streamB)594 streamA.readAllBytes(), 595 streamB.readAllBytes() 596 596 ); 597 597 } -
trunk/test/unit/org/openstreetmap/josm/actions/SessionSaveActionTest.java
r18800 r19056 55 55 56 56 JOptionPaneSimpleMocker mocker = new JOptionPaneSimpleMocker(Collections.singletonMap(overrideStr, 0)); 57 SessionSaveAction.setCurrentSession(jos, false,Arrays.asList(gpx, osm)); //gpx and OSM layer57 SessionSaveAction.setCurrentSession(jos, Arrays.asList(gpx, osm)); //gpx and OSM layer 58 58 MainApplication.getLayerManager().addLayer(gpx); //only gpx layer 59 59 saveAction.actionPerformed(null); //Complain that OSM layer was removed -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java
r18893 r19056 19 19 import org.openstreetmap.josm.plugins.PluginInformation; 20 20 import org.openstreetmap.josm.testutils.annotations.AssumeRevision; 21 import org.openstreetmap.josm.tools.Utils;22 21 23 22 /** … … 129 128 assertArrayEquals( 130 129 existingPluginContents, 131 Utils.readBytesFromStream(pluginDirPluginStream)130 pluginDirPluginStream.readAllBytes() 132 131 ); 133 132 } -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r18893 r19056 170 170 } 171 171 try { 172 byte[] data = Utils.readBytesFromStream(response.getContent());172 byte[] data = response.getContent().readAllBytes(); 173 173 if (response.getResponseCode() < 300) { 174 174 workingURLs.put(url, data); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java
r18893 r19056 17 17 import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT; 18 18 import org.openstreetmap.josm.testutils.annotations.HTTPS; 19 import org.openstreetmap.josm.tools.Utils;20 19 21 20 /** … … 60 59 assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, connection.getResponseCode()); 61 60 try (InputStream is = connection.getErrorStream()) { 62 String responseBody = new String( Utils.readBytesFromStream(is), StandardCharsets.UTF_8);61 String responseBody = new String(is.readAllBytes(), StandardCharsets.UTF_8); 63 62 assert responseBody.contains(RequestProcessor.getUsageAsHtml()); 64 63 } -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
r18870 r19056 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.fail;6 5 7 6 import java.awt.Color; 8 7 import java.io.File; 9 8 import java.io.IOException; 9 import java.io.UncheckedIOException; 10 10 import java.nio.charset.StandardCharsets; 11 11 import java.nio.file.Files; … … 134 134 return Collections.list(zipFile.entries()).stream().collect(Collectors.toMap(ZipEntry::getName, e -> { 135 135 try { 136 return Utils.readBytesFromStream(zipFile.getInputStream(e));136 return zipFile.getInputStream(e).readAllBytes(); 137 137 } catch (IOException ex) { 138 fail(ex);138 throw new UncheckedIOException(ex); 139 139 } 140 return null;141 140 })); 142 141 } … … 275 274 276 275 Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers_combined.jos"); 277 String expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");276 String expected = Files.readString(path).replace("\r", ""); 278 277 String actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", ""); 279 278 assertEquals(expected, actual); 280 279 281 280 path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx"); 282 expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");281 expected = Files.readString(path).replace("\r", ""); 283 282 actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", ""); 284 283 assertEquals(expected, actual); … … 291 290 292 291 path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos"); 293 expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");292 expected = Files.readString(path).replace("\r", ""); 294 293 actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", ""); 295 294 assertEquals(expected, actual); 296 295 297 296 path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx"); 298 expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");297 expected = Files.readString(path).replace("\r", ""); 299 298 actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", ""); 300 299 assertEquals(expected, actual); 301 300 302 301 path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/markers.gpx"); 303 expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");302 expected = Files.readString(path).replace("\r", ""); 304 303 actual = new String(bytes.get("layers/02/data.gpx"), StandardCharsets.UTF_8).replace("\r", ""); 305 304 assertEquals(expected, actual); -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/AnnotationUtils.java
r18106 r19056 48 48 public static void resetStaticClass(Class<?> clazz) throws ReflectiveOperationException { 49 49 for (Field field : clazz.getDeclaredFields()) { 50 if (!field.isAccessible()) {51 field.setAccessible(true);52 }53 50 // Don't reset fields that are not static 54 51 if ((field.getModifiers() & Modifier.STATIC) == 0) { 55 52 continue; 53 } 54 if (!field.canAccess(null)) { 55 field.setAccessible(true); 56 56 } 57 57 final boolean isFinal = (field.getModifiers() & Modifier.FINAL) != 0; -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/BasicWiremock.java
r18893 r19056 41 41 42 42 import com.github.tomakehurst.wiremock.WireMockServer; 43 import com.github.tomakehurst.wiremock.extension.ResponseTransformer; 43 import com.github.tomakehurst.wiremock.client.WireMock; 44 import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2; 44 45 import com.github.tomakehurst.wiremock.verification.LoggedRequest; 45 46 … … 65 66 66 67 /** 67 * {@link ResponseTransformer } for use with the WireMock server.68 * {@link ResponseTransformerV2} for use with the WireMock server. 68 69 * Current constructors supported: 69 70 * <ul> … … 73 74 * @return The transformers to instantiate 74 75 */ 75 Class<? extends ResponseTransformer >[] responseTransformers() default {};76 Class<? extends ResponseTransformerV2>[] responseTransformers() default {}; 76 77 77 78 /** … … 92 93 .orElseThrow(() -> new IllegalArgumentException("There must be a @BasicWiremock annotation")); 93 94 return context.getStore(namespace).getOrComputeIfAbsent(WireMockServer.class, clazz -> { 94 final List<ResponseTransformer > transformers = new ArrayList<>(annotation.responseTransformers().length);95 for (Class<? extends ResponseTransformer > responseTransformer : annotation.responseTransformers()) {95 final List<ResponseTransformerV2> transformers = new ArrayList<>(annotation.responseTransformers().length); 96 for (Class<? extends ResponseTransformerV2> responseTransformer : annotation.responseTransformers()) { 96 97 for (Pair<Class<?>[], Object[]> parameterMapping : Arrays.asList( 97 98 new Pair<>(new Class<?>[] {ExtensionContext.class }, new Object[] {context }), 98 99 new Pair<>(new Class<?>[0], new Object[0]))) { 99 100 try { 100 Constructor<? extends ResponseTransformer > constructor = responseTransformer101 Constructor<? extends ResponseTransformerV2> constructor = responseTransformer 101 102 .getConstructor(parameterMapping.a); 102 103 transformers.add(constructor.newInstance(parameterMapping.b)); … … 109 110 return new WireMockServer( 110 111 options().usingFilesUnderDirectory(Utils.isStripEmpty(annotation.value()) ? TestUtils.getTestDataRoot() : 111 annotation.value()).extensions(transformers.toArray(new ResponseTransformer [0])).dynamicPort());112 annotation.value()).extensions(transformers.toArray(new ResponseTransformerV2[0])).dynamicPort()); 112 113 }, WireMockServer.class); 113 114 } … … 167 168 for (Field field : wireMockFields) { 168 169 if (WireMockServer.class.isAssignableFrom(field.getType())) { 169 final boolean isAccessible = field. isAccessible();170 final boolean isAccessible = field.canAccess(context.getRequiredTestInstance()); 170 171 field.setAccessible(true); 171 172 try { … … 214 215 } 215 216 super.beforeAll(context); 216 Config.getPref().put("osm-server.url", getWiremock(context).baseUrl()); 217 Config.getPref().put("osm-server.url", getWiremock(context).baseUrl() + "/api"); 218 getWiremock(context).stubFor(WireMock.get("/api/0.6/capabilities") 219 .willReturn(WireMock.aResponse().withBodyFile("api/0.6/capabilities"))); 220 getWiremock(context).stubFor(WireMock.get("/api/capabilities") 221 .willReturn(WireMock.aResponse().withBodyFile("api/capabilities"))); 217 222 OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE); 218 223 } -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r18811 r19056 11 11 import java.io.File; 12 12 import java.io.IOException; 13 import java.io.InputStream; 13 14 import java.util.ArrayList; 14 15 import java.util.Arrays; … … 22 23 import java.util.regex.Pattern; 23 24 25 import org.junit.jupiter.api.Test; 26 24 27 import net.trajano.commons.testing.UtilityClassTestUtil; 25 import org.junit.jupiter.api.Test;26 28 27 29 /** … … 354 356 * Tests if readBytesFromStream handles null streams (might happen when there is no data on error stream) 355 357 * @throws IOException in case of I/O error 356 */ 357 @Test 358 * @deprecated {@link Utils#readBytesFromStream(InputStream)} is deprecated since the JVM has the same functionality. 359 */ 360 @Test 361 @Deprecated 358 362 void testNullStreamForReadBytesFromStream() throws IOException { 359 363 assertEquals(0, Utils.readBytesFromStream(null).length, "Empty on null stream");
Note:
See TracChangeset
for help on using the changeset viewer.