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

Last change on this file since 12558 was 12558, checked in by Don-vip, 7 years ago

see #15102 - unit tests update

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import org.junit.Rule;
5import org.junit.Test;
6import org.junit.rules.ExpectedException;
7import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
8import org.openstreetmap.josm.testutils.JOSMTestRules;
9
10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11
12/**
13 * Unit tests of {@link LoadAndZoomHandler} class.
14 */
15public class LoadAndZoomHandlerTest {
16
17 /**
18 * Rule used for tests throwing exceptions.
19 */
20 @Rule
21 public ExpectedException thrown = ExpectedException.none();
22
23 /**
24 * Setup test.
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules();
29
30 private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException {
31 LoadAndZoomHandler req = new LoadAndZoomHandler();
32 if (url != null)
33 req.setUrl(url);
34 return req;
35 }
36
37 /**
38 * Unit test for bad request - no param.
39 * @throws Exception if any error occurs
40 */
41 @Test
42 public void testBadRequestNoParam() throws Exception {
43 thrown.expect(RequestHandlerBadRequestException.class);
44 thrown.expectMessage("NumberFormatException (empty String)");
45 newHandler(null).handle();
46 }
47
48 /**
49 * Unit test for bad request - invalid URL.
50 * @throws Exception if any error occurs
51 */
52 @Test
53 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();
57 }
58
59 /**
60 * Unit test for bad request - incomplete URL.
61 * @throws Exception if any error occurs
62 */
63 @Test
64 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();
68 }
69
70 /**
71 * Unit test for nominal request - local data file.
72 * @throws Exception if any error occurs
73 */
74 @Test
75 public void testNominalRequest() throws Exception {
76 newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle();
77 }
78}
Note: See TracBrowser for help on using the repository browser.