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
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r16582 r16618  
    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;
     
    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;
     
    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();
     
    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
     
    553547    @Test
    554548    public void testEnumExactKeyValueMode() {
    555         TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class);
     549        assertDoesNotThrow(() -> TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class));
    556550    }
    557551
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    r16178 r16618  
    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
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java

    r16006 r16618  
    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;
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UntaggedNodeTest.java

    r10945 r16618  
    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;
  • trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java

    r14138 r16618  
    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;
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java

    r11905 r16618  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.layer;
    3 
    4 import static org.hamcrest.CoreMatchers.any;
     3import static org.hamcrest.CoreMatchers.instanceOf;
     4import static org.hamcrest.CoreMatchers.is;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56import static org.junit.Assert.assertEquals;
    67import static org.junit.Assert.assertFalse;
     
    1011import static org.junit.Assert.assertTrue;
    1112import static org.junit.Assert.fail;
     13import static org.junit.jupiter.api.Assertions.assertThrows;
     14import static org.openstreetmap.josm.testutils.ThrowableRootCauseMatcher.hasRootCause;
    1215
    1316import java.awt.Component;
     
    2326
    2427import org.junit.Before;
    25 import org.junit.Rule;
    2628import org.junit.Test;
    2729import org.openstreetmap.josm.data.Bounds;
     
    3335import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    3436import org.openstreetmap.josm.gui.util.GuiHelper;
    35 import org.openstreetmap.josm.testutils.ExpectedRootException;
    3637import org.openstreetmap.josm.tools.bugreport.ReportedException;
    3738
     
    163164
    164165    /**
    165      * Rule used to expect exceptions.
    166      */
    167     @Rule
    168     public ExpectedRootException thrown = ExpectedRootException.none();
    169 
    170     /**
    171166     * Set up test layer manager.
    172167     */
     
    228223    @Test
    229224    public void testAddLayerFails() {
    230         thrown.expect(ReportedException.class);
    231         thrown.expectCause(any(InvocationTargetException.class));
    232         thrown.expectRootCause(any(IllegalArgumentException.class));
    233 
    234         TestLayer layer1 = new TestLayer();
    235         layerManager.addLayer(layer1);
    236         layerManager.addLayer(layer1);
     225        Exception e = assertThrows(ReportedException.class, () -> {
     226            TestLayer layer1 = new TestLayer();
     227            layerManager.addLayer(layer1);
     228            layerManager.addLayer(layer1);
     229        });
     230        assertThat(e.getCause(), is(instanceOf(InvocationTargetException.class)));
     231        assertThat(e.getCause(), hasRootCause(is(instanceOf(IllegalArgumentException.class))));
    237232    }
    238233
     
    242237    @Test
    243238    public void testAddLayerIllegalPosition() {
    244         thrown.expect(ReportedException.class);
    245         thrown.expectCause(any(InvocationTargetException.class));
    246         thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    247 
    248         TestLayer layer1 = new TestLayer() {
    249             @Override
    250             public LayerPositionStrategy getDefaultLayerPosition() {
    251                 return manager -> 42;
    252             }
    253         };
    254         layerManager.addLayer(layer1);
     239        Exception e = assertThrows(ReportedException.class, () -> {
     240            TestLayer layer1 = new TestLayer() {
     241                @Override
     242                public LayerPositionStrategy getDefaultLayerPosition() {
     243                    return manager -> 42;
     244                }
     245            };
     246            layerManager.addLayer(layer1);
     247        });
     248        assertThat(e.getCause(), is(instanceOf(InvocationTargetException.class)));
     249        assertThat(e.getCause(), hasRootCause(is(instanceOf(IndexOutOfBoundsException.class))));
    255250    }
    256251
     
    309304    @Test
    310305    public void testMoveLayerFailsRange() {
    311         thrown.expect(ReportedException.class);
    312         thrown.expectCause(any(InvocationTargetException.class));
    313         thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    314 
    315         TestLayer layer1 = new TestLayer();
    316         TestLayer layer2 = new TestLayer();
    317         layerManager.addLayer(layer1);
    318         layerManager.addLayer(layer2);
    319         layerManager.moveLayer(layer2, 2);
     306        Exception e = assertThrows(ReportedException.class, () -> {
     307            TestLayer layer1 = new TestLayer();
     308            TestLayer layer2 = new TestLayer();
     309            layerManager.addLayer(layer1);
     310            layerManager.addLayer(layer2);
     311            layerManager.moveLayer(layer2, 2);
     312        });
     313        assertThat(e.getCause(), is(instanceOf(InvocationTargetException.class)));
     314        assertThat(e.getCause(), hasRootCause(is(instanceOf(IndexOutOfBoundsException.class))));
    320315    }
    321316
     
    325320    @Test
    326321    public void testMoveLayerFailsNotInList() {
    327         thrown.expect(ReportedException.class);
    328         thrown.expectCause(any(InvocationTargetException.class));
    329         thrown.expectRootCause(any(IllegalArgumentException.class));
    330 
    331         TestLayer layer1 = new TestLayer();
    332         TestLayer layer2 = new TestLayer();
    333         layerManager.addLayer(layer1);
    334         layerManager.moveLayer(layer2, 0);
     322        Exception e = assertThrows(ReportedException.class, () -> {
     323            TestLayer layer1 = new TestLayer();
     324            TestLayer layer2 = new TestLayer();
     325            layerManager.addLayer(layer1);
     326            layerManager.moveLayer(layer2, 0);
     327        });
     328        assertThat(e.getCause(), is(instanceOf(InvocationTargetException.class)));
     329        assertThat(e.getCause(), hasRootCause(is(instanceOf(IllegalArgumentException.class))));
    335330    }
    336331
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java

    r12907 r16618  
    33
    44import static org.CustomMatchers.isFP;
     5import static org.hamcrest.MatcherAssert.assertThat;
    56
    67import java.util.ArrayList;
     
    1213import org.hamcrest.Matcher;
    1314import org.junit.Rule;
    14 import org.junit.Assert;
    1515import org.junit.Test;
    1616import org.junit.runner.RunWith;
     
    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(
     
    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}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java

    r16560 r16618  
    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;
  • 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}
  • trunk/test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java

    r10397 r16618  
    1717 * and {@code ExpectedException} cannot be extended because it has a private constructor.
    1818 * @see <a href="https://github.com/junit-team/junit4/pull/778">Github pull request</a>
     19 * @deprecated Use matchers instead with the return from {@link org.junit.jupiter.api.Assertions#assertThrows}
    1920 */
     21@Deprecated
    2022public final class ExpectedRootException implements TestRule {
    2123
  • trunk/test/unit/org/openstreetmap/josm/tools/GeoUrlToBoundsTest.java

    r15184 r16618  
    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;
  • trunk/test/unit/org/openstreetmap/josm/tools/OptionParserTest.java

    r16608 r16618  
    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;
     
    1213import java.util.concurrent.atomic.AtomicReference;
    1314
    14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1515import org.junit.Rule;
    1616import org.junit.Test;
    17 import org.junit.rules.ExpectedException;
    1817import org.openstreetmap.josm.testutils.JOSMTestRules;
    1918import org.openstreetmap.josm.tools.OptionParser.OptionCount;
    2019import org.openstreetmap.josm.tools.OptionParser.OptionParseException;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2122
    2223/**
     
    2526 */
    2627public class OptionParserTest {
    27 
    28     /**
    29      * Rule used for tests throwing exceptions.
    30      */
    31     @Rule
    32     public ExpectedException thrown = ExpectedException.none();
    33 
    3428    /**
    3529     * Setup test.
     
    4236    @Test
    4337    public void testEmptyParserRejectsLongopt() {
    44         thrown.expect(OptionParseException.class);
    45         thrown.expectMessage("test: unrecognized option '--long'");
    46         new OptionParser("test").parseOptions(Arrays.asList("--long"));
     38        Exception e = assertThrows(OptionParseException.class, () ->
     39                new OptionParser("test").parseOptions(Arrays.asList("--long")));
     40        assertEquals("test: unrecognized option '--long'", e.getMessage());
    4741    }
    4842
    4943    @Test
    5044    public void testEmptyParserRejectsShortopt() {
    51         thrown.expect(OptionParseException.class);
    52         thrown.expectMessage("test: unrecognized option '-s'");
    53         new OptionParser("test").parseOptions(Arrays.asList("-s"));
     45        Exception e = assertThrows(OptionParseException.class, () ->
     46                new OptionParser("test").parseOptions(Arrays.asList("-s")));
     47        assertEquals("test: unrecognized option '-s'", e.getMessage());
    5448    }
    5549
    5650    @Test
    5751    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"));
     52        Exception e = assertThrows(OptionParseException.class, () ->
     53                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, () ->
     61                new OptionParser("test").addFlagParameter("test", this::nop).parseOptions(Arrays.asList("--wrong")));
     62        assertEquals("test: unrecognized option '--wrong'", e.getMessage());
    6963    }
    7064
     
    8175    @Test
    8276    public void testParserOptionFailsIfMissing() {
    83         thrown.expect(OptionParseException.class);
    84         thrown.expectMessage("test: unrecognized option '--test2'");
    85         AtomicReference<String> argFound = new AtomicReference<>();
    86         OptionParser parser = new OptionParser("test")
    87                 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    88 
    89         parser.parseOptions(Arrays.asList("--test2", "arg"));
     77        AtomicReference<String> argFound = new AtomicReference<>();
     78        OptionParser parser = new OptionParser("test")
     79                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
     80
     81        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "arg")));
     82        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    9083    }
    9184
    9285    @Test
    9386    public void testParserOptionFailsIfMissingArgument() {
    94         thrown.expect(OptionParseException.class);
    95         thrown.expectMessage("test: unrecognized option '--test2'");
    96         AtomicReference<String> argFound = new AtomicReference<>();
    97         OptionParser parser = new OptionParser("test")
    98                 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    99 
    100         parser.parseOptions(Arrays.asList("--test2", "--other"));
     87        AtomicReference<String> argFound = new AtomicReference<>();
     88        OptionParser parser = new OptionParser("test")
     89                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
     90
     91        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "--other")));
     92        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    10193    }
    10294
    10395    @Test
    10496    public void testParserOptionFailsIfMissing2() {
    105         thrown.expect(OptionParseException.class);
    106         thrown.expectMessage("test: option '--test' is required");
    107         AtomicReference<String> argFound = new AtomicReference<>();
    108         OptionParser parser = new OptionParser("test")
    109                 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    110 
    111         parser.parseOptions(Arrays.asList("--", "--test", "arg"));
     97        AtomicReference<String> argFound = new AtomicReference<>();
     98        OptionParser parser = new OptionParser("test")
     99                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
     100
     101        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--", "--test", "arg")));
     102        assertEquals("test: option '--test' is required", e.getMessage());
    112103    }
    113104
    114105    @Test
    115106    public void testParserOptionFailsIfTwice() {
    116         thrown.expect(OptionParseException.class);
    117         thrown.expectMessage("test: option '--test' may not appear multiple times");
    118         AtomicReference<String> argFound = new AtomicReference<>();
    119         OptionParser parser = new OptionParser("test")
    120                 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    121 
    122         parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg"));
     107        AtomicReference<String> argFound = new AtomicReference<>();
     108        OptionParser parser = new OptionParser("test")
     109                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
     110
     111        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg")));
     112        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    123113    }
    124114
    125115    @Test
    126116    public void testParserOptionFailsIfTwiceForAlias() {
    127         thrown.expect(OptionParseException.class);
    128         thrown.expectMessage("test: option '-t' may not appear multiple times");
    129         AtomicReference<String> argFound = new AtomicReference<>();
    130         OptionParser parser = new OptionParser("test")
    131                 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set)
    132                 .addShortAlias("test", "t");
    133 
    134         parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg"));
     117        AtomicReference<String> argFound = new AtomicReference<>();
     118        OptionParser parser = new OptionParser("test")
     119                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set)
     120                .addShortAlias("test", "t");
     121
     122        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg")));
     123        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    135124    }
    136125
    137126    @Test
    138127    public void testOptionalOptionFailsIfTwice() {
    139         thrown.expect(OptionParseException.class);
    140         thrown.expectMessage("test: option '--test' may not appear multiple times");
    141128        OptionParser parser = new OptionParser("test")
    142129                .addFlagParameter("test", this::nop);
    143         parser.parseOptions(Arrays.asList("--test", "--test"));
     130        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--test")));
     131        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    144132    }
    145133
    146134    @Test
    147135    public void testOptionalOptionFailsIfTwiceForAlias() {
    148         thrown.expect(OptionParseException.class);
    149         thrown.expectMessage("test: option '-t' may not appear multiple times");
    150136        OptionParser parser = new OptionParser("test")
    151137                .addFlagParameter("test", this::nop)
    152138                .addShortAlias("test", "t");
    153         parser.parseOptions(Arrays.asList("-t", "-t"));
     139        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "-t")));
     140        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    154141    }
    155142
    156143    @Test
    157144    public void testOptionalOptionFailsIfTwiceForAlias2() {
    158         thrown.expect(OptionParseException.class);
    159         thrown.expectMessage("test: option '-t' may not appear multiple times");
    160145        OptionParser parser = new OptionParser("test")
    161146                .addFlagParameter("test", this::nop)
    162147                .addShortAlias("test", "t");
    163         parser.parseOptions(Arrays.asList("-tt"));
     148        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-tt")));
     149        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    164150    }
    165151
     
    188174    @Test
    189175    public void testLongArgumentsMissingOption() {
    190         thrown.expect(OptionParseException.class);
    191         thrown.expectMessage("test: option '--test' requires an argument");
    192176        OptionParser parser = new OptionParser("test")
    193177                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    194178
    195         parser.parseOptions(Arrays.asList("--test"));
     179        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test")));
     180        assertEquals("test: option '--test' requires an argument", e.getMessage());
    196181    }
    197182
    198183    @Test
    199184    public void testLongArgumentsMissingOption2() {
    200         thrown.expect(OptionParseException.class);
    201         thrown.expectMessage("test: option '--test' requires an argument");
    202185        OptionParser parser = new OptionParser("test")
    203186                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    204187
    205         parser.parseOptions(Arrays.asList("--test", "--", "x"));
     188        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--", "x")));
     189        assertEquals("test: option '--test' requires an argument", e.getMessage());
    206190    }
    207191
    208192    @Test
    209193    public void testShortArgumentsMissingOption() {
    210         thrown.expect(OptionParseException.class);
    211         thrown.expectMessage("test: option '-t' requires an argument");
    212194        OptionParser parser = new OptionParser("test")
    213195                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    214196                .addShortAlias("test", "t");
    215197
    216         parser.parseOptions(Arrays.asList("-t"));
     198        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t")));
     199        assertEquals("test: option '-t' requires an argument", e.getMessage());
    217200    }
    218201
    219202    @Test
    220203    public void testShortArgumentsMissingOption2() {
    221         thrown.expect(OptionParseException.class);
    222         thrown.expectMessage("test: option '-t' requires an argument");
    223204        OptionParser parser = new OptionParser("test")
    224205                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    225206                .addShortAlias("test", "t");
    226207
    227         parser.parseOptions(Arrays.asList("-t", "--", "x"));
     208        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "--", "x")));
     209        assertEquals("test: option '-t' requires an argument", e.getMessage());
    228210    }
    229211
    230212    @Test
    231213    public void testLongFlagHasOption() {
    232         thrown.expect(OptionParseException.class);
    233         thrown.expectMessage("test: option '--test' does not allow an argument");
    234214        OptionParser parser = new OptionParser("test")
    235215                .addFlagParameter("test", this::nop);
    236216
    237         parser.parseOptions(Arrays.asList("--test=arg"));
     217        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test=arg")));
     218        assertEquals("test: option '--test' does not allow an argument", e.getMessage());
    238219    }
    239220
    240221    @Test
    241222    public void testShortFlagHasOption() {
    242         thrown.expect(OptionParseException.class);
    243         thrown.expectMessage("test: option '-t' does not allow an argument");
    244223        OptionParser parser = new OptionParser("test")
    245224                .addFlagParameter("test", this::nop)
    246225                .addShortAlias("test", "t");
    247226
    248         parser.parseOptions(Arrays.asList("-t=arg"));
     227        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t=arg")));
     228        assertEquals("test: option '-t' does not allow an argument", e.getMessage());
    249229    }
    250230
     
    306286    @Test
    307287    public void testAmbiguousAlternatives() {
    308         thrown.expect(OptionParseException.class);
    309         thrown.expectMessage("test: option '--fl' is ambiguous");
    310288        AtomicReference<String> argFound = new AtomicReference<>();
    311289        AtomicBoolean usedFlag = new AtomicBoolean();
     
    317295                .addFlagParameter("fleg", () -> unusedFlag.set(true));
    318296
    319         parser.parseOptions(Arrays.asList("--te=arg", "--fl"));
     297        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--te=arg", "--fl")));
     298        assertEquals("test: option '--fl' is ambiguous", e.getMessage());
    320299    }
    321300
     
    350329    @Test
    351330    public void testIllegalOptionName() {
    352         thrown.expect(IllegalArgumentException.class);
    353         thrown.expectMessage("Illegal option name: ''");
    354         new OptionParser("test").addFlagParameter("", this::nop);
     331        Exception e = assertThrows(IllegalArgumentException.class, () ->
     332                new OptionParser("test").addFlagParameter("", this::nop));
     333        assertEquals("Illegal option name: ''", e.getMessage());
    355334    }
    356335
    357336    @Test
    358337    public void testIllegalOptionName2() {
    359         thrown.expect(IllegalArgumentException.class);
    360         thrown.expectMessage("Illegal option name: '-'");
    361         new OptionParser("test").addFlagParameter("-", this::nop);
     338        Exception e = assertThrows(IllegalArgumentException.class, () ->
     339                new OptionParser("test").addFlagParameter("-", this::nop));
     340        assertEquals("Illegal option name: '-'", e.getMessage());
    362341    }
    363342
    364343    @Test
    365344    public void testIllegalOptionName3() {
    366         thrown.expect(IllegalArgumentException.class);
    367         thrown.expectMessage("Illegal option name: '-test'");
    368         new OptionParser("test").addFlagParameter("-test", this::nop);
     345        Exception e = assertThrows(IllegalArgumentException.class, () ->
     346                new OptionParser("test").addFlagParameter("-test", this::nop));
     347        assertEquals("Illegal option name: '-test'", e.getMessage());
    369348    }
    370349
    371350    @Test
    372351    public void testIllegalOptionName4() {
    373         thrown.expect(IllegalArgumentException.class);
    374         thrown.expectMessage("Illegal option name: '$'");
    375         new OptionParser("test").addFlagParameter("$", this::nop);
     352        Exception e = assertThrows(IllegalArgumentException.class, () ->
     353                new OptionParser("test").addFlagParameter("$", this::nop));
     354        assertEquals("Illegal option name: '$'", e.getMessage());
    376355    }
    377356
    378357    @Test
    379358    public void testDuplicateOptionName() {
    380         thrown.expect(IllegalArgumentException.class);
    381         thrown.expectMessage("The option '--test' is already registered");
    382         new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop);
     359        Exception e = assertThrows(IllegalArgumentException.class, () ->
     360                new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop));
     361        assertEquals("The option '--test' is already registered", e.getMessage());
    383362    }
    384363
    385364    @Test
    386365    public void testDuplicateOptionName2() {
    387         thrown.expect(IllegalArgumentException.class);
    388         thrown.expectMessage("The option '--test' is already registered");
    389         new OptionParser("test").addFlagParameter("test", this::nop)
    390             .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop);
     366        Exception e = assertThrows(IllegalArgumentException.class, () ->
     367                new OptionParser("test").addFlagParameter("test", this::nop)
     368            .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop));
     369        assertEquals("The option '--test' is already registered", e.getMessage());
    391370    }
    392371
    393372    @Test
    394373    public void testInvalidShortAlias() {
    395         thrown.expect(IllegalArgumentException.class);
    396         thrown.expectMessage("Short name '$' must be one character");
    397         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$");
     374        Exception e = assertThrows(IllegalArgumentException.class, () ->
     375                new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$"));
     376        assertEquals("Short name '$' must be one character", e.getMessage());
    398377    }
    399378
    400379    @Test
    401380    public void testInvalidShortAlias2() {
    402         thrown.expect(IllegalArgumentException.class);
    403         thrown.expectMessage("Short name '' must be one character");
    404         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "");
     381        Exception e = assertThrows(IllegalArgumentException.class, () ->
     382                new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", ""));
     383        assertEquals("Short name '' must be one character", e.getMessage());
    405384    }
    406385
    407386    @Test
    408387    public void testInvalidShortAlias3() {
    409         thrown.expect(IllegalArgumentException.class);
    410         thrown.expectMessage("Short name 'xx' must be one character");
    411         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx");
     388        Exception e = assertThrows(IllegalArgumentException.class, () ->
     389                new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx"));
     390        assertEquals("Short name 'xx' must be one character", e.getMessage());
    412391    }
    413392
    414393    @Test
    415394    public void testDuplicateShortAlias() {
    416         thrown.expect(IllegalArgumentException.class);
    417         thrown.expectMessage("Short name 't' is already used");
    418         new OptionParser("test").addFlagParameter("test", this::nop)
     395        Exception e = assertThrows(IllegalArgumentException.class, () ->
     396                new OptionParser("test").addFlagParameter("test", this::nop)
    419397        .addFlagParameter("test2", this::nop)
    420398        .addShortAlias("test", "t")
    421         .addShortAlias("test2", "t");
     399        .addShortAlias("test2", "t"));
     400        assertEquals("Short name 't' is already used", e.getMessage());
    422401    }
    423402
    424403    @Test
    425404    public void testInvalidShortNoLong() {
    426         thrown.expect(IllegalArgumentException.class);
    427         thrown.expectMessage("No long definition for test2 was defined. " +
    428                 "Define the long definition first before creating a short definition for it.");
    429         new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t");
     405        Exception e = assertThrows(IllegalArgumentException.class, () ->
     406                new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t"));
     407        assertEquals("No long definition for test2 was defined. " +
     408                "Define the long definition first before creating a short definition for it.", e.getMessage());
    430409    }
    431410
  • trunk/test/unit/org/openstreetmap/josm/tools/StringParserTest.java

    r16181 r16618  
    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
     11import org.junit.Test;
     12
    1113import net.trajano.commons.testing.UtilityClassTestUtil;
    12 import org.junit.Test;
    1314
    1415/**
Note: See TracChangeset for help on using the changeset viewer.