kopia lustrzana https://github.com/JOSM/MapWithAI
Use assertThrows instead of ExpectedException
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
38c0bbeaaf
commit
1277c00ee1
|
@ -5,6 +5,7 @@ import static org.awaitility.Awaitility.await;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||||
|
|
||||||
|
@ -12,7 +13,6 @@ import org.awaitility.Awaitility;
|
||||||
import org.awaitility.Durations;
|
import org.awaitility.Durations;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.openstreetmap.josm.data.osm.BBox;
|
import org.openstreetmap.josm.data.osm.BBox;
|
||||||
import org.openstreetmap.josm.gui.MainApplication;
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
||||||
|
@ -29,13 +29,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MapWithAIRemoteControlTest {
|
public class MapWithAIRemoteControlTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* Rule used for tests throwing exceptions.
|
|
||||||
*/
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup test.
|
* Setup test.
|
||||||
*/
|
*/
|
||||||
|
@ -58,9 +51,9 @@ public class MapWithAIRemoteControlTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBadRequestInvalidUrl() throws Exception {
|
public void testBadRequestInvalidUrl() throws Exception {
|
||||||
thrown.expect(RequestHandlerBadRequestException.class);
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
||||||
thrown.expectMessage("MalformedURLException: no protocol: invalid_url");
|
() -> newHandler("https://localhost?url=invalid_url").handle());
|
||||||
newHandler("https://localhost?url=invalid_url").handle();
|
assertEquals("MalformedURLException: no protocol: invalid_url", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BBox getTestBBox() {
|
private static BBox getTestBBox() {
|
||||||
|
@ -98,10 +91,10 @@ public class MapWithAIRemoteControlTest {
|
||||||
assertNotEquals(badUrl, MapWithAIPreferenceHelper.getMapWithAIUrl());
|
assertNotEquals(badUrl, MapWithAIPreferenceHelper.getMapWithAIUrl());
|
||||||
|
|
||||||
final String badUrl2 = "NothingToSeeHere";
|
final String badUrl2 = "NothingToSeeHere";
|
||||||
thrown.expect(RequestHandlerBadRequestException.class);
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
||||||
thrown.expectMessage("MalformedURLException: no protocol: " + badUrl2);
|
() -> newHandler("https://localhost?url=" + Utils.encodeUrl(badUrl2)).handle());
|
||||||
|
assertEquals("MalformedURLException: no protocol: " + badUrl2, exception.getMessage());
|
||||||
|
|
||||||
newHandler("https://localhost?url=" + Utils.encodeUrl(badUrl2)).handle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -118,10 +111,11 @@ public class MapWithAIRemoteControlTest {
|
||||||
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
||||||
assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
|
||||||
|
|
||||||
thrown.expect(RequestHandlerBadRequestException.class);
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
||||||
thrown.expectMessage("NumberFormatException (For input string: \"BAD_VALUE\")");
|
() -> newHandler(
|
||||||
newHandler("http://127.0.0.1:8111/mapwithai?bbox=" + getTestBBox().toStringCSV(",") + "&max_obj=BAD_VALUE")
|
"http://127.0.0.1:8111/mapwithai?bbox=" + getTestBBox().toStringCSV(",") + "&max_obj=BAD_VALUE")
|
||||||
.handle();
|
.handle());
|
||||||
|
assertEquals("NumberFormatException (For input string: \"BAD_VALUE\")", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -140,11 +134,14 @@ public class MapWithAIRemoteControlTest {
|
||||||
assertTrue(temp.bounds(added));
|
assertTrue(temp.bounds(added));
|
||||||
|
|
||||||
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
|
||||||
temp = new BBox(39.0621223, -108.4625421, 39.0633059, -108.4594728);
|
BBox temp2 = new BBox(39.0621223, -108.4625421, 39.0633059, -108.4594728);
|
||||||
thrown.expect(RequestHandlerBadRequestException.class);
|
Exception exception = assertThrows(RequestHandlerBadRequestException.class,
|
||||||
thrown.expectMessage(
|
() -> newHandler(
|
||||||
"Bad bbox: 39.0621223,-108.4625421,39.0633059,-108.4594728 (converted to [ x: 39.0621223 -> 39.0633059, y: -108.4625421 -> -108.4594728 ])");
|
"http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp2.toStringCSV(",")))
|
||||||
newHandler("http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp.toStringCSV(","))).handle();
|
.handle());
|
||||||
|
assertEquals(
|
||||||
|
"Bad bbox: 39.0621223,-108.4625421,39.0633059,-108.4594728 (converted to [ x: 39.0621223 -> 39.0633059, y: -108.4625421 -> -108.4594728 ])",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Ładowanie…
Reference in New Issue