Ticket #16567: 16567.deprecated.4.patch

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

Update for testMultipleShort changes

  • 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/layer/LayerManagerTest.java

     
    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;
    78import static org.junit.Assert.assertNotNull;
     
    910import static org.junit.Assert.assertSame;
    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;
    1417import java.awt.Graphics;
     
    2225import javax.swing.Icon;
    2326
    2427import org.junit.Before;
    25 import org.junit.Rule;
    2628import org.junit.Test;
    2729import org.openstreetmap.josm.data.Bounds;
    2830import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    3234import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    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
    3839/**
     
    162163    protected LayerManager layerManager;
    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     */
    173168    @Before
     
    227222     */
    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
    239234    /**
     
    241236     */
    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
    257252    /**
     
    308303     */
    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
    322317    /**
     
    324319     */
    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
    337332    /**
  • 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/testutils/ExpectedRootException.java

     
    1616 * This class is needed to add {@link #expectRootCause} method, which has been rejected by JUnit developers,
    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
    2224    private final ExpectedException rule = ExpectedException.none();
  • 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;
    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;
    2120
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     22
    2223/**
    2324 * Test for {@link OptionParser}
    2425 * @author Michael Zangl
    2526 */
    2627public class OptionParserTest {
    27 
    2828    /**
    29      * Rule used for tests throwing exceptions.
    30      */
    31     @Rule
    32     public ExpectedException thrown = ExpectedException.none();
    33 
    34     /**
    3529     * Setup test.
    3630     */
    3731    @Rule
     
    4135    // A reason for moving to jupiter...
    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, () -> new OptionParser("test").parseOptions(Arrays.asList("--long")));
     39        assertEquals("test: unrecognized option '--long'", e.getMessage());
    4740    }
    4841
    4942    @Test
    5043    public void testEmptyParserRejectsShortopt() {
    51         thrown.expect(OptionParseException.class);
    52         thrown.expectMessage("test: unrecognized option '-s'");
    53         new OptionParser("test").parseOptions(Arrays.asList("-s"));
     44        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").parseOptions(Arrays.asList("-s")));
     45        assertEquals("test: unrecognized option '-s'", e.getMessage());
    5446    }
    5547
    5648    @Test
    5749    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"));
     50        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "t")
     51                .parseOptions(Arrays.asList("-s")));
     52        assertEquals("test: unrecognized option '-s'", e.getMessage());
    6253    }
    6354
    6455    @Test
    6556    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"));
     57        Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).parseOptions(Arrays.asList("--wrong")));
     58        assertEquals("test: unrecognized option '--wrong'", e.getMessage());
    6959    }
    7060
    7161    @Test
     
    8070
    8171    @Test
    8272    public void testParserOptionFailsIfMissing() {
    83         thrown.expect(OptionParseException.class);
    84         thrown.expectMessage("test: unrecognized option '--test2'");
    8573        AtomicReference<String> argFound = new AtomicReference<>();
    8674        OptionParser parser = new OptionParser("test")
    8775                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    8876
    89         parser.parseOptions(Arrays.asList("--test2", "arg"));
     77        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "arg")));
     78        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    9079    }
    9180
    9281    @Test
    9382    public void testParserOptionFailsIfMissingArgument() {
    94         thrown.expect(OptionParseException.class);
    95         thrown.expectMessage("test: unrecognized option '--test2'");
    9683        AtomicReference<String> argFound = new AtomicReference<>();
    9784        OptionParser parser = new OptionParser("test")
    9885                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    9986
    100         parser.parseOptions(Arrays.asList("--test2", "--other"));
     87        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "--other")));
     88        assertEquals("test: unrecognized option '--test2'", e.getMessage());
    10189    }
    10290
    10391    @Test
    10492    public void testParserOptionFailsIfMissing2() {
    105         thrown.expect(OptionParseException.class);
    106         thrown.expectMessage("test: option '--test' is required");
    10793        AtomicReference<String> argFound = new AtomicReference<>();
    10894        OptionParser parser = new OptionParser("test")
    10995                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    11096
    111         parser.parseOptions(Arrays.asList("--", "--test", "arg"));
     97        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--", "--test", "arg")));
     98        assertEquals("test: option '--test' is required", e.getMessage());
    11299    }
    113100
    114101    @Test
    115102    public void testParserOptionFailsIfTwice() {
    116         thrown.expect(OptionParseException.class);
    117         thrown.expectMessage("test: option '--test' may not appear multiple times");
    118103        AtomicReference<String> argFound = new AtomicReference<>();
    119104        OptionParser parser = new OptionParser("test")
    120105                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set);
    121106
    122         parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg"));
     107        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg")));
     108        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    123109    }
    124110
    125111    @Test
    126112    public void testParserOptionFailsIfTwiceForAlias() {
    127         thrown.expect(OptionParseException.class);
    128         thrown.expectMessage("test: option '-t' may not appear multiple times");
    129113        AtomicReference<String> argFound = new AtomicReference<>();
    130114        OptionParser parser = new OptionParser("test")
    131115                .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set)
    132116                .addShortAlias("test", "t");
    133117
    134         parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg"));
     118        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg")));
     119        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    135120    }
    136121
    137122    @Test
    138123    public void testOptionalOptionFailsIfTwice() {
    139         thrown.expect(OptionParseException.class);
    140         thrown.expectMessage("test: option '--test' may not appear multiple times");
    141124        OptionParser parser = new OptionParser("test")
    142125                .addFlagParameter("test", this::nop);
    143         parser.parseOptions(Arrays.asList("--test", "--test"));
     126        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--test")));
     127        assertEquals("test: option '--test' may not appear multiple times", e.getMessage());
    144128    }
    145129
    146130    @Test
    147131    public void testOptionalOptionFailsIfTwiceForAlias() {
    148         thrown.expect(OptionParseException.class);
    149         thrown.expectMessage("test: option '-t' may not appear multiple times");
    150132        OptionParser parser = new OptionParser("test")
    151133                .addFlagParameter("test", this::nop)
    152134                .addShortAlias("test", "t");
    153         parser.parseOptions(Arrays.asList("-t", "-t"));
     135        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "-t")));
     136        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    154137    }
    155138
    156139    @Test
    157140    public void testOptionalOptionFailsIfTwiceForAlias2() {
    158         thrown.expect(OptionParseException.class);
    159         thrown.expectMessage("test: option '-t' may not appear multiple times");
    160141        OptionParser parser = new OptionParser("test")
    161142                .addFlagParameter("test", this::nop)
    162143                .addShortAlias("test", "t");
    163         parser.parseOptions(Arrays.asList("-tt"));
     144        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-tt")));
     145        assertEquals("test: option '-t' may not appear multiple times", e.getMessage());
    164146    }
    165147
    166148    @Test
     
    187169
    188170    @Test
    189171    public void testLongArgumentsMissingOption() {
    190         thrown.expect(OptionParseException.class);
    191         thrown.expectMessage("test: option '--test' requires an argument");
    192172        OptionParser parser = new OptionParser("test")
    193173                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    194174
    195         parser.parseOptions(Arrays.asList("--test"));
     175        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test")));
     176        assertEquals("test: option '--test' requires an argument", e.getMessage());
    196177    }
    197178
    198179    @Test
    199180    public void testLongArgumentsMissingOption2() {
    200         thrown.expect(OptionParseException.class);
    201         thrown.expectMessage("test: option '--test' requires an argument");
    202181        OptionParser parser = new OptionParser("test")
    203182                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop);
    204183
    205         parser.parseOptions(Arrays.asList("--test", "--", "x"));
     184        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--", "x")));
     185        assertEquals("test: option '--test' requires an argument", e.getMessage());
    206186    }
    207187
    208188    @Test
    209189    public void testShortArgumentsMissingOption() {
    210         thrown.expect(OptionParseException.class);
    211         thrown.expectMessage("test: option '-t' requires an argument");
    212190        OptionParser parser = new OptionParser("test")
    213191                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    214192                .addShortAlias("test", "t");
    215193
    216         parser.parseOptions(Arrays.asList("-t"));
     194        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t")));
     195        assertEquals("test: option '-t' requires an argument", e.getMessage());
    217196    }
    218197
    219198    @Test
    220199    public void testShortArgumentsMissingOption2() {
    221         thrown.expect(OptionParseException.class);
    222         thrown.expectMessage("test: option '-t' requires an argument");
    223200        OptionParser parser = new OptionParser("test")
    224201                .addArgumentParameter("test", OptionCount.REQUIRED, this::nop)
    225202                .addShortAlias("test", "t");
    226203
    227         parser.parseOptions(Arrays.asList("-t", "--", "x"));
     204        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "--", "x")));
     205        assertEquals("test: option '-t' requires an argument", e.getMessage());
    228206    }
    229207
    230208    @Test
    231209    public void testLongFlagHasOption() {
    232         thrown.expect(OptionParseException.class);
    233         thrown.expectMessage("test: option '--test' does not allow an argument");
    234210        OptionParser parser = new OptionParser("test")
    235211                .addFlagParameter("test", this::nop);
    236212
    237         parser.parseOptions(Arrays.asList("--test=arg"));
     213        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test=arg")));
     214        assertEquals("test: option '--test' does not allow an argument", e.getMessage());
    238215    }
    239216
    240217    @Test
    241218    public void testShortFlagHasOption() {
    242         thrown.expect(OptionParseException.class);
    243         thrown.expectMessage("test: option '-t' does not allow an argument");
    244219        OptionParser parser = new OptionParser("test")
    245220                .addFlagParameter("test", this::nop)
    246221                .addShortAlias("test", "t");
    247222
    248         parser.parseOptions(Arrays.asList("-t=arg"));
     223        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t=arg")));
     224        assertEquals("test: option '-t' does not allow an argument", e.getMessage());
    249225    }
    250226
    251227    @Test
     
    305281
    306282    @Test
    307283    public void testAmbiguousAlternatives() {
    308         thrown.expect(OptionParseException.class);
    309         thrown.expectMessage("test: option '--fl' is ambiguous");
    310284        AtomicReference<String> argFound = new AtomicReference<>();
    311285        AtomicBoolean usedFlag = new AtomicBoolean();
    312286        AtomicBoolean unusedFlag = new AtomicBoolean();
     
    316290                .addFlagParameter("flag", () -> usedFlag.set(true))
    317291                .addFlagParameter("fleg", () -> unusedFlag.set(true));
    318292
    319         parser.parseOptions(Arrays.asList("--te=arg", "--fl"));
     293        Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--te=arg", "--fl")));
     294        assertEquals("test: option '--fl' is ambiguous", e.getMessage());
    320295    }
    321296
    322297    @Test
     
    349324
    350325    @Test
    351326    public void testIllegalOptionName() {
    352         thrown.expect(IllegalArgumentException.class);
    353         thrown.expectMessage("Illegal option name: ''");
    354         new OptionParser("test").addFlagParameter("", this::nop);
     327        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("", this::nop));
     328        assertEquals("Illegal option name: ''", e.getMessage());
    355329    }
    356330
    357331    @Test
    358332    public void testIllegalOptionName2() {
    359         thrown.expect(IllegalArgumentException.class);
    360         thrown.expectMessage("Illegal option name: '-'");
    361         new OptionParser("test").addFlagParameter("-", this::nop);
     333        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-", this::nop));
     334        assertEquals("Illegal option name: '-'", e.getMessage());
    362335    }
    363336
    364337    @Test
    365338    public void testIllegalOptionName3() {
    366         thrown.expect(IllegalArgumentException.class);
    367         thrown.expectMessage("Illegal option name: '-test'");
    368         new OptionParser("test").addFlagParameter("-test", this::nop);
     339        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-test", this::nop));
     340        assertEquals("Illegal option name: '-test'", e.getMessage());
    369341    }
    370342
    371343    @Test
    372344    public void testIllegalOptionName4() {
    373         thrown.expect(IllegalArgumentException.class);
    374         thrown.expectMessage("Illegal option name: '$'");
    375         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());
    376347    }
    377348
    378349    @Test
    379350    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);
     351        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop));
     352        assertEquals("The option '--test' is already registered", e.getMessage());
    383353    }
    384354
    385355    @Test
    386356    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);
     357        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop)
     358            .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop));
     359        assertEquals("The option '--test' is already registered", e.getMessage());
    391360    }
    392361
    393362    @Test
    394363    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", "$");
     364        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$"));
     365        assertEquals("Short name '$' must be one character", e.getMessage());
    398366    }
    399367
    400368    @Test
    401369    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", "");
     370        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", ""));
     371        assertEquals("Short name '' must be one character", e.getMessage());
    405372    }
    406373
    407374    @Test
    408375    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");
     376        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx"));
     377        assertEquals("Short name 'xx' must be one character", e.getMessage());
    412378    }
    413379
    414380    @Test
    415381    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)
     382        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop)
    419383        .addFlagParameter("test2", this::nop)
    420384        .addShortAlias("test", "t")
    421         .addShortAlias("test2", "t");
     385        .addShortAlias("test2", "t"));
     386        assertEquals("Short name 't' is already used", e.getMessage());
    422387    }
    423388
    424389    @Test
    425390    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");
     391        Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t"));
     392        assertEquals("No long definition for test2 was defined. " +
     393                "Define the long definition first before creating a short definition for it.", e.getMessage());
    430394    }
    431395
    432396    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 */