Ignore:
Timestamp:
2020-06-14T11:54:13+02:00 (4 years ago)
Author:
simon04
Message:

see #16567 - Fix deprecations related to JUnit 5 (patch by taylor.smock)

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  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertThrows;
     7
    48import org.junit.Rule;
    59import org.junit.Test;
    6 import org.junit.rules.ExpectedException;
    710import org.openstreetmap.josm.data.osm.DataSet;
    811import org.openstreetmap.josm.gui.MainApplication;
     
    1720 */
    1821public class AddNodeHandlerTest {
    19 
    20     /**
    21      * Rule used for tests throwing exceptions.
    22      */
    23     @Rule
    24     public ExpectedException thrown = ExpectedException.none();
    25 
    2622    /**
    2723     * Setup test.
     
    4036    /**
    4137     * Unit test for bad request - no layer.
    42      * @throws Exception if any error occurs
    4338     */
    4439    @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());
    4943    }
    5044
    5145    /**
    5246     * Unit test for bad request - no param.
    53      * @throws Exception if any error occurs
    5447     */
    5548    @Test
    56     public void testBadRequestNoParam() throws Exception {
    57         thrown.expect(RequestHandlerBadRequestException.class);
    58         thrown.expectMessage("NumberFormatException (empty String)");
     49    public void testBadRequestNoParam() {
    5950        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    6051        MainApplication.getLayerManager().addLayer(layer);
    61         newHandler(null).handle();
     52        Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
     53        assertEquals("NumberFormatException (empty String)", e.getMessage());
    6254    }
    6355
    6456    /**
    6557     * Unit test for bad request - invalid URL.
    66      * @throws Exception if any error occurs
    6758     */
    6859    @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());
    7363    }
    7464
    7565    /**
    7666     * Unit test for bad request - incomplete URL.
    77      * @throws Exception if any error occurs
    7867     */
    7968    @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());
    8472    }
    8573
    8674    /**
    8775     * Unit test for nominal request - local data file.
    88      * @throws Exception if any error occurs
    8976     */
    9077    @Test
    91     public void testNominalRequest() throws Exception {
     78    public void testNominalRequest() {
    9279        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    9380        MainApplication.getLayerManager().addLayer(layer);
    94         newHandler("https://localhost?lat=0&lon=0").handle();
     81        assertDoesNotThrow(() -> newHandler("https://localhost?lat=0&lon=0").handle());
    9582    }
    9683}
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java

    r12636 r16618  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertThrows;
     7
    48import org.junit.Rule;
    59import org.junit.Test;
    6 import org.junit.rules.ExpectedException;
    710import org.openstreetmap.josm.data.osm.DataSet;
    811import org.openstreetmap.josm.gui.MainApplication;
     
    1720 */
    1821public class AddWayHandlerTest {
    19 
    20     /**
    21      * Rule used for tests throwing exceptions.
    22      */
    23     @Rule
    24     public ExpectedException thrown = ExpectedException.none();
    25 
    2622    /**
    2723     * Setup test.
     
    4036    /**
    4137     * Unit test for bad request - no layer.
    42      * @throws Exception if any error occurs
    4338     */
    4439    @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());
    4943    }
    5044
    5145    /**
    5246     * Unit test for bad request - no param.
    53      * @throws Exception if any error occurs
    5447     */
    5548    @Test
    56     public void testBadRequestNoParam() throws Exception {
    57         thrown.expect(RequestHandlerBadRequestException.class);
    58         thrown.expectMessage("Invalid coordinates: []");
     49    public void testBadRequestNoParam() {
    5950        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    6051        try {
    6152            MainApplication.getLayerManager().addLayer(layer);
    62             newHandler(null).handle();
     53            Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
     54            assertEquals("Invalid coordinates: []", e.getMessage());
    6355        } finally {
    6456            MainApplication.getLayerManager().removeLayer(layer);
     
    6860    /**
    6961     * Unit test for bad request - invalid URL.
    70      * @throws Exception if any error occurs
    7162     */
    7263    @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());
    7767    }
    7868
    7969    /**
    8070     * Unit test for bad request - incomplete URL.
    81      * @throws Exception if any error occurs
    8271     */
    8372    @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());
    8876    }
    8977
    9078    /**
    9179     * Unit test for nominal request - local data file.
    92      * @throws Exception if any error occurs
    9380     */
    9481    @Test
    95     public void testNominalRequest() throws Exception {
     82    public void testNominalRequest() {
    9683        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    9784        try {
    9885            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());
    10087        } finally {
    10188            MainApplication.getLayerManager().removeLayer(layer);
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java

    r16589 r16618  
    33
    44import static org.hamcrest.CoreMatchers.hasItem;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56import static org.junit.Assert.assertEquals;
    6 import static org.junit.Assert.assertThat;
     7import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     8import static org.junit.jupiter.api.Assertions.assertThrows;
    79
    810import java.util.Arrays;
     
    1113import org.junit.Rule;
    1214import org.junit.Test;
    13 import org.junit.rules.ExpectedException;
    1415import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1516import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
     
    2223 */
    2324public class ImageryHandlerTest {
    24 
    25     /**
    26      * Rule used for tests throwing exceptions.
    27      */
    28     @Rule
    29     public ExpectedException thrown = ExpectedException.none();
    30 
    3125    /**
    3226     * Setup test.
     
    4539    /**
    4640     * Unit test for bad request - no param.
    47      * @throws Exception if any error occurs
    4841     */
    4942    @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
    5447    }
    5548
    5649    /**
    5750     * Unit test for bad request - invalid URL.
    58      * @throws Exception if any error occurs
    5951     */
    6052    @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());
    6556    }
    6657
    6758    /**
    6859     * Unit test for bad request - incomplete URL.
    69      * @throws Exception if any error occurs
    7060     */
    7161    @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());
    7665    }
    7766
    7867    /**
    7968     * Unit test for nominal request - local data file.
    80      * @throws Exception if any error occurs
    8169     */
    8270    @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());
    8573    }
    8674
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java

    r12636 r16618  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     6import static org.junit.jupiter.api.Assertions.assertThrows;
    57
    68import java.io.File;
     
    810import org.junit.Rule;
    911import org.junit.Test;
    10 import org.junit.rules.ExpectedException;
    1112import org.openstreetmap.josm.TestUtils;
    1213import org.openstreetmap.josm.gui.MainApplication;
     
    2223 */
    2324public class ImportHandlerTest {
    24 
    25     /**
    26      * Rule used for tests throwing exceptions.
    27      */
    28     @Rule
    29     public ExpectedException thrown = ExpectedException.none();
    30 
    3125    /**
    3226     * Setup test.
     
    5953    @Test
    6054    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());
    6457    }
    6558
     
    7063    @Test
    7164    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());
    7567    }
    7668
     
    8173    @Test
    8274    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());
    8677    }
    8778
     
    9485        String url = new File(TestUtils.getRegressionDataFile(11957, "data.osm")).toURI().toURL().toExternalForm();
    9586        try {
    96             newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle();
     87            assertDoesNotThrow(() -> newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle());
    9788        } finally {
    9889            for (OsmDataLayer layer : MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)) {
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java

    r12558 r16618  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertThrows;
     7
    48import org.junit.Rule;
    59import org.junit.Test;
    6 import org.junit.rules.ExpectedException;
    710import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
    811import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    1417 */
    1518public class LoadAndZoomHandlerTest {
    16 
    17     /**
    18      * Rule used for tests throwing exceptions.
    19      */
    20     @Rule
    21     public ExpectedException thrown = ExpectedException.none();
    22 
    2319    /**
    2420     * Setup test.
     
    4137    @Test
    4238    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());
    4641    }
    4742
     
    5247    @Test
    5348    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());
    5751    }
    5852
     
    6357    @Test
    6458    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());
    6861    }
    6962
     
    7467    @Test
    7568    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());
    7770    }
    7871}
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java

    r12558 r16618  
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertThrows;
     7
    48import org.junit.Rule;
    59import org.junit.Test;
    6 import org.junit.rules.ExpectedException;
    710import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
    811import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    1417 */
    1518public class LoadObjectHandlerTest {
    16 
    17     /**
    18      * Rule used for tests throwing exceptions.
    19      */
    20     @Rule
    21     public ExpectedException thrown = ExpectedException.none();
    22 
    2319    /**
    2420     * Setup test.
     
    3733    /**
    3834     * Unit test for bad request - no param.
    39      * @throws Exception if any error occurs
    4035     */
    4136    @Test
    42     public void testBadRequestNoParam() throws Exception {
    43         newHandler(null).handle();
     37    public void testBadRequestNoParam() {
     38        assertDoesNotThrow(() -> newHandler(null).handle());
    4439    }
    4540
    4641    /**
    4742     * Unit test for bad request - invalid URL.
    48      * @throws Exception if any error occurs
    4943     */
    5044    @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());
    5548    }
    5649
    5750    /**
    5851     * Unit test for bad request - incomplete URL.
    59      * @throws Exception if any error occurs
    6052     */
    6153    @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());
    6657    }
    6758
    6859    /**
    6960     * Unit test for nominal request - local data file.
    70      * @throws Exception if any error occurs
    7161     */
    7262    @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());
    7565    }
    7666}
Note: See TracChangeset for help on using the changeset viewer.