source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java@ 16618

Last change on this file since 16618 was 16618, checked in by simon04, 4 years ago

see #16567 - Fix deprecations related to JUnit 5 (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 2.1 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.Rule;
9import org.junit.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 LoadObjectHandler} class.
17 */
18public class LoadObjectHandlerTest {
19 /**
20 * Setup test.
21 */
22 @Rule
23 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
24 public JOSMTestRules test = new JOSMTestRules();
25
26 private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException {
27 LoadObjectHandler req = new LoadObjectHandler();
28 if (url != null)
29 req.setUrl(url);
30 return req;
31 }
32
33 /**
34 * Unit test for bad request - no param.
35 */
36 @Test
37 public void testBadRequestNoParam() {
38 assertDoesNotThrow(() -> newHandler(null).handle());
39 }
40
41 /**
42 * Unit test for bad request - invalid URL.
43 */
44 @Test
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());
48 }
49
50 /**
51 * Unit test for bad request - incomplete URL.
52 */
53 @Test
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());
57 }
58
59 /**
60 * Unit test for nominal request - local data file.
61 */
62 @Test
63 public void testNominalRequest() {
64 assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle());
65 }
66}
Note: See TracBrowser for help on using the repository browser.