Ticket #16567: 16567.deprecated.4.patch
| File 16567.deprecated.4.patch, 56.9 KB (added by , 6 years ago) |
|---|
-
test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
5 5 import static org.junit.Assert.assertFalse; 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; 10 12 import java.nio.charset.StandardCharsets; … … 18 20 import org.junit.Assert; 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; 24 25 import org.openstreetmap.josm.data.osm.DataSet; … … 60 61 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 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(); 71 66 final Node n1 = new Node(LatLon.ZERO); … … 426 421 */ 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 434 428 /** … … 552 546 */ 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 558 552 /** -
test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
4 4 import static org.CustomMatchers.hasSize; 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 12 12 import java.util.Arrays; -
test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java
3 3 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; 9 9 import java.io.IOException; -
test/unit/org/openstreetmap/josm/data/validation/tests/UntaggedNodeTest.java
3 3 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; 9 9 -
test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
1 1 // License: GPL. For details, see LICENSE file. 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; 8 8 import java.awt.Rectangle; -
test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java
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; 7 8 import static org.junit.Assert.assertNotNull; … … 9 10 import static org.junit.Assert.assertSame; 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; 14 17 import java.awt.Graphics; … … 22 25 import javax.swing.Icon; 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; 28 30 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 32 34 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 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 38 39 /** … … 162 163 protected LayerManager layerManager; 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 */ 173 168 @Before … … 227 222 */ 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 239 234 /** … … 241 236 */ 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 257 252 /** … … 308 303 */ 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 322 317 /** … … 324 319 */ 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 337 332 /** -
test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java
2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 4 import static org.CustomMatchers.isFP; 5 import static org.hamcrest.MatcherAssert.assertThat; 5 6 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; … … 11 12 import org.hamcrest.CoreMatchers; 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; 17 17 import org.junit.runners.Parameterized; … … 69 69 LatLon aFeldberg = bFeldberg.getMin(); 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( 76 76 bFeldberg.getMin(), new LatLon(aFeldberg150mUp.lat(), aFeldberg200mRight.lon())); … … 163 163 RenderingCLI cli = new RenderingCLI(); 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 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java
2 2 package org.openstreetmap.josm.gui.tagging.presets; 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; 9 9 -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java
1 1 // License: GPL. For details, see LICENSE file. 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; 9 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 16 19 * Unit tests of {@link AddNodeHandler} class. 17 20 */ 18 21 public class AddNodeHandlerTest { 19 20 22 /** 21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 /**27 23 * Setup test. 28 24 */ 29 25 @Rule … … 39 35 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 } -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java
1 1 // License: GPL. For details, see LICENSE file. 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; 9 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 16 19 * Unit tests of {@link AddWayHandler} class. 17 20 */ 18 21 public class AddWayHandlerTest { 19 20 22 /** 21 * Rule used for tests throwing exceptions.22 */23 @Rule24 public ExpectedException thrown = ExpectedException.none();25 26 /**27 23 * Setup test. 28 24 */ 29 25 @Rule … … 39 35 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); 65 57 } … … 67 59 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); 102 89 } -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java
2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 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; 9 11 import java.util.List; … … 10 12 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; 16 17 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 21 22 * Unit tests of {@link ImageryHandler} class. 22 23 */ 23 24 public class ImageryHandlerTest { 24 25 25 /** 26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 /**32 26 * Setup test. 33 27 */ 34 28 @Rule … … 44 38 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 87 75 /** -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 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; 7 9 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; 13 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 21 22 * Unit tests of {@link ImportHandler} class. 22 23 */ 23 24 public class ImportHandlerTest { 24 25 25 /** 26 * Rule used for tests throwing exceptions.27 */28 @Rule29 public ExpectedException thrown = ExpectedException.none();30 31 /**32 26 * Setup test. 33 27 */ 34 28 @Rule … … 58 52 */ 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 66 59 /** … … 69 62 */ 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 77 69 /** … … 80 72 */ 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 88 79 /** … … 93 84 public void testNominalRequest() throws Exception { 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)) { 99 90 MainApplication.getLayerManager().removeLayer(layer); -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java
1 1 // License: GPL. For details, see LICENSE file. 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; 9 12 … … 13 16 * Unit tests of {@link LoadAndZoomHandler} class. 14 17 */ 15 18 public class LoadAndZoomHandlerTest { 16 17 19 /** 18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 /**24 20 * Setup test. 25 21 */ 26 22 @Rule … … 40 36 */ 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 48 43 /** … … 51 46 */ 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 59 53 /** … … 62 56 */ 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 70 63 /** … … 73 66 */ 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 } -
test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java
1 1 // License: GPL. For details, see LICENSE file. 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; 9 12 … … 13 16 * Unit tests of {@link LoadObjectHandler} class. 14 17 */ 15 18 public class LoadObjectHandlerTest { 16 17 19 /** 18 * Rule used for tests throwing exceptions.19 */20 @Rule21 public ExpectedException thrown = ExpectedException.none();22 23 /**24 20 * Setup test. 25 21 */ 26 22 @Rule … … 36 32 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 } -
test/unit/org/openstreetmap/josm/testutils/ExpectedRootException.java
16 16 * This class is needed to add {@link #expectRootCause} method, which has been rejected by JUnit developers, 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 22 24 private final ExpectedException rule = ExpectedException.none(); -
test/unit/org/openstreetmap/josm/tools/GeoUrlToBoundsTest.java
2 2 package org.openstreetmap.josm.tools; 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; 9 9 -
test/unit/org/openstreetmap/josm/tools/OptionParserTest.java
4 4 import static org.junit.Assert.assertEquals; 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; 9 10 import java.util.Arrays; … … 11 12 import java.util.concurrent.atomic.AtomicBoolean; 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; 21 20 21 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 22 22 23 /** 23 24 * Test for {@link OptionParser} 24 25 * @author Michael Zangl 25 26 */ 26 27 public class OptionParserTest { 27 28 28 /** 29 * Rule used for tests throwing exceptions.30 */31 @Rule32 public ExpectedException thrown = ExpectedException.none();33 34 /**35 29 * Setup test. 36 30 */ 37 31 @Rule … … 41 35 // A reason for moving to jupiter... 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, () -> new OptionParser("test").parseOptions(Arrays.asList("--long"))); 39 assertEquals("test: unrecognized option '--long'", e.getMessage()); 47 40 } 48 41 49 42 @Test 50 43 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()); 54 46 } 55 47 56 48 @Test 57 49 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()); 62 53 } 63 54 64 55 @Test 65 56 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()); 69 59 } 70 60 71 61 @Test … … 80 70 81 71 @Test 82 72 public void testParserOptionFailsIfMissing() { 83 thrown.expect(OptionParseException.class);84 thrown.expectMessage("test: unrecognized option '--test2'");85 73 AtomicReference<String> argFound = new AtomicReference<>(); 86 74 OptionParser parser = new OptionParser("test") 87 75 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 88 76 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()); 90 79 } 91 80 92 81 @Test 93 82 public void testParserOptionFailsIfMissingArgument() { 94 thrown.expect(OptionParseException.class);95 thrown.expectMessage("test: unrecognized option '--test2'");96 83 AtomicReference<String> argFound = new AtomicReference<>(); 97 84 OptionParser parser = new OptionParser("test") 98 85 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 99 86 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()); 101 89 } 102 90 103 91 @Test 104 92 public void testParserOptionFailsIfMissing2() { 105 thrown.expect(OptionParseException.class);106 thrown.expectMessage("test: option '--test' is required");107 93 AtomicReference<String> argFound = new AtomicReference<>(); 108 94 OptionParser parser = new OptionParser("test") 109 95 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 110 96 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()); 112 99 } 113 100 114 101 @Test 115 102 public void testParserOptionFailsIfTwice() { 116 thrown.expect(OptionParseException.class);117 thrown.expectMessage("test: option '--test' may not appear multiple times");118 103 AtomicReference<String> argFound = new AtomicReference<>(); 119 104 OptionParser parser = new OptionParser("test") 120 105 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 121 106 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()); 123 109 } 124 110 125 111 @Test 126 112 public void testParserOptionFailsIfTwiceForAlias() { 127 thrown.expect(OptionParseException.class);128 thrown.expectMessage("test: option '-t' may not appear multiple times");129 113 AtomicReference<String> argFound = new AtomicReference<>(); 130 114 OptionParser parser = new OptionParser("test") 131 115 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set) 132 116 .addShortAlias("test", "t"); 133 117 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()); 135 120 } 136 121 137 122 @Test 138 123 public void testOptionalOptionFailsIfTwice() { 139 thrown.expect(OptionParseException.class);140 thrown.expectMessage("test: option '--test' may not appear multiple times");141 124 OptionParser parser = new OptionParser("test") 142 125 .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()); 144 128 } 145 129 146 130 @Test 147 131 public void testOptionalOptionFailsIfTwiceForAlias() { 148 thrown.expect(OptionParseException.class);149 thrown.expectMessage("test: option '-t' may not appear multiple times");150 132 OptionParser parser = new OptionParser("test") 151 133 .addFlagParameter("test", this::nop) 152 134 .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()); 154 137 } 155 138 156 139 @Test 157 140 public void testOptionalOptionFailsIfTwiceForAlias2() { 158 thrown.expect(OptionParseException.class);159 thrown.expectMessage("test: option '-t' may not appear multiple times");160 141 OptionParser parser = new OptionParser("test") 161 142 .addFlagParameter("test", this::nop) 162 143 .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()); 164 146 } 165 147 166 148 @Test … … 187 169 188 170 @Test 189 171 public void testLongArgumentsMissingOption() { 190 thrown.expect(OptionParseException.class);191 thrown.expectMessage("test: option '--test' requires an argument");192 172 OptionParser parser = new OptionParser("test") 193 173 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 194 174 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()); 196 177 } 197 178 198 179 @Test 199 180 public void testLongArgumentsMissingOption2() { 200 thrown.expect(OptionParseException.class);201 thrown.expectMessage("test: option '--test' requires an argument");202 181 OptionParser parser = new OptionParser("test") 203 182 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 204 183 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()); 206 186 } 207 187 208 188 @Test 209 189 public void testShortArgumentsMissingOption() { 210 thrown.expect(OptionParseException.class);211 thrown.expectMessage("test: option '-t' requires an argument");212 190 OptionParser parser = new OptionParser("test") 213 191 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 214 192 .addShortAlias("test", "t"); 215 193 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()); 217 196 } 218 197 219 198 @Test 220 199 public void testShortArgumentsMissingOption2() { 221 thrown.expect(OptionParseException.class);222 thrown.expectMessage("test: option '-t' requires an argument");223 200 OptionParser parser = new OptionParser("test") 224 201 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 225 202 .addShortAlias("test", "t"); 226 203 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()); 228 206 } 229 207 230 208 @Test 231 209 public void testLongFlagHasOption() { 232 thrown.expect(OptionParseException.class);233 thrown.expectMessage("test: option '--test' does not allow an argument");234 210 OptionParser parser = new OptionParser("test") 235 211 .addFlagParameter("test", this::nop); 236 212 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()); 238 215 } 239 216 240 217 @Test 241 218 public void testShortFlagHasOption() { 242 thrown.expect(OptionParseException.class);243 thrown.expectMessage("test: option '-t' does not allow an argument");244 219 OptionParser parser = new OptionParser("test") 245 220 .addFlagParameter("test", this::nop) 246 221 .addShortAlias("test", "t"); 247 222 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()); 249 225 } 250 226 251 227 @Test … … 305 281 306 282 @Test 307 283 public void testAmbiguousAlternatives() { 308 thrown.expect(OptionParseException.class);309 thrown.expectMessage("test: option '--fl' is ambiguous");310 284 AtomicReference<String> argFound = new AtomicReference<>(); 311 285 AtomicBoolean usedFlag = new AtomicBoolean(); 312 286 AtomicBoolean unusedFlag = new AtomicBoolean(); … … 316 290 .addFlagParameter("flag", () -> usedFlag.set(true)) 317 291 .addFlagParameter("fleg", () -> unusedFlag.set(true)); 318 292 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()); 320 295 } 321 296 322 297 @Test … … 349 324 350 325 @Test 351 326 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()); 355 329 } 356 330 357 331 @Test 358 332 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()); 362 335 } 363 336 364 337 @Test 365 338 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()); 369 341 } 370 342 371 343 @Test 372 344 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()); 376 347 } 377 348 378 349 @Test 379 350 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()); 383 353 } 384 354 385 355 @Test 386 356 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()); 391 360 } 392 361 393 362 @Test 394 363 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()); 398 366 } 399 367 400 368 @Test 401 369 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()); 405 372 } 406 373 407 374 @Test 408 375 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()); 412 378 } 413 379 414 380 @Test 415 381 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) 419 383 .addFlagParameter("test2", this::nop) 420 384 .addShortAlias("test", "t") 421 .addShortAlias("test2", "t"); 385 .addShortAlias("test2", "t")); 386 assertEquals("Short name 't' is already used", e.getMessage()); 422 387 } 423 388 424 389 @Test 425 390 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()); 430 394 } 431 395 432 396 private void nop() { -
test/unit/org/openstreetmap/josm/tools/StringParserTest.java
2 2 package org.openstreetmap.josm.tools; 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 net.trajano.commons.testing.UtilityClassTestUtil;12 11 import org.junit.Test; 13 12 13 import net.trajano.commons.testing.UtilityClassTestUtil; 14 14 15 /** 15 16 * Unit tests of {@link StringParser} class. 16 17 */
