Changeset 16618 in josm for trunk/test
- Timestamp:
- 2020-06-14T11:54:13+02:00 (4 years ago)
- 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 6 6 import static org.junit.Assert.assertNotNull; 7 7 import static org.junit.Assert.assertTrue; 8 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 9 import static org.junit.jupiter.api.Assertions.assertThrows; 8 10 9 11 import java.lang.reflect.Field; … … 19 21 import org.junit.Rule; 20 22 import org.junit.Test; 21 import org.junit.rules.ExpectedException;22 23 import org.openstreetmap.josm.TestUtils; 23 24 import org.openstreetmap.josm.data.coor.LatLon; … … 61 62 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000); 62 63 63 /**64 * Rule to assert exception message.65 */66 @Rule67 public ExpectedException expectedEx = ExpectedException.none();68 69 64 private static final class SearchContext { 70 65 final DataSet ds = new DataSet(); … … 427 422 @Test 428 423 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()); 432 426 } 433 427 … … 553 547 @Test 554 548 public void testEnumExactKeyValueMode() { 555 TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class);549 assertDoesNotThrow(() -> TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class)); 556 550 } 557 551 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
r16178 r16618 5 5 import static org.CustomMatchers.isEmpty; 6 6 import static org.hamcrest.CoreMatchers.not; 7 import static org.hamcrest.MatcherAssert.assertThat; 7 8 import static org.junit.Assert.assertEquals; 8 9 import static org.junit.Assert.assertNotNull; 9 import static org.junit.Assert.assertThat;10 10 import static org.junit.Assert.assertTrue; 11 11 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java
r16006 r16618 4 4 import static org.CustomMatchers.hasSize; 5 5 import static org.CustomMatchers.isEmpty; 6 import static org. junit.Assert.assertThat;6 import static org.hamcrest.MatcherAssert.assertThat; 7 7 8 8 import java.io.FileNotFoundException; -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/UntaggedNodeTest.java
r10945 r16618 4 4 import static org.CustomMatchers.hasSize; 5 5 import static org.CustomMatchers.isEmpty; 6 import static org. junit.Assert.assertThat;6 import static org.hamcrest.MatcherAssert.assertThat; 7 7 8 8 import java.io.InputStream; -
trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
r14138 r16618 2 2 package org.openstreetmap.josm.gui; 3 3 4 import static org.hamcrest.MatcherAssert.assertThat; 4 5 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertThat;6 6 7 7 import java.awt.Point; -
trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java
r11905 r16618 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.layer; 3 4 import static org.hamcrest.CoreMatchers.any; 3 import static org.hamcrest.CoreMatchers.instanceOf; 4 import static org.hamcrest.CoreMatchers.is; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.junit.Assert.assertEquals; 6 7 import static org.junit.Assert.assertFalse; … … 10 11 import static org.junit.Assert.assertTrue; 11 12 import static org.junit.Assert.fail; 13 import static org.junit.jupiter.api.Assertions.assertThrows; 14 import static org.openstreetmap.josm.testutils.ThrowableRootCauseMatcher.hasRootCause; 12 15 13 16 import java.awt.Component; … … 23 26 24 27 import org.junit.Before; 25 import org.junit.Rule;26 28 import org.junit.Test; 27 29 import org.openstreetmap.josm.data.Bounds; … … 33 35 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 34 36 import org.openstreetmap.josm.gui.util.GuiHelper; 35 import org.openstreetmap.josm.testutils.ExpectedRootException;36 37 import org.openstreetmap.josm.tools.bugreport.ReportedException; 37 38 … … 163 164 164 165 /** 165 * Rule used to expect exceptions.166 */167 @Rule168 public ExpectedRootException thrown = ExpectedRootException.none();169 170 /**171 166 * Set up test layer manager. 172 167 */ … … 228 223 @Test 229 224 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)))); 237 232 } 238 233 … … 242 237 @Test 243 238 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 @Override250 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)))); 255 250 } 256 251 … … 309 304 @Test 310 305 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)))); 320 315 } 321 316 … … 325 320 @Test 326 321 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)))); 335 330 } 336 331 -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java
r12907 r16618 3 3 4 4 import static org.CustomMatchers.isFP; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 6 7 import java.util.ArrayList; … … 12 13 import org.hamcrest.Matcher; 13 14 import org.junit.Rule; 14 import org.junit.Assert;15 15 import org.junit.Test; 16 16 import org.junit.runner.RunWith; … … 70 70 LatLon aFeldberg200mRight = new LatLon(aFeldberg.lat(), 13.433008399004041); 71 71 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)); 74 74 75 75 Bounds bFeldberg200x150m = new Bounds( … … 164 164 cli.parseArguments(args); 165 165 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); 168 168 } 169 169 } -
trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java
r16560 r16618 3 3 4 4 import static org.CustomMatchers.hasSize; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertThat;7 7 import static org.junit.Assert.assertTrue; 8 8 import static org.junit.Assert.fail; -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java
r14217 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.data.osm.DataSet; 8 11 import org.openstreetmap.josm.gui.MainApplication; … … 17 20 */ 18 21 public class AddNodeHandlerTest { 19 20 /**21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 22 /** 27 23 * Setup test. … … 40 36 /** 41 37 * Unit test for bad request - no layer. 42 * @throws Exception if any error occurs43 38 */ 44 39 @Test 45 public void testBadRequestNoLayer() throws Exception { 46 thrown.expect(RequestHandlerBadRequestException.class); 47 thrown.expectMessage("There is no layer opened to add node"); 48 newHandler("https://localhost?lat=0&lon=0").handle(); 40 public void testBadRequestNoLayer() { 41 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?lat=0&lon=0").handle()); 42 assertEquals("There is no layer opened to add node", e.getMessage()); 49 43 } 50 44 51 45 /** 52 46 * Unit test for bad request - no param. 53 * @throws Exception if any error occurs54 47 */ 55 48 @Test 56 public void testBadRequestNoParam() throws Exception { 57 thrown.expect(RequestHandlerBadRequestException.class); 58 thrown.expectMessage("NumberFormatException (empty String)"); 49 public void testBadRequestNoParam() { 59 50 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 60 51 MainApplication.getLayerManager().addLayer(layer); 61 newHandler(null).handle(); 52 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 53 assertEquals("NumberFormatException (empty String)", e.getMessage()); 62 54 } 63 55 64 56 /** 65 57 * Unit test for bad request - invalid URL. 66 * @throws Exception if any error occurs67 58 */ 68 59 @Test 69 public void testBadRequestInvalidUrl() throws Exception { 70 thrown.expect(RequestHandlerBadRequestException.class); 71 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon"); 72 newHandler("invalid_url").handle(); 60 public void testBadRequestInvalidUrl() { 61 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 62 assertEquals("The following keys are mandatory, but have not been provided: lat, lon", e.getMessage()); 73 63 } 74 64 75 65 /** 76 66 * Unit test for bad request - incomplete URL. 77 * @throws Exception if any error occurs78 67 */ 79 68 @Test 80 public void testBadRequestIncompleteUrl() throws Exception { 81 thrown.expect(RequestHandlerBadRequestException.class); 82 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon"); 83 newHandler("https://localhost").handle(); 69 public void testBadRequestIncompleteUrl() { 70 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 71 assertEquals("The following keys are mandatory, but have not been provided: lat, lon", e.getMessage()); 84 72 } 85 73 86 74 /** 87 75 * Unit test for nominal request - local data file. 88 * @throws Exception if any error occurs89 76 */ 90 77 @Test 91 public void testNominalRequest() throws Exception{78 public void testNominalRequest() { 92 79 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 93 80 MainApplication.getLayerManager().addLayer(layer); 94 newHandler("https://localhost?lat=0&lon=0").handle();81 assertDoesNotThrow(() -> newHandler("https://localhost?lat=0&lon=0").handle()); 95 82 } 96 83 } -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java
r12636 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.data.osm.DataSet; 8 11 import org.openstreetmap.josm.gui.MainApplication; … … 17 20 */ 18 21 public class AddWayHandlerTest { 19 20 /**21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 22 /** 27 23 * Setup test. … … 40 36 /** 41 37 * Unit test for bad request - no layer. 42 * @throws Exception if any error occurs43 38 */ 44 39 @Test 45 public void testBadRequestNoLayer() throws Exception { 46 thrown.expect(RequestHandlerBadRequestException.class); 47 thrown.expectMessage("There is no layer opened to add way"); 48 newHandler("https://localhost?way=0,0;1,1").handle(); 40 public void testBadRequestNoLayer() { 41 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?way=0,0;1,1").handle()); 42 assertEquals("There is no layer opened to add way", e.getMessage()); 49 43 } 50 44 51 45 /** 52 46 * Unit test for bad request - no param. 53 * @throws Exception if any error occurs54 47 */ 55 48 @Test 56 public void testBadRequestNoParam() throws Exception { 57 thrown.expect(RequestHandlerBadRequestException.class); 58 thrown.expectMessage("Invalid coordinates: []"); 49 public void testBadRequestNoParam() { 59 50 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 60 51 try { 61 52 MainApplication.getLayerManager().addLayer(layer); 62 newHandler(null).handle(); 53 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 54 assertEquals("Invalid coordinates: []", e.getMessage()); 63 55 } finally { 64 56 MainApplication.getLayerManager().removeLayer(layer); … … 68 60 /** 69 61 * Unit test for bad request - invalid URL. 70 * @throws Exception if any error occurs71 62 */ 72 63 @Test 73 public void testBadRequestInvalidUrl() throws Exception { 74 thrown.expect(RequestHandlerBadRequestException.class); 75 thrown.expectMessage("The following keys are mandatory, but have not been provided: way"); 76 newHandler("invalid_url").handle(); 64 public void testBadRequestInvalidUrl() { 65 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 66 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage()); 77 67 } 78 68 79 69 /** 80 70 * Unit test for bad request - incomplete URL. 81 * @throws Exception if any error occurs82 71 */ 83 72 @Test 84 public void testBadRequestIncompleteUrl() throws Exception { 85 thrown.expect(RequestHandlerBadRequestException.class); 86 thrown.expectMessage("The following keys are mandatory, but have not been provided: way"); 87 newHandler("https://localhost").handle(); 73 public void testBadRequestIncompleteUrl() { 74 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 75 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage()); 88 76 } 89 77 90 78 /** 91 79 * Unit test for nominal request - local data file. 92 * @throws Exception if any error occurs93 80 */ 94 81 @Test 95 public void testNominalRequest() throws Exception{82 public void testNominalRequest() { 96 83 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 97 84 try { 98 85 MainApplication.getLayerManager().addLayer(layer); 99 newHandler("https://localhost?way=0,0;1,1").handle();86 assertDoesNotThrow(() -> newHandler("https://localhost?way=0,0;1,1").handle()); 100 87 } finally { 101 88 MainApplication.getLayerManager().removeLayer(layer); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java
r16589 r16618 3 3 4 4 import static org.hamcrest.CoreMatchers.hasItem; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertThat; 7 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 8 import static org.junit.jupiter.api.Assertions.assertThrows; 7 9 8 10 import java.util.Arrays; … … 11 13 import org.junit.Rule; 12 14 import org.junit.Test; 13 import org.junit.rules.ExpectedException;14 15 import org.openstreetmap.josm.data.imagery.ImageryInfo; 15 16 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; … … 22 23 */ 23 24 public class ImageryHandlerTest { 24 25 /**26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 25 /** 32 26 * Setup test. … … 45 39 /** 46 40 * Unit test for bad request - no param. 47 * @throws Exception if any error occurs48 41 */ 49 42 @Test 50 public void testBadRequestNoParam() throws Exception{51 thrown.expect(RequestHandlerBadRequestException.class);52 thrown.expectMessage("Parameter must not be null");53 newHandler(null).handle(); 43 public void testBadRequestNoParam() { 44 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 45 assertEquals("Parameter must not be null", e.getMessage()); 46 54 47 } 55 48 56 49 /** 57 50 * Unit test for bad request - invalid URL. 58 * @throws Exception if any error occurs59 51 */ 60 52 @Test 61 public void testBadRequestInvalidUrl() throws Exception { 62 thrown.expect(RequestHandlerBadRequestException.class); 63 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 64 newHandler("invalid_url").handle(); 53 public void testBadRequestInvalidUrl() { 54 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 55 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 65 56 } 66 57 67 58 /** 68 59 * Unit test for bad request - incomplete URL. 69 * @throws Exception if any error occurs70 60 */ 71 61 @Test 72 public void testBadRequestIncompleteUrl() throws Exception { 73 thrown.expect(RequestHandlerBadRequestException.class); 74 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 75 newHandler("https://localhost").handle(); 62 public void testBadRequestIncompleteUrl() { 63 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 64 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 76 65 } 77 66 78 67 /** 79 68 * Unit test for nominal request - local data file. 80 * @throws Exception if any error occurs81 69 */ 82 70 @Test 83 public void testNominalRequest() throws Exception{84 newHandler("https://localhost?url=foo").handle();71 public void testNominalRequest() { 72 assertDoesNotThrow(() -> newHandler("https://localhost?url=foo").handle()); 85 73 } 86 74 -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
r12636 r16618 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 5 7 6 8 import java.io.File; … … 8 10 import org.junit.Rule; 9 11 import org.junit.Test; 10 import org.junit.rules.ExpectedException;11 12 import org.openstreetmap.josm.TestUtils; 12 13 import org.openstreetmap.josm.gui.MainApplication; … … 22 23 */ 23 24 public class ImportHandlerTest { 24 25 /**26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 25 /** 32 26 * Setup test. … … 59 53 @Test 60 54 public void testBadRequestNoParam() throws Exception { 61 thrown.expect(RequestHandlerBadRequestException.class); 62 thrown.expectMessage("MalformedURLException: null"); 63 newHandler(null).handle(); 55 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 56 assertEquals("MalformedURLException: null", e.getMessage()); 64 57 } 65 58 … … 70 63 @Test 71 64 public void testBadRequestInvalidUrl() throws Exception { 72 thrown.expect(RequestHandlerBadRequestException.class); 73 thrown.expectMessage("MalformedURLException: no protocol: invalid_url"); 74 newHandler("https://localhost?url=invalid_url").handle(); 65 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?url=invalid_url").handle()); 66 assertEquals("MalformedURLException: no protocol: invalid_url", e.getMessage()); 75 67 } 76 68 … … 81 73 @Test 82 74 public void testBadRequestIncompleteUrl() throws Exception { 83 thrown.expect(RequestHandlerBadRequestException.class); 84 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 85 newHandler("https://localhost").handle(); 75 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 76 assertEquals("The following keys are mandatory, but have not been provided: url", e.getMessage()); 86 77 } 87 78 … … 94 85 String url = new File(TestUtils.getRegressionDataFile(11957, "data.osm")).toURI().toURL().toExternalForm(); 95 86 try { 96 newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle();87 assertDoesNotThrow(() -> newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle()); 97 88 } finally { 98 89 for (OsmDataLayer layer : MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)) { -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java
r12558 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 8 11 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 14 17 */ 15 18 public class LoadAndZoomHandlerTest { 16 17 /**18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 19 /** 24 20 * Setup test. … … 41 37 @Test 42 38 public void testBadRequestNoParam() throws Exception { 43 thrown.expect(RequestHandlerBadRequestException.class); 44 thrown.expectMessage("NumberFormatException (empty String)"); 45 newHandler(null).handle(); 39 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle()); 40 assertEquals("NumberFormatException (empty String)", e.getMessage()); 46 41 } 47 42 … … 52 47 @Test 53 48 public void testBadRequestInvalidUrl() throws Exception { 54 thrown.expect(RequestHandlerBadRequestException.class); 55 thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); 56 newHandler("invalid_url").handle(); 49 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 50 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage()); 57 51 } 58 52 … … 63 57 @Test 64 58 public void testBadRequestIncompleteUrl() throws Exception { 65 thrown.expect(RequestHandlerBadRequestException.class); 66 thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right"); 67 newHandler("https://localhost").handle(); 59 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 60 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage()); 68 61 } 69 62 … … 74 67 @Test 75 68 public void testNominalRequest() throws Exception { 76 newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle();69 assertDoesNotThrow(() -> newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle()); 77 70 } 78 71 } -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java
r12558 r16618 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 4 8 import org.junit.Rule; 5 9 import org.junit.Test; 6 import org.junit.rules.ExpectedException;7 10 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 8 11 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 14 17 */ 15 18 public class LoadObjectHandlerTest { 16 17 /**18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 19 /** 24 20 * Setup test. … … 37 33 /** 38 34 * Unit test for bad request - no param. 39 * @throws Exception if any error occurs40 35 */ 41 36 @Test 42 public void testBadRequestNoParam() throws Exception{43 newHandler(null).handle();37 public void testBadRequestNoParam() { 38 assertDoesNotThrow(() -> newHandler(null).handle()); 44 39 } 45 40 46 41 /** 47 42 * Unit test for bad request - invalid URL. 48 * @throws Exception if any error occurs49 43 */ 50 44 @Test 51 public void testBadRequestInvalidUrl() throws Exception { 52 thrown.expect(RequestHandlerBadRequestException.class); 53 thrown.expectMessage("The following keys are mandatory, but have not been provided: objects"); 54 newHandler("invalid_url").handle(); 45 public void testBadRequestInvalidUrl() { 46 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle()); 47 assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage()); 55 48 } 56 49 57 50 /** 58 51 * Unit test for bad request - incomplete URL. 59 * @throws Exception if any error occurs60 52 */ 61 53 @Test 62 public void testBadRequestIncompleteUrl() throws Exception { 63 thrown.expect(RequestHandlerBadRequestException.class); 64 thrown.expectMessage("The following keys are mandatory, but have not been provided: objects"); 65 newHandler("https://localhost").handle(); 54 public void testBadRequestIncompleteUrl() { 55 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle()); 56 assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage()); 66 57 } 67 58 68 59 /** 69 60 * Unit test for nominal request - local data file. 70 * @throws Exception if any error occurs71 61 */ 72 62 @Test 73 public void testNominalRequest() throws Exception{74 newHandler("https://localhost?objects=foo,bar").handle();63 public void testNominalRequest() { 64 assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle()); 75 65 } 76 66 } -
trunk/test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java
r10397 r16618 17 17 * and {@code ExpectedException} cannot be extended because it has a private constructor. 18 18 * @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} 19 20 */ 21 @Deprecated 20 22 public final class ExpectedRootException implements TestRule { 21 23 -
trunk/test/unit/org/openstreetmap/josm/tools/GeoUrlToBoundsTest.java
r15184 r16618 3 3 4 4 import static org.hamcrest.CoreMatchers.nullValue; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.hamcrest.core.Is.is; 6 import static org.junit.Assert.assertThat;7 7 8 8 import org.junit.Test; -
trunk/test/unit/org/openstreetmap/josm/tools/OptionParserTest.java
r16608 r16618 5 5 import static org.junit.Assert.assertFalse; 6 6 import static org.junit.Assert.assertTrue; 7 import static org.junit.jupiter.api.Assertions.assertThrows; 7 8 8 9 import java.util.ArrayList; … … 12 13 import java.util.concurrent.atomic.AtomicReference; 13 14 14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;15 15 import org.junit.Rule; 16 16 import org.junit.Test; 17 import org.junit.rules.ExpectedException;18 17 import org.openstreetmap.josm.testutils.JOSMTestRules; 19 18 import org.openstreetmap.josm.tools.OptionParser.OptionCount; 20 19 import org.openstreetmap.josm.tools.OptionParser.OptionParseException; 20 21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 21 22 22 23 /** … … 25 26 */ 26 27 public class OptionParserTest { 27 28 /**29 * Rule used for tests throwing exceptions.30 */31 @Rule32 public ExpectedException thrown = ExpectedException.none();33 34 28 /** 35 29 * Setup test. … … 42 36 @Test 43 37 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()); 47 41 } 48 42 49 43 @Test 50 44 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()); 54 48 } 55 49 56 50 @Test 57 51 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()); 62 56 } 63 57 64 58 @Test 65 59 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()); 69 63 } 70 64 … … 81 75 @Test 82 76 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()); 90 83 } 91 84 92 85 @Test 93 86 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()); 101 93 } 102 94 103 95 @Test 104 96 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()); 112 103 } 113 104 114 105 @Test 115 106 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()); 123 113 } 124 114 125 115 @Test 126 116 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()); 135 124 } 136 125 137 126 @Test 138 127 public void testOptionalOptionFailsIfTwice() { 139 thrown.expect(OptionParseException.class);140 thrown.expectMessage("test: option '--test' may not appear multiple times");141 128 OptionParser parser = new OptionParser("test") 142 129 .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()); 144 132 } 145 133 146 134 @Test 147 135 public void testOptionalOptionFailsIfTwiceForAlias() { 148 thrown.expect(OptionParseException.class);149 thrown.expectMessage("test: option '-t' may not appear multiple times");150 136 OptionParser parser = new OptionParser("test") 151 137 .addFlagParameter("test", this::nop) 152 138 .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()); 154 141 } 155 142 156 143 @Test 157 144 public void testOptionalOptionFailsIfTwiceForAlias2() { 158 thrown.expect(OptionParseException.class);159 thrown.expectMessage("test: option '-t' may not appear multiple times");160 145 OptionParser parser = new OptionParser("test") 161 146 .addFlagParameter("test", this::nop) 162 147 .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()); 164 150 } 165 151 … … 188 174 @Test 189 175 public void testLongArgumentsMissingOption() { 190 thrown.expect(OptionParseException.class);191 thrown.expectMessage("test: option '--test' requires an argument");192 176 OptionParser parser = new OptionParser("test") 193 177 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 194 178 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()); 196 181 } 197 182 198 183 @Test 199 184 public void testLongArgumentsMissingOption2() { 200 thrown.expect(OptionParseException.class);201 thrown.expectMessage("test: option '--test' requires an argument");202 185 OptionParser parser = new OptionParser("test") 203 186 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 204 187 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()); 206 190 } 207 191 208 192 @Test 209 193 public void testShortArgumentsMissingOption() { 210 thrown.expect(OptionParseException.class);211 thrown.expectMessage("test: option '-t' requires an argument");212 194 OptionParser parser = new OptionParser("test") 213 195 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 214 196 .addShortAlias("test", "t"); 215 197 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()); 217 200 } 218 201 219 202 @Test 220 203 public void testShortArgumentsMissingOption2() { 221 thrown.expect(OptionParseException.class);222 thrown.expectMessage("test: option '-t' requires an argument");223 204 OptionParser parser = new OptionParser("test") 224 205 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 225 206 .addShortAlias("test", "t"); 226 207 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()); 228 210 } 229 211 230 212 @Test 231 213 public void testLongFlagHasOption() { 232 thrown.expect(OptionParseException.class);233 thrown.expectMessage("test: option '--test' does not allow an argument");234 214 OptionParser parser = new OptionParser("test") 235 215 .addFlagParameter("test", this::nop); 236 216 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()); 238 219 } 239 220 240 221 @Test 241 222 public void testShortFlagHasOption() { 242 thrown.expect(OptionParseException.class);243 thrown.expectMessage("test: option '-t' does not allow an argument");244 223 OptionParser parser = new OptionParser("test") 245 224 .addFlagParameter("test", this::nop) 246 225 .addShortAlias("test", "t"); 247 226 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()); 249 229 } 250 230 … … 306 286 @Test 307 287 public void testAmbiguousAlternatives() { 308 thrown.expect(OptionParseException.class);309 thrown.expectMessage("test: option '--fl' is ambiguous");310 288 AtomicReference<String> argFound = new AtomicReference<>(); 311 289 AtomicBoolean usedFlag = new AtomicBoolean(); … … 317 295 .addFlagParameter("fleg", () -> unusedFlag.set(true)); 318 296 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()); 320 299 } 321 300 … … 350 329 @Test 351 330 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()); 355 334 } 356 335 357 336 @Test 358 337 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()); 362 341 } 363 342 364 343 @Test 365 344 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()); 369 348 } 370 349 371 350 @Test 372 351 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()); 376 355 } 377 356 378 357 @Test 379 358 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()); 383 362 } 384 363 385 364 @Test 386 365 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()); 391 370 } 392 371 393 372 @Test 394 373 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()); 398 377 } 399 378 400 379 @Test 401 380 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()); 405 384 } 406 385 407 386 @Test 408 387 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()); 412 391 } 413 392 414 393 @Test 415 394 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) 419 397 .addFlagParameter("test2", this::nop) 420 398 .addShortAlias("test", "t") 421 .addShortAlias("test2", "t"); 399 .addShortAlias("test2", "t")); 400 assertEquals("Short name 't' is already used", e.getMessage()); 422 401 } 423 402 424 403 @Test 425 404 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()); 430 409 } 431 410 -
trunk/test/unit/org/openstreetmap/josm/tools/StringParserTest.java
r16181 r16618 3 3 4 4 import static org.hamcrest.CoreMatchers.is; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertThat;7 7 import static org.junit.Assert.assertTrue; 8 8 9 9 import java.util.Optional; 10 10 11 import org.junit.Test; 12 11 13 import net.trajano.commons.testing.UtilityClassTestUtil; 12 import org.junit.Test;13 14 14 15 /**
Note:
See TracChangeset
for help on using the changeset viewer.