Ticket #16567: 16567.deprecated.1.patch

File 16567.deprecated.1.patch, 52.1 KB (added by taylor.smock, 6 years ago)

Fix (most) deprecation warnings. There is still one in ExpectedRootException and OptionParserTest.

  • test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

     
    55import static org.junit.Assert.assertFalse;
    66import static org.junit.Assert.assertNotNull;
    77import static org.junit.Assert.assertTrue;
     8import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     9import static org.junit.jupiter.api.Assertions.assertThrows;
    810
    911import java.lang.reflect.Field;
    1012import java.nio.charset.StandardCharsets;
     
    1820import org.junit.Assert;
    1921import org.junit.Rule;
    2022import org.junit.Test;
    21 import org.junit.rules.ExpectedException;
    2223import org.openstreetmap.josm.TestUtils;
    2324import org.openstreetmap.josm.data.coor.LatLon;
    2425import org.openstreetmap.josm.data.osm.DataSet;
     
    6061    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    6162    public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000);
    6263
    63     /**
    64      * Rule to assert exception message.
    65      */
    66     @Rule
    67     public ExpectedException expectedEx = ExpectedException.none();
    68 
    6964    private static final class SearchContext {
    7065        final DataSet ds = new DataSet();
    7166        final Node n1 = new Node(LatLon.ZERO);
     
    426421     */
    427422    @Test
    428423    public void testFooTypeBar() throws SearchParseError {
    429         expectedEx.expect(SearchParseError.class);
    430         expectedEx.expectMessage("<html>Expecting <code>:</code> after <i>type</i></html>");
    431         SearchCompiler.compile("foo type bar");
     424        Exception e = assertThrows(SearchParseError.class, () -> SearchCompiler.compile("foo type bar"));
     425        assertEquals("<html>Expecting <code>:</code> after <i>type</i></html>", e.getMessage());
    432426    }
    433427
    434428    /**
     
    552546     */
    553547    @Test
    554548    public void testEnumExactKeyValueMode() {
    555         TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class);
     549        assertDoesNotThrow(() -> TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class));
    556550    }
    557551
    558552    /**
  • test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

     
    44import static org.CustomMatchers.hasSize;
    55import static org.CustomMatchers.isEmpty;
    66import static org.hamcrest.CoreMatchers.not;
     7import static org.hamcrest.MatcherAssert.assertThat;
    78import static org.junit.Assert.assertEquals;
    89import static org.junit.Assert.assertNotNull;
    9 import static org.junit.Assert.assertThat;
    1010import static org.junit.Assert.assertTrue;
    1111
    1212import java.util.Arrays;
  • test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java

     
    33
    44import static org.CustomMatchers.hasSize;
    55import static org.CustomMatchers.isEmpty;
    6 import static org.junit.Assert.assertThat;
     6import static org.hamcrest.MatcherAssert.assertThat;
    77
    88import java.io.FileNotFoundException;
    99import java.io.IOException;
  • test/unit/org/openstreetmap/josm/data/validation/tests/UntaggedNodeTest.java

     
    33
    44import static org.CustomMatchers.hasSize;
    55import static org.CustomMatchers.isEmpty;
    6 import static org.junit.Assert.assertThat;
     6import static org.hamcrest.MatcherAssert.assertThat;
    77
    88import java.io.InputStream;
    99
  • test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui;
    33
     4import static org.hamcrest.MatcherAssert.assertThat;
    45import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertThat;
    66
    77import java.awt.Point;
    88import java.awt.Rectangle;
  • test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java

     
    22package org.openstreetmap.josm.gui.mappaint;
    33
    44import static org.CustomMatchers.isFP;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56
    67import java.util.ArrayList;
    78import java.util.Collection;
     
    1112import org.hamcrest.CoreMatchers;
    1213import org.hamcrest.Matcher;
    1314import org.junit.Rule;
    14 import org.junit.Assert;
    1515import org.junit.Test;
    1616import org.junit.runner.RunWith;
    1717import org.junit.runners.Parameterized;
     
    6969        LatLon aFeldberg = bFeldberg.getMin();
    7070        LatLon aFeldberg200mRight = new LatLon(aFeldberg.lat(), 13.433008399004041);
    7171        LatLon aFeldberg150mUp = new LatLon(53.33134745249311, aFeldberg.lon());
    72         Assert.assertThat(aFeldberg.greatCircleDistance(aFeldberg200mRight), isFP(200.0, 0.01));
    73         Assert.assertThat(aFeldberg.greatCircleDistance(aFeldberg150mUp), isFP(150.0, 0.01));
     72        assertThat(aFeldberg.greatCircleDistance(aFeldberg200mRight), isFP(200.0, 0.01));
     73        assertThat(aFeldberg.greatCircleDistance(aFeldberg150mUp), isFP(150.0, 0.01));
    7474
    7575        Bounds bFeldberg200x150m = new Bounds(
    7676                bFeldberg.getMin(), new LatLon(aFeldberg150mUp.lat(), aFeldberg200mRight.lon()));
     
    163163        RenderingCLI cli = new RenderingCLI();
    164164        cli.parseArguments(args);
    165165        RenderingCLI.RenderingArea ra = cli.determineRenderingArea(null);
    166         Assert.assertThat(ra.scale, scaleMatcher);
    167         Assert.assertThat(ra.bounds, boundsMatcher);
     166        assertThat(ra.scale, scaleMatcher);
     167        assertThat(ra.bounds, boundsMatcher);
    168168    }
    169169}
  • test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java

     
    22package org.openstreetmap.josm.gui.tagging.presets;
    33
    44import static org.CustomMatchers.hasSize;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56import static org.junit.Assert.assertEquals;
    6 import static org.junit.Assert.assertThat;
    77import static org.junit.Assert.assertTrue;
    88import static org.junit.Assert.fail;
    99
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    912import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    1619 * Unit tests of {@link AddNodeHandler} class.
    1720 */
    1821public class AddNodeHandlerTest {
    19 
    2022    /**
    21      * Rule used for tests throwing exceptions.
    22      */
    23     @Rule
    24     public ExpectedException thrown = ExpectedException.none();
    25 
    26     /**
    2723     * Setup test.
    2824     */
    2925    @Rule
     
    3935
    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}
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    912import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    1619 * Unit tests of {@link AddWayHandler} class.
    1720 */
    1821public class AddWayHandlerTest {
    19 
    2022    /**
    21      * Rule used for tests throwing exceptions.
    22      */
    23     @Rule
    24     public ExpectedException thrown = ExpectedException.none();
    25 
    26     /**
    2723     * Setup test.
    2824     */
    2925    @Rule
     
    3935
    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);
    6557        }
     
    6759
    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);
    10289        }
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java

     
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    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;
    911import java.util.List;
     
    1012
    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;
    1617import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2122 * Unit tests of {@link ImageryHandler} class.
    2223 */
    2324public class ImageryHandlerTest {
    24 
    2525    /**
    26      * Rule used for tests throwing exceptions.
    27      */
    28     @Rule
    29     public ExpectedException thrown = ExpectedException.none();
    30 
    31     /**
    3226     * Setup test.
    3327     */
    3428    @Rule
     
    4438
    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
    8775    /**
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java

     
    22package org.openstreetmap.josm.io.remotecontrol.handler;
    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;
    79
    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;
    1314import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    2122 * Unit tests of {@link ImportHandler} class.
    2223 */
    2324public class ImportHandlerTest {
    24 
    2525    /**
    26      * Rule used for tests throwing exceptions.
    27      */
    28     @Rule
    29     public ExpectedException thrown = ExpectedException.none();
    30 
    31     /**
    3226     * Setup test.
    3327     */
    3428    @Rule
     
    5852     */
    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
    6659    /**
     
    6962     */
    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
    7769    /**
     
    8072     */
    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
    8879    /**
     
    9384    public void testNominalRequest() throws Exception {
    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)) {
    9990                MainApplication.getLayerManager().removeLayer(layer);
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    912
     
    1316 * Unit tests of {@link LoadAndZoomHandler} class.
    1417 */
    1518public class LoadAndZoomHandlerTest {
    16 
    1719    /**
    18      * Rule used for tests throwing exceptions.
    19      */
    20     @Rule
    21     public ExpectedException thrown = ExpectedException.none();
    22 
    23     /**
    2420     * Setup test.
    2521     */
    2622    @Rule
     
    4036     */
    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
    4843    /**
     
    5146     */
    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
    5953    /**
     
    6256     */
    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
    7063    /**
     
    7366     */
    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}
  • test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    912
     
    1316 * Unit tests of {@link LoadObjectHandler} class.
    1417 */
    1518public class LoadObjectHandlerTest {
    16 
    1719    /**
    18      * Rule used for tests throwing exceptions.
    19      */
    20     @Rule
    21     public ExpectedException thrown = ExpectedException.none();
    22 
    23     /**
    2420     * Setup test.
    2521     */
    2622    @Rule
     
    3632
    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}
  • test/unit/org/openstreetmap/josm/tools/GeoUrlToBoundsTest.java

     
    22package org.openstreetmap.josm.tools;
    33
    44import static org.hamcrest.CoreMatchers.nullValue;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56import static org.hamcrest.core.Is.is;
    6 import static org.junit.Assert.assertThat;
    77
    88import org.junit.Test;
    99
  • test/unit/org/openstreetmap/josm/tools/OptionParserTest.java

     
    44import static org.junit.Assert.assertEquals;
    55import static org.junit.Assert.assertFalse;
    66import static org.junit.Assert.assertTrue;
     7import static org.junit.jupiter.api.Assertions.assertThrows;
    78
    89import java.util.ArrayList;
    910import java.util.Arrays;
     
    1112import java.util.concurrent.atomic.AtomicBoolean;
    1213import java.util.concurrent.atomic.AtomicReference;
    1314
    14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1515import org.junit.Rule;
    1616import org.junit.Test;
    1717import org.junit.rules.ExpectedException;
     
    1919import org.openstreetmap.josm.tools.OptionParser.OptionCount;
    2020import org.openstreetmap.josm.tools.OptionParser.OptionParseException;
    2121
     22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     23
    2224/**
    2325 * Test for {@link OptionParser}
    2426 * @author Michael Zangl
    2527 */
    2628public class OptionParserTest {
    27 
    28     /**
    29      * Rule used for tests throwing exceptions.
    30      */
    3129    @Rule
    3230    public ExpectedException thrown = ExpectedException.none();
    33 
    3431    /**
    3532     * Setup test.
    3633     */
     
    4138    // A reason for moving to jupiter...
    4239    @Test
    4340    public void testEmptyParserRejectsLongopt() {
    44         thrown.expect(OptionParseException.class);
    45         thrown.expectMessage("test: unrecognized option '--long'");
    46         new OptionParser("test").parseOptions(Arrays.asList("--long"));
     41        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").parseOptions(Arrays.asList("--long")));
     42        assertEquals("test: unrecognized option '--long'", e.getMessage());
    4743    }
    4844
    4945    @Test
    5046    public void testEmptyParserRejectsShortopt() {
    51         thrown.expect(OptionParseException.class);
    52         thrown.expectMessage("test: unrecognized option '-s'");
    53         new OptionParser("test").parseOptions(Arrays.asList("-s"));
     47        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").parseOptions(Arrays.asList("-s")));
     48        assertEquals("test: unrecognized option '-s'", e.getMessage());
    5449    }
    5550
    5651    @Test
    5752    public void testParserRejectsWrongShortopt() {
    58         thrown.expect(OptionParseException.class);
    59         thrown.expectMessage("test: unrecognized option '-s'");
    60         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "t")
    61                 .parseOptions(Arrays.asList("-s"));
     53        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "t")
     54                .parseOptions(Arrays.asList("-s")));
     55        assertEquals("test: unrecognized option '-s'", e.getMessage());
    6256    }
    6357
    6458    @Test
    6559    public void testParserRejectsWrongLongopt() {
    66         thrown.expect(OptionParseException.class);
    67         thrown.expectMessage("test: unrecognized option '--wrong'");
    68         new OptionParser("test").addFlagParameter("test", this::nop).parseOptions(Arrays.asList("--wrong"));
     60        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).parseOptions(Arrays.asList("--wrong")));
     61        assertEquals("test: unrecognized option '--wrong'", e.getMessage());
    6962    }
    7063
    7164    @Test
     
    8073
    8174    @Test
    8275    public void testParserOptionFailsIfMissing() {
    83         thrown.expect(OptionParseException.class);
    84         thrown.expectMessage("test: unrecognized option '--test2'");
    8576        AtomicReference<String> argFound = new AtomicReference<>();
    8677        OptionParser parser = new OptionParser("test")
    8778                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    8879
    89         parser.parseOptions(Arrays.asList("--test2", "arg"));
     80        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "arg")));
     81        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    9082    }
    9183
    9284    @Test
    9385    public void testParserOptionFailsIfMissingArgument() {
    94         thrown.expect(OptionParseException.class);
    95         thrown.expectMessage("test: unrecognized option '--test2'");
    9686        AtomicReference<String> argFound = new AtomicReference<>();
    9787        OptionParser parser = new OptionParser("test")
    9888                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    9989
    100         parser.parseOptions(Arrays.asList("--test2", "--other"));
     90        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "--other")));
     91        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    10192    }
    10293
    10394    @Test
    10495    public void testParserOptionFailsIfMissing2() {
    105         thrown.expect(OptionParseException.class);
    106         thrown.expectMessage("test: option '--test' is required");
    10796        AtomicReference<String> argFound = new AtomicReference<>();
    10897        OptionParser parser = new OptionParser("test")
    10998                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    11099
    111         parser.parseOptions(Arrays.asList("--", "--test", "arg"));
     100        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--", "--test", "arg")));
     101        assertEquals("test: option '--test' is required", e.getMessage());
    112102    }
    113103
    114104    @Test
    115105    public void testParserOptionFailsIfTwice() {
    116         thrown.expect(OptionParseException.class);
    117         thrown.expectMessage("test: option '--test' may not appear multiple times");
    118106        AtomicReference<String> argFound = new AtomicReference<>();
    119107        OptionParser parser = new OptionParser("test")
    120108                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    121109
    122         parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg"));
     110        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg")));
     111        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    123112    }
    124113
    125114    @Test
    126115    public void testParserOptionFailsIfTwiceForAlias() {
    127         thrown.expect(OptionParseException.class);
    128         thrown.expectMessage("test: option '-t' may not appear multiple times");
    129116        AtomicReference<String> argFound = new AtomicReference<>();
    130117        OptionParser parser = new OptionParser("test")
    131118                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set)
    132119                .addShortAlias("test", "t");
    133120
    134         parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg"));
     121        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg")));
     122        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    135123    }
    136124
    137125    @Test
    138126    public void testOptionalOptionFailsIfTwice() {
    139         thrown.expect(OptionParseException.class);
    140         thrown.expectMessage("test: option '--test' may not appear multiple times");
    141127        OptionParser parser = new OptionParser("test")
    142128                .addFlagParameter("test", this::nop);
    143         parser.parseOptions(Arrays.asList("--test", "--test"));
     129        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--test")));
     130        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    144131    }
    145132
    146133    @Test
    147134    public void testOptionalOptionFailsIfTwiceForAlias() {
    148         thrown.expect(OptionParseException.class);
    149         thrown.expectMessage("test: option '-t' may not appear multiple times");
    150135        OptionParser parser = new OptionParser("test")
    151136                .addFlagParameter("test", this::nop)
    152137                .addShortAlias("test", "t");
    153         parser.parseOptions(Arrays.asList("-t", "-t"));
     138        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "-t")));
     139        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    154140    }
    155141
    156142    @Test
    157143    public void testOptionalOptionFailsIfTwiceForAlias2() {
    158         thrown.expect(OptionParseException.class);
    159         thrown.expectMessage("test: option '-t' may not appear multiple times");
    160144        OptionParser parser = new OptionParser("test")
    161145                .addFlagParameter("test", this::nop)
    162146                .addShortAlias("test", "t");
    163         parser.parseOptions(Arrays.asList("-tt"));
     147        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-tt")));
     148        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    164149    }
    165150
    166151    @Test
     
    187172
    188173    @Test
    189174    public void testLongArgumentsMissingOption() {
    190         thrown.expect(OptionParseException.class);
    191         thrown.expectMessage("test: option '--test' requires an argument");
    192175        OptionParser parser = new OptionParser("test")
    193176                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    194177
    195         parser.parseOptions(Arrays.asList("--test"));
     178        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test")));
     179        assertEquals("test: option '--test' requires an argument", e.getMessage());
    196180    }
    197181
    198182    @Test
    199183    public void testLongArgumentsMissingOption2() {
    200         thrown.expect(OptionParseException.class);
    201         thrown.expectMessage("test: option '--test' requires an argument");
    202184        OptionParser parser = new OptionParser("test")
    203185                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    204186
    205         parser.parseOptions(Arrays.asList("--test", "--", "x"));
     187        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--", "x")));
     188        assertEquals("test: option '--test' requires an argument", e.getMessage());
    206189    }
    207190
    208191    @Test
    209192    public void testShortArgumentsMissingOption() {
    210         thrown.expect(OptionParseException.class);
    211         thrown.expectMessage("test: option '-t' requires an argument");
    212193        OptionParser parser = new OptionParser("test")
    213194                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    214195                .addShortAlias("test", "t");
    215196
    216         parser.parseOptions(Arrays.asList("-t"));
     197        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t")));
     198        assertEquals("test: option '-t' requires an argument", e.getMessage());
    217199    }
    218200
    219201    @Test
    220202    public void testShortArgumentsMissingOption2() {
    221         thrown.expect(OptionParseException.class);
    222         thrown.expectMessage("test: option '-t' requires an argument");
    223203        OptionParser parser = new OptionParser("test")
    224204                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    225205                .addShortAlias("test", "t");
    226206
    227         parser.parseOptions(Arrays.asList("-t", "--", "x"));
     207        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "--", "x")));
     208        assertEquals("test: option '-t' requires an argument", e.getMessage());
    228209    }
    229210
    230211    @Test
    231212    public void testLongFlagHasOption() {
    232         thrown.expect(OptionParseException.class);
    233         thrown.expectMessage("test: option '--test' does not allow an argument");
    234213        OptionParser parser = new OptionParser("test")
    235214                .addFlagParameter("test", this::nop);
    236215
    237         parser.parseOptions(Arrays.asList("--test=arg"));
     216        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test=arg")));
     217        assertEquals("test: option '--test' does not allow an argument", e.getMessage());
    238218    }
    239219
    240220    @Test
    241221    public void testShortFlagHasOption() {
    242         thrown.expect(OptionParseException.class);
    243         thrown.expectMessage("test: option '-t' does not allow an argument");
    244222        OptionParser parser = new OptionParser("test")
    245223                .addFlagParameter("test", this::nop)
    246224                .addShortAlias("test", "t");
    247225
    248         parser.parseOptions(Arrays.asList("-t=arg"));
     226        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t=arg")));
     227        assertEquals("test: option '-t' does not allow an argument", e.getMessage());
    249228    }
    250229
    251230    @Test
     
    305284
    306285    @Test
    307286    public void testAmbiguousAlternatives() {
    308         thrown.expect(OptionParseException.class);
    309         thrown.expectMessage("test: option '--fl' is ambiguous");
    310287        AtomicReference<String> argFound = new AtomicReference<>();
    311288        AtomicBoolean usedFlag = new AtomicBoolean();
    312289        AtomicBoolean unusedFlag = new AtomicBoolean();
     
    316293                .addFlagParameter("flag", () -> usedFlag.set(true))
    317294                .addFlagParameter("fleg", () -> unusedFlag.set(true));
    318295
    319         parser.parseOptions(Arrays.asList("--te=arg", "--fl"));
     296        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--te=arg", "--fl")));
     297        assertEquals("test: option '--fl' is ambiguous", e.getMessage());
    320298    }
    321299
    322300    @Test
    323301    public void testMultipleShort() {
     302        // TODO figure out what is supposed to happen here
    324303        thrown.expect(OptionParseException.class);
    325304        thrown.expectMessage("test: unrecognized option '-ft'");
    326305        AtomicReference<String> argFound = new AtomicReference<>();
     
    334313                .addShortAlias("flag", "f")
    335314                .addFlagParameter("fleg", () -> unusedFlag.set(true));
    336315
    337         List<String> remaining = parser.parseOptions(Arrays.asList("-ft=arg", "x"));
     316        final List<String> remaining = new ArrayList<>();
     317        remaining.addAll(parser.parseOptions(Arrays.asList("-ft=arg", "x")));
     318        Exception e = assertThrows(OptionParseException.class, () -> remaining.addAll(parser.parseOptions(Arrays.asList("-ft=arg", "x"))));
     319        assertEquals("test: unrecognized option '-ft'", e.getMessage());
    338320
    339321        assertEquals(Arrays.asList("x"), remaining);
    340322        assertEquals("arg", argFound.get());
     
    341323        assertTrue(usedFlag.get());
    342324        assertFalse(unusedFlag.get());
    343325
    344         remaining = parser.parseOptions(Arrays.asList("-ft", "arg", "x"));
     326        remaining.clear();
     327        remaining.addAll(parser.parseOptions(Arrays.asList("-ft", "arg", "x")));
    345328
    346329        assertEquals(Arrays.asList("x"), remaining);
    347330        assertEquals("arg", argFound.get());
     
    348331        assertTrue(usedFlag.get());
    349332        assertFalse(unusedFlag.get());
    350333
    351         remaining = parser.parseOptions(Arrays.asList("-f", "-t=arg", "x"));
     334        remaining.clear();
     335        remaining.addAll(parser.parseOptions(Arrays.asList("-f", "-t=arg", "x")));
    352336
    353337        assertEquals(Arrays.asList("x"), remaining);
    354338        assertEquals("arg", argFound.get());
     
    358342
    359343    @Test
    360344    public void testIllegalOptionName() {
    361         thrown.expect(IllegalArgumentException.class);
    362         thrown.expectMessage("Illegal option name: ''");
    363         new OptionParser("test").addFlagParameter("", this::nop);
     345        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("", this::nop));
     346        assertEquals("Illegal option name: ''", e.getMessage());
    364347    }
    365348
    366349    @Test
    367350    public void testIllegalOptionName2() {
    368         thrown.expect(IllegalArgumentException.class);
    369         thrown.expectMessage("Illegal option name: '-'");
    370         new OptionParser("test").addFlagParameter("-", this::nop);
     351        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-", this::nop));
     352        assertEquals("Illegal option name: '-'", e.getMessage());
    371353    }
    372354
    373355    @Test
    374356    public void testIllegalOptionName3() {
    375         thrown.expect(IllegalArgumentException.class);
    376         thrown.expectMessage("Illegal option name: '-test'");
    377         new OptionParser("test").addFlagParameter("-test", this::nop);
     357        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-test", this::nop));
     358        assertEquals("Illegal option name: '-test'", e.getMessage());
    378359    }
    379360
    380361    @Test
    381362    public void testIllegalOptionName4() {
    382         thrown.expect(IllegalArgumentException.class);
    383         thrown.expectMessage("Illegal option name: '$'");
    384         new OptionParser("test").addFlagParameter("$", this::nop);
     363        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("$", this::nop));
     364        assertEquals("Illegal option name: '$'", e.getMessage());
    385365    }
    386366
    387367    @Test
    388368    public void testDuplicateOptionName() {
    389         thrown.expect(IllegalArgumentException.class);
    390         thrown.expectMessage("The option '--test' is already registered");
    391         new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop);
     369        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop));
     370        assertEquals("The option '--test' is already registered", e.getMessage());
    392371    }
    393372
    394373    @Test
    395374    public void testDuplicateOptionName2() {
    396         thrown.expect(IllegalArgumentException.class);
    397         thrown.expectMessage("The option '--test' is already registered");
    398         new OptionParser("test").addFlagParameter("test", this::nop)
    399             .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop);
     375        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop)
     376            .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop));
     377        assertEquals("The option '--test' is already registered", e.getMessage());
    400378    }
    401379
    402380    @Test
    403381    public void testInvalidShortAlias() {
    404         thrown.expect(IllegalArgumentException.class);
    405         thrown.expectMessage("Short name '$' must be one character");
    406         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$");
     382        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$"));
     383        assertEquals("Short name '$' must be one character", e.getMessage());
    407384    }
    408385
    409386    @Test
    410387    public void testInvalidShortAlias2() {
    411         thrown.expect(IllegalArgumentException.class);
    412         thrown.expectMessage("Short name '' must be one character");
    413         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "");
     388        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", ""));
     389        assertEquals("Short name '' must be one character", e.getMessage());
    414390    }
    415391
    416392    @Test
    417393    public void testInvalidShortAlias3() {
    418         thrown.expect(IllegalArgumentException.class);
    419         thrown.expectMessage("Short name 'xx' must be one character");
    420         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx");
     394        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx"));
     395        assertEquals("Short name 'xx' must be one character", e.getMessage());
    421396    }
    422397
    423398    @Test
    424399    public void testDuplicateShortAlias() {
    425         thrown.expect(IllegalArgumentException.class);
    426         thrown.expectMessage("Short name 't' is already used");
    427         new OptionParser("test").addFlagParameter("test", this::nop)
     400        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop)
    428401        .addFlagParameter("test2", this::nop)
    429402        .addShortAlias("test", "t")
    430         .addShortAlias("test2", "t");
     403        .addShortAlias("test2", "t"));
     404        assertEquals("Short name 't' is already used", e.getMessage());
    431405    }
    432406
    433407    @Test
    434408    public void testInvalidShortNoLong() {
    435         thrown.expect(IllegalArgumentException.class);
    436         thrown.expectMessage("No long definition for test2 was defined. " +
    437                 "Define the long definition first before creating a short definition for it.");
    438         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t");
     409        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t"));
     410        assertEquals("No long definition for test2 was defined. " +
     411                "Define the long definition first before creating a short definition for it.", e.getMessage());
    439412    }
    440413
    441414    private void nop() {
  • test/unit/org/openstreetmap/josm/tools/StringParserTest.java

     
    22package org.openstreetmap.josm.tools;
    33
    44import static org.hamcrest.CoreMatchers.is;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56import static org.junit.Assert.assertFalse;
    6 import static org.junit.Assert.assertThat;
    77import static org.junit.Assert.assertTrue;
    88
    99import java.util.Optional;
    1010
    11 import net.trajano.commons.testing.UtilityClassTestUtil;
    1211import org.junit.Test;
    1312
     13import net.trajano.commons.testing.UtilityClassTestUtil;
     14
    1415/**
    1516 * Unit tests of {@link StringParser} class.
    1617 */