source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandlerTest.java

Last change on this file was 18037, checked in by Don-vip, 3 years ago

fix #21064 - Add JUnit 5 extension for preferences (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertThrows;
7
8import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
9import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
10
11import org.junit.jupiter.api.Test;
12
13/**
14 * Unit tests of {@link LoadAndZoomHandler} class.
15 */
16class LoadAndZoomHandlerTest {
17 private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException {
18 LoadAndZoomHandler req = new LoadAndZoomHandler();
19 if (url != null)
20 req.setUrl(url);
21 return req;
22 }
23
24 /**
25 * Unit test for bad request - no param.
26 * @throws Exception if any error occurs
27 */
28 @Test
29 void testBadRequestNoParam() throws Exception {
30 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
31 assertEquals("NumberFormatException (empty String)", e.getMessage());
32 }
33
34 /**
35 * Unit test for bad request - invalid URL.
36 * @throws Exception if any error occurs
37 */
38 @Test
39 void testBadRequestInvalidUrl() throws Exception {
40 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle());
41 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage());
42 }
43
44 /**
45 * Unit test for bad request - incomplete URL.
46 * @throws Exception if any error occurs
47 */
48 @Test
49 void testBadRequestIncompleteUrl() throws Exception {
50 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle());
51 assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage());
52 }
53
54 /**
55 * Unit test for nominal request - local data file.
56 * @throws Exception if any error occurs
57 */
58 @Test
59 @BasicPreferences
60 void testNominalRequest() throws Exception {
61 assertDoesNotThrow(() -> newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle());
62 }
63}
Note: See TracBrowser for help on using the repository browser.