Changeset 16618 in josm for trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler
- Timestamp:
- 2020-06-14T11:54:13+02:00 (4 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java
r14217 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.data.osm.DataSet; 8 11 import org.openstreetmap.josm.gui.MainApplication; … … 17 20 */ 18 21 public class AddNodeHandlerTest { 19 20 /**21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 22 /** 27 23 * Setup test. … … 40 36 /** 41 37 * Unit test for bad request - no layer. 42 * @throws Exception if any error occurs43 38 */ 44 39 @Test 45 public void testBadRequestNoLayer() throws Exception { 46 thrown.expect(RequestHandlerBadRequestException.class); 47 thrown.expectMessage("There is no layer opened to add node"); 48 newHandler("https://localhost?lat=0&lon=0").handle(); 40 public void testBadRequestNoLayer() { 41 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?lat=0&lon=0").handle()); 42 assertEquals("There is no layer opened to add node", e.getMessage()); 49 43 } 50 44 51 45 /** 52 46 * Unit test for bad request - no param. 53 * @throws Exception if any error occurs54 47 */ 55 48 @Test 56 public void testBadRequestNoParam() throws Exception { 57 thrown.expect(RequestHandlerBadRequestException.class); 58 thrown.expectMessage("NumberFormatException (empty String)"); 49 public void testBadRequestNoParam() { 59 50 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 60 51 MainApplication.getLayerManager().addLayer(layer); 61 newHandler(null).handle(); 52 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 53 assertEquals("NumberFormatException (empty String)", e.getMessage()); 62 54 } 63 55 64 56 /** 65 57 * Unit test for bad request - invalid URL. 66 * @throws Exception if any error occurs67 58 */ 68 59 @Test 69 public void testBadRequestInvalidUrl() throws Exception { 70 thrown.expect(RequestHandlerBadRequestException.class); 71 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon"); 72 newHandler("invalid_url").handle(); 60 public void testBadRequestInvalidUrl() { 61 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 62 assertEquals("The following keys are mandatory, but have not been provided: lat, lon", e.getMessage()); 73 63 } 74 64 75 65 /** 76 66 * Unit test for bad request - incomplete URL. 77 * @throws Exception if any error occurs78 67 */ 79 68 @Test 80 public void testBadRequestIncompleteUrl() throws Exception { 81 thrown.expect(RequestHandlerBadRequestException.class); 82 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon"); 83 newHandler("https://localhost").handle(); 69 public void testBadRequestIncompleteUrl() { 70 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 71 assertEquals("The following keys are mandatory, but have not been provided: lat, lon", e.getMessage()); 84 72 } 85 73 86 74 /** 87 75 * Unit test for nominal request - local data file. 88 * @throws Exception if any error occurs89 76 */ 90 77 @Test 91 public void testNominalRequest() throws Exception{78 public void testNominalRequest() { 92 79 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 93 80 MainApplication.getLayerManager().addLayer(layer); 94 newHandler("https://localhost?lat=0&lon=0").handle();81 assertDoesNotThrow(() -> newHandler("https://localhost?lat=0&lon=0").handle()); 95 82 } 96 83 } -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java
r12636 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.data.osm.DataSet; 8 11 import org.openstreetmap.josm.gui.MainApplication; … … 17 20 */ 18 21 public class AddWayHandlerTest { 19 20 /**21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 22 /** 27 23 * Setup test. … … 40 36 /** 41 37 * Unit test for bad request - no layer. 42 * @throws Exception if any error occurs43 38 */ 44 39 @Test 45 public void testBadRequestNoLayer() throws Exception { 46 thrown.expect(RequestHandlerBadRequestException.class); 47 thrown.expectMessage("There is no layer opened to add way"); 48 newHandler("https://localhost?way=0,0;1,1").handle(); 40 public void testBadRequestNoLayer() { 41 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?way=0,0;1,1").handle()); 42 assertEquals("There is no layer opened to add way", e.getMessage()); 49 43 } 50 44 51 45 /** 52 46 * Unit test for bad request - no param. 53 * @throws Exception if any error occurs54 47 */ 55 48 @Test 56 public void testBadRequestNoParam() throws Exception { 57 thrown.expect(RequestHandlerBadRequestException.class); 58 thrown.expectMessage("Invalid coordinates: []"); 49 public void testBadRequestNoParam() { 59 50 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 60 51 try { 61 52 MainApplication.getLayerManager().addLayer(layer); 62 newHandler(null).handle(); 53 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 54 assertEquals("Invalid coordinates: []", e.getMessage()); 63 55 } finally { 64 56 MainApplication.getLayerManager().removeLayer(layer); … … 68 60 /** 69 61 * Unit test for bad request - invalid URL. 70 * @throws Exception if any error occurs71 62 */ 72 63 @Test 73 public void testBadRequestInvalidUrl() throws Exception { 74 thrown.expect(RequestHandlerBadRequestException.class); 75 thrown.expectMessage("The following keys are mandatory, but have not been provided: way"); 76 newHandler("invalid_url").handle(); 64 public void testBadRequestInvalidUrl() { 65 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 66 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage()); 77 67 } 78 68 79 69 /** 80 70 * Unit test for bad request - incomplete URL. 81 * @throws Exception if any error occurs82 71 */ 83 72 @Test 84 public void testBadRequestIncompleteUrl() throws Exception { 85 thrown.expect(RequestHandlerBadRequestException.class); 86 thrown.expectMessage("The following keys are mandatory, but have not been provided: way"); 87 newHandler("https://localhost").handle(); 73 public void testBadRequestIncompleteUrl() { 74 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 75 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage()); 88 76 } 89 77 90 78 /** 91 79 * Unit test for nominal request - local data file. 92 * @throws Exception if any error occurs93 80 */ 94 81 @Test 95 public void testNominalRequest() throws Exception{82 public void testNominalRequest() { 96 83 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 97 84 try { 98 85 MainApplication.getLayerManager().addLayer(layer); 99 newHandler("https://localhost?way=0,0;1,1").handle();86 assertDoesNotThrow(() -> newHandler("https://localhost?way=0,0;1,1").handle()); 100 87 } finally { 101 88 MainApplication.getLayerManager().removeLayer(layer); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java
r16589 r16618 3 3 4 4 import static org.hamcrest.CoreMatchers.hasItem; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertThat; 7 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 8 import static org.junit.jupiter.api.Assertions.assertThrows; 7 9 8 10 import java.util.Arrays; … … 11 13 import org.junit.Rule; 12 14 import org.junit.Test; 13 import org.junit.rules.ExpectedException;14 15 import org.openstreetmap.josm.data.imagery.ImageryInfo; 15 16 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; … … 22 23 */ 23 24 public class ImageryHandlerTest { 24 25 /**26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 25 /** 32 26 * Setup test. … … 45 39 /** 46 40 * Unit test for bad request - no param. 47 * @throws Exception if any error occurs48 41 */ 49 42 @Test 50 public void testBadRequestNoParam() throws Exception{51 thrown.expect(RequestHandlerBadRequestException.class);52 thrown.expectMessage("Parameter must not be null");53 newHandler(null).handle(); 43 public void testBadRequestNoParam() { 44 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 45 assertEquals("Parameter must not be null", e.getMessage()); 46 54 47 } 55 48 56 49 /** 57 50 * Unit test for bad request - invalid URL. 58 * @throws Exception if any error occurs59 51 */ 60 52 @Test 61 public void testBadRequestInvalidUrl() throws Exception { 62 thrown.expect(RequestHandlerBadRequestException.class); 63 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 64 newHandler("invalid_url").handle(); 53 public void testBadRequestInvalidUrl() { 54 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 55 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 65 56 } 66 57 67 58 /** 68 59 * Unit test for bad request - incomplete URL. 69 * @throws Exception if any error occurs70 60 */ 71 61 @Test 72 public void testBadRequestIncompleteUrl() throws Exception { 73 thrown.expect(RequestHandlerBadRequestException.class); 74 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 75 newHandler("https://localhost").handle(); 62 public void testBadRequestIncompleteUrl() { 63 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 64 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 76 65 } 77 66 78 67 /** 79 68 * Unit test for nominal request - local data file. 80 * @throws Exception if any error occurs81 69 */ 82 70 @Test 83 public void testNominalRequest() throws Exception{84 newHandler("https://localhost?url=foo").handle();71 public void testNominalRequest() { 72 assertDoesNotThrow(() -> newHandler("https://localhost?url=foo").handle()); 85 73 } 86 74 -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
r12636 r16618 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 5 7 6 8 import java.io.File; … … 8 10 import org.junit.Rule; 9 11 import org.junit.Test; 10 import org.junit.rules.ExpectedException;11 12 import org.openstreetmap.josm.TestUtils; 12 13 import org.openstreetmap.josm.gui.MainApplication; … … 22 23 */ 23 24 public class ImportHandlerTest { 24 25 /**26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 25 /** 32 26 * Setup test. … … 59 53 @Test 60 54 public void testBadRequestNoParam() throws Exception { 61 thrown.expect(RequestHandlerBadRequestException.class); 62 thrown.expectMessage("MalformedURLException: null"); 63 newHandler(null).handle(); 55 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 56 assertEquals("MalformedURLException: null", e.getMessage()); 64 57 } 65 58 … … 70 63 @Test 71 64 public void testBadRequestInvalidUrl() throws Exception { 72 thrown.expect(RequestHandlerBadRequestException.class); 73 thrown.expectMessage("MalformedURLException: no protocol: invalid_url"); 74 newHandler("https://localhost?url=invalid_url").handle(); 65 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?url=invalid_url").handle()); 66 assertEquals("MalformedURLException: no protocol: invalid_url", e.getMessage()); 75 67 } 76 68 … … 81 73 @Test 82 74 public void testBadRequestIncompleteUrl() throws Exception { 83 thrown.expect(RequestHandlerBadRequestException.class); 84 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 85 newHandler("https://localhost").handle(); 75 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 76 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 86 77 } 87 78 … … 94 85 String url = new File(TestUtils.getRegressionDataFile(11957, "data.osm")).toURI().toURL().toExternalForm(); 95 86 try { 96 newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle();87 assertDoesNotThrow(() -> newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle()); 97 88 } finally { 98 89 for (OsmDataLayer layer : MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)) { -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java
r12558 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 8 11 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 14 17 */ 15 18 public class LoadAndZoomHandlerTest { 16 17 /**18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 19 /** 24 20 * Setup test. … … 41 37 @Test 42 38 public void testBadRequestNoParam() throws Exception { 43 thrown.expect(RequestHandlerBadRequestException.class); 44 thrown.expectMessage("NumberFormatException (empty String)"); 45 newHandler(null).handle(); 39 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 40 assertEquals("NumberFormatException (empty String)", e.getMessage()); 46 41 } 47 42 … … 52 47 @Test 53 48 public void testBadRequestInvalidUrl() throws Exception { 54 thrown.expect(RequestHandlerBadRequestException.class); 55 thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); 56 newHandler("invalid_url").handle(); 49 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 50 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage()); 57 51 } 58 52 … … 63 57 @Test 64 58 public void testBadRequestIncompleteUrl() throws Exception { 65 thrown.expect(RequestHandlerBadRequestException.class); 66 thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); 67 newHandler("https://localhost").handle(); 59 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 60 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage()); 68 61 } 69 62 … … 74 67 @Test 75 68 public void testNominalRequest() throws Exception { 76 newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle();69 assertDoesNotThrow(() -> newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle()); 77 70 } 78 71 } -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java
r12558 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 8 11 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 14 17 */ 15 18 public class LoadObjectHandlerTest { 16 17 /**18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 19 /** 24 20 * Setup test. … … 37 33 /** 38 34 * Unit test for bad request - no param. 39 * @throws Exception if any error occurs40 35 */ 41 36 @Test 42 public void testBadRequestNoParam() throws Exception{43 newHandler(null).handle();37 public void testBadRequestNoParam() { 38 assertDoesNotThrow(() -> newHandler(null).handle()); 44 39 } 45 40 46 41 /** 47 42 * Unit test for bad request - invalid URL. 48 * @throws Exception if any error occurs49 43 */ 50 44 @Test 51 public void testBadRequestInvalidUrl() throws Exception { 52 thrown.expect(RequestHandlerBadRequestException.class); 53 thrown.expectMessage("The following keys are mandatory, but have not been provided: objects"); 54 newHandler("invalid_url").handle(); 45 public void testBadRequestInvalidUrl() { 46 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 47 assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage()); 55 48 } 56 49 57 50 /** 58 51 * Unit test for bad request - incomplete URL. 59 * @throws Exception if any error occurs60 52 */ 61 53 @Test 62 public void testBadRequestIncompleteUrl() throws Exception { 63 thrown.expect(RequestHandlerBadRequestException.class); 64 thrown.expectMessage("The following keys are mandatory, but have not been provided: objects"); 65 newHandler("https://localhost").handle(); 54 public void testBadRequestIncompleteUrl() { 55 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 56 assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage()); 66 57 } 67 58 68 59 /** 69 60 * Unit test for nominal request - local data file. 70 * @throws Exception if any error occurs71 61 */ 72 62 @Test 73 public void testNominalRequest() throws Exception{74 newHandler("https://localhost?objects=foo,bar").handle();63 public void testNominalRequest() { 64 assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle()); 75 65 } 76 66 }
Note:
See TracChangeset
for help on using the changeset viewer.