Ticket #16567: 16567.deprecated.1.patch
| File 16567.deprecated.1.patch, 52.1 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/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/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 17 import org.junit.rules.ExpectedException; … … 19 19 import org.openstreetmap.josm.tools.OptionParser.OptionCount; 20 20 import org.openstreetmap.josm.tools.OptionParser.OptionParseException; 21 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 23 22 24 /** 23 25 * Test for {@link OptionParser} 24 26 * @author Michael Zangl 25 27 */ 26 28 public class OptionParserTest { 27 28 /**29 * Rule used for tests throwing exceptions.30 */31 29 @Rule 32 30 public ExpectedException thrown = ExpectedException.none(); 33 34 31 /** 35 32 * Setup test. 36 33 */ … … 41 38 // A reason for moving to jupiter... 42 39 @Test 43 40 public void testEmptyParserRejectsLongopt() { 44 thrown.expect(OptionParseException.class); 45 thrown.expectMessage("test: unrecognized option '--long'"); 46 new OptionParser("test").parseOptions(Arrays.asList("--long")); 41 Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").parseOptions(Arrays.asList("--long"))); 42 assertEquals("test: unrecognized option '--long'", e.getMessage()); 47 43 } 48 44 49 45 @Test 50 46 public void testEmptyParserRejectsShortopt() { 51 thrown.expect(OptionParseException.class); 52 thrown.expectMessage("test: unrecognized option '-s'"); 53 new OptionParser("test").parseOptions(Arrays.asList("-s")); 47 Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").parseOptions(Arrays.asList("-s"))); 48 assertEquals("test: unrecognized option '-s'", e.getMessage()); 54 49 } 55 50 56 51 @Test 57 52 public void testParserRejectsWrongShortopt() { 58 thrown.expect(OptionParseException.class); 59 thrown.expectMessage("test: unrecognized option '-s'"); 60 new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "t") 61 .parseOptions(Arrays.asList("-s")); 53 Exception e = assertThrows(OptionParseException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "t") 54 .parseOptions(Arrays.asList("-s"))); 55 assertEquals("test: unrecognized option '-s'", e.getMessage()); 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, () -> new OptionParser("test").addFlagParameter("test", this::nop).parseOptions(Arrays.asList("--wrong"))); 61 assertEquals("test: unrecognized option '--wrong'", e.getMessage()); 69 62 } 70 63 71 64 @Test … … 80 73 81 74 @Test 82 75 public void testParserOptionFailsIfMissing() { 83 thrown.expect(OptionParseException.class);84 thrown.expectMessage("test: unrecognized option '--test2'");85 76 AtomicReference<String> argFound = new AtomicReference<>(); 86 77 OptionParser parser = new OptionParser("test") 87 78 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 88 79 89 parser.parseOptions(Arrays.asList("--test2", "arg")); 80 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "arg"))); 81 assertEquals("test: unrecognized option '--test2'", e.getMessage()); 90 82 } 91 83 92 84 @Test 93 85 public void testParserOptionFailsIfMissingArgument() { 94 thrown.expect(OptionParseException.class);95 thrown.expectMessage("test: unrecognized option '--test2'");96 86 AtomicReference<String> argFound = new AtomicReference<>(); 97 87 OptionParser parser = new OptionParser("test") 98 88 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 99 89 100 parser.parseOptions(Arrays.asList("--test2", "--other")); 90 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test2", "--other"))); 91 assertEquals("test: unrecognized option '--test2'", e.getMessage()); 101 92 } 102 93 103 94 @Test 104 95 public void testParserOptionFailsIfMissing2() { 105 thrown.expect(OptionParseException.class);106 thrown.expectMessage("test: option '--test' is required");107 96 AtomicReference<String> argFound = new AtomicReference<>(); 108 97 OptionParser parser = new OptionParser("test") 109 98 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 110 99 111 parser.parseOptions(Arrays.asList("--", "--test", "arg")); 100 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--", "--test", "arg"))); 101 assertEquals("test: option '--test' is required", e.getMessage()); 112 102 } 113 103 114 104 @Test 115 105 public void testParserOptionFailsIfTwice() { 116 thrown.expect(OptionParseException.class);117 thrown.expectMessage("test: option '--test' may not appear multiple times");118 106 AtomicReference<String> argFound = new AtomicReference<>(); 119 107 OptionParser parser = new OptionParser("test") 120 108 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set); 121 109 122 parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg")); 110 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "--test", "arg"))); 111 assertEquals("test: option '--test' may not appear multiple times", e.getMessage()); 123 112 } 124 113 125 114 @Test 126 115 public void testParserOptionFailsIfTwiceForAlias() { 127 thrown.expect(OptionParseException.class);128 thrown.expectMessage("test: option '-t' may not appear multiple times");129 116 AtomicReference<String> argFound = new AtomicReference<>(); 130 117 OptionParser parser = new OptionParser("test") 131 118 .addArgumentParameter("test", OptionCount.REQUIRED, argFound::set) 132 119 .addShortAlias("test", "t"); 133 120 134 parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg")); 121 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "arg", "-t", "arg"))); 122 assertEquals("test: option '-t' may not appear multiple times", e.getMessage()); 135 123 } 136 124 137 125 @Test 138 126 public void testOptionalOptionFailsIfTwice() { 139 thrown.expect(OptionParseException.class);140 thrown.expectMessage("test: option '--test' may not appear multiple times");141 127 OptionParser parser = new OptionParser("test") 142 128 .addFlagParameter("test", this::nop); 143 parser.parseOptions(Arrays.asList("--test", "--test")); 129 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--test"))); 130 assertEquals("test: option '--test' may not appear multiple times", e.getMessage()); 144 131 } 145 132 146 133 @Test 147 134 public void testOptionalOptionFailsIfTwiceForAlias() { 148 thrown.expect(OptionParseException.class);149 thrown.expectMessage("test: option '-t' may not appear multiple times");150 135 OptionParser parser = new OptionParser("test") 151 136 .addFlagParameter("test", this::nop) 152 137 .addShortAlias("test", "t"); 153 parser.parseOptions(Arrays.asList("-t", "-t")); 138 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "-t"))); 139 assertEquals("test: option '-t' may not appear multiple times", e.getMessage()); 154 140 } 155 141 156 142 @Test 157 143 public void testOptionalOptionFailsIfTwiceForAlias2() { 158 thrown.expect(OptionParseException.class);159 thrown.expectMessage("test: option '-t' may not appear multiple times");160 144 OptionParser parser = new OptionParser("test") 161 145 .addFlagParameter("test", this::nop) 162 146 .addShortAlias("test", "t"); 163 parser.parseOptions(Arrays.asList("-tt")); 147 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-tt"))); 148 assertEquals("test: option '-t' may not appear multiple times", e.getMessage()); 164 149 } 165 150 166 151 @Test … … 187 172 188 173 @Test 189 174 public void testLongArgumentsMissingOption() { 190 thrown.expect(OptionParseException.class);191 thrown.expectMessage("test: option '--test' requires an argument");192 175 OptionParser parser = new OptionParser("test") 193 176 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 194 177 195 parser.parseOptions(Arrays.asList("--test")); 178 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test"))); 179 assertEquals("test: option '--test' requires an argument", e.getMessage()); 196 180 } 197 181 198 182 @Test 199 183 public void testLongArgumentsMissingOption2() { 200 thrown.expect(OptionParseException.class);201 thrown.expectMessage("test: option '--test' requires an argument");202 184 OptionParser parser = new OptionParser("test") 203 185 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop); 204 186 205 parser.parseOptions(Arrays.asList("--test", "--", "x")); 187 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test", "--", "x"))); 188 assertEquals("test: option '--test' requires an argument", e.getMessage()); 206 189 } 207 190 208 191 @Test 209 192 public void testShortArgumentsMissingOption() { 210 thrown.expect(OptionParseException.class);211 thrown.expectMessage("test: option '-t' requires an argument");212 193 OptionParser parser = new OptionParser("test") 213 194 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 214 195 .addShortAlias("test", "t"); 215 196 216 parser.parseOptions(Arrays.asList("-t")); 197 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t"))); 198 assertEquals("test: option '-t' requires an argument", e.getMessage()); 217 199 } 218 200 219 201 @Test 220 202 public void testShortArgumentsMissingOption2() { 221 thrown.expect(OptionParseException.class);222 thrown.expectMessage("test: option '-t' requires an argument");223 203 OptionParser parser = new OptionParser("test") 224 204 .addArgumentParameter("test", OptionCount.REQUIRED, this::nop) 225 205 .addShortAlias("test", "t"); 226 206 227 parser.parseOptions(Arrays.asList("-t", "--", "x")); 207 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t", "--", "x"))); 208 assertEquals("test: option '-t' requires an argument", e.getMessage()); 228 209 } 229 210 230 211 @Test 231 212 public void testLongFlagHasOption() { 232 thrown.expect(OptionParseException.class);233 thrown.expectMessage("test: option '--test' does not allow an argument");234 213 OptionParser parser = new OptionParser("test") 235 214 .addFlagParameter("test", this::nop); 236 215 237 parser.parseOptions(Arrays.asList("--test=arg")); 216 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--test=arg"))); 217 assertEquals("test: option '--test' does not allow an argument", e.getMessage()); 238 218 } 239 219 240 220 @Test 241 221 public void testShortFlagHasOption() { 242 thrown.expect(OptionParseException.class);243 thrown.expectMessage("test: option '-t' does not allow an argument");244 222 OptionParser parser = new OptionParser("test") 245 223 .addFlagParameter("test", this::nop) 246 224 .addShortAlias("test", "t"); 247 225 248 parser.parseOptions(Arrays.asList("-t=arg")); 226 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("-t=arg"))); 227 assertEquals("test: option '-t' does not allow an argument", e.getMessage()); 249 228 } 250 229 251 230 @Test … … 305 284 306 285 @Test 307 286 public void testAmbiguousAlternatives() { 308 thrown.expect(OptionParseException.class);309 thrown.expectMessage("test: option '--fl' is ambiguous");310 287 AtomicReference<String> argFound = new AtomicReference<>(); 311 288 AtomicBoolean usedFlag = new AtomicBoolean(); 312 289 AtomicBoolean unusedFlag = new AtomicBoolean(); … … 316 293 .addFlagParameter("flag", () -> usedFlag.set(true)) 317 294 .addFlagParameter("fleg", () -> unusedFlag.set(true)); 318 295 319 parser.parseOptions(Arrays.asList("--te=arg", "--fl")); 296 Exception e = assertThrows(OptionParseException.class, () -> parser.parseOptions(Arrays.asList("--te=arg", "--fl"))); 297 assertEquals("test: option '--fl' is ambiguous", e.getMessage()); 320 298 } 321 299 322 300 @Test 323 301 public void testMultipleShort() { 302 // TODO figure out what is supposed to happen here 324 303 thrown.expect(OptionParseException.class); 325 304 thrown.expectMessage("test: unrecognized option '-ft'"); 326 305 AtomicReference<String> argFound = new AtomicReference<>(); … … 334 313 .addShortAlias("flag", "f") 335 314 .addFlagParameter("fleg", () -> unusedFlag.set(true)); 336 315 337 List<String> remaining = parser.parseOptions(Arrays.asList("-ft=arg", "x")); 316 final List<String> remaining = new ArrayList<>(); 317 remaining.addAll(parser.parseOptions(Arrays.asList("-ft=arg", "x"))); 318 Exception e = assertThrows(OptionParseException.class, () -> remaining.addAll(parser.parseOptions(Arrays.asList("-ft=arg", "x")))); 319 assertEquals("test: unrecognized option '-ft'", e.getMessage()); 338 320 339 321 assertEquals(Arrays.asList("x"), remaining); 340 322 assertEquals("arg", argFound.get()); … … 341 323 assertTrue(usedFlag.get()); 342 324 assertFalse(unusedFlag.get()); 343 325 344 remaining = parser.parseOptions(Arrays.asList("-ft", "arg", "x")); 326 remaining.clear(); 327 remaining.addAll(parser.parseOptions(Arrays.asList("-ft", "arg", "x"))); 345 328 346 329 assertEquals(Arrays.asList("x"), remaining); 347 330 assertEquals("arg", argFound.get()); … … 348 331 assertTrue(usedFlag.get()); 349 332 assertFalse(unusedFlag.get()); 350 333 351 remaining = parser.parseOptions(Arrays.asList("-f", "-t=arg", "x")); 334 remaining.clear(); 335 remaining.addAll(parser.parseOptions(Arrays.asList("-f", "-t=arg", "x"))); 352 336 353 337 assertEquals(Arrays.asList("x"), remaining); 354 338 assertEquals("arg", argFound.get()); … … 358 342 359 343 @Test 360 344 public void testIllegalOptionName() { 361 thrown.expect(IllegalArgumentException.class); 362 thrown.expectMessage("Illegal option name: ''"); 363 new OptionParser("test").addFlagParameter("", this::nop); 345 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("", this::nop)); 346 assertEquals("Illegal option name: ''", e.getMessage()); 364 347 } 365 348 366 349 @Test 367 350 public void testIllegalOptionName2() { 368 thrown.expect(IllegalArgumentException.class); 369 thrown.expectMessage("Illegal option name: '-'"); 370 new OptionParser("test").addFlagParameter("-", this::nop); 351 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-", this::nop)); 352 assertEquals("Illegal option name: '-'", e.getMessage()); 371 353 } 372 354 373 355 @Test 374 356 public void testIllegalOptionName3() { 375 thrown.expect(IllegalArgumentException.class); 376 thrown.expectMessage("Illegal option name: '-test'"); 377 new OptionParser("test").addFlagParameter("-test", this::nop); 357 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("-test", this::nop)); 358 assertEquals("Illegal option name: '-test'", e.getMessage()); 378 359 } 379 360 380 361 @Test 381 362 public void testIllegalOptionName4() { 382 thrown.expect(IllegalArgumentException.class); 383 thrown.expectMessage("Illegal option name: '$'"); 384 new OptionParser("test").addFlagParameter("$", this::nop); 363 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("$", this::nop)); 364 assertEquals("Illegal option name: '$'", e.getMessage()); 385 365 } 386 366 387 367 @Test 388 368 public void testDuplicateOptionName() { 389 thrown.expect(IllegalArgumentException.class); 390 thrown.expectMessage("The option '--test' is already registered"); 391 new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop); 369 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop)); 370 assertEquals("The option '--test' is already registered", e.getMessage()); 392 371 } 393 372 394 373 @Test 395 374 public void testDuplicateOptionName2() { 396 thrown.expect(IllegalArgumentException.class); 397 thrown.expectMessage("The option '--test' is already registered"); 398 new OptionParser("test").addFlagParameter("test", this::nop) 399 .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop); 375 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop) 376 .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop)); 377 assertEquals("The option '--test' is already registered", e.getMessage()); 400 378 } 401 379 402 380 @Test 403 381 public void testInvalidShortAlias() { 404 thrown.expect(IllegalArgumentException.class); 405 thrown.expectMessage("Short name '$' must be one character"); 406 new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$"); 382 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "$")); 383 assertEquals("Short name '$' must be one character", e.getMessage()); 407 384 } 408 385 409 386 @Test 410 387 public void testInvalidShortAlias2() { 411 thrown.expect(IllegalArgumentException.class); 412 thrown.expectMessage("Short name '' must be one character"); 413 new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", ""); 388 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "")); 389 assertEquals("Short name '' must be one character", e.getMessage()); 414 390 } 415 391 416 392 @Test 417 393 public void testInvalidShortAlias3() { 418 thrown.expect(IllegalArgumentException.class); 419 thrown.expectMessage("Short name 'xx' must be one character"); 420 new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx"); 394 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test", "xx")); 395 assertEquals("Short name 'xx' must be one character", e.getMessage()); 421 396 } 422 397 423 398 @Test 424 399 public void testDuplicateShortAlias() { 425 thrown.expect(IllegalArgumentException.class); 426 thrown.expectMessage("Short name 't' is already used"); 427 new OptionParser("test").addFlagParameter("test", this::nop) 400 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop) 428 401 .addFlagParameter("test2", this::nop) 429 402 .addShortAlias("test", "t") 430 .addShortAlias("test2", "t"); 403 .addShortAlias("test2", "t")); 404 assertEquals("Short name 't' is already used", e.getMessage()); 431 405 } 432 406 433 407 @Test 434 408 public void testInvalidShortNoLong() { 435 thrown.expect(IllegalArgumentException.class); 436 thrown.expectMessage("No long definition for test2 was defined. " + 437 "Define the long definition first before creating a short definition for it."); 438 new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t"); 409 Exception e = assertThrows(IllegalArgumentException.class, () -> new OptionParser("test").addFlagParameter("test", this::nop).addShortAlias("test2", "t")); 410 assertEquals("No long definition for test2 was defined. " + 411 "Define the long definition first before creating a short definition for it.", e.getMessage()); 439 412 } 440 413 441 414 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 */
