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

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

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 2.6 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.junit.jupiter.api.extension.RegisterExtension;
9import org.junit.jupiter.api.Test;
10import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
11import org.openstreetmap.josm.testutils.JOSMTestRules;
12
13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14
15/**
16 * Unit tests of {@link LoadAndZoomHandler} class.
17 */
18class LoadAndZoomHandlerTest {
19 /**
20 * Setup test.
21 */
22 @RegisterExtension
23 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
24 public JOSMTestRules test = new JOSMTestRules();
25
26 private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException {
27 LoadAndZoomHandler req = new LoadAndZoomHandler();
28 if (url != null)
29 req.setUrl(url);
30 return req;
31 }
32
33 /**
34 * Unit test for bad request - no param.
35 * @throws Exception if any error occurs
36 */
37 @Test
38 void testBadRequestNoParam() throws Exception {
39 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
40 assertEquals("NumberFormatException (empty String)", e.getMessage());
41 }
42
43 /**
44 * Unit test for bad request - invalid URL.
45 * @throws Exception if any error occurs
46 */
47 @Test
48 void testBadRequestInvalidUrl() throws Exception {
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());
51 }
52
53 /**
54 * Unit test for bad request - incomplete URL.
55 * @throws Exception if any error occurs
56 */
57 @Test
58 void testBadRequestIncompleteUrl() throws Exception {
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());
61 }
62
63 /**
64 * Unit test for nominal request - local data file.
65 * @throws Exception if any error occurs
66 */
67 @Test
68 void testNominalRequest() throws Exception {
69 assertDoesNotThrow(() -> newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle());
70 }
71}
Note: See TracBrowser for help on using the repository browser.