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

Last change on this file since 10364 was 10116, checked in by Don-vip, 8 years ago

add more unit tests

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import org.junit.BeforeClass;
5import org.junit.Rule;
6import org.junit.Test;
7import org.junit.rules.ExpectedException;
8import org.openstreetmap.josm.JOSMFixture;
9import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
10
11/**
12 * Unit tests of {@link LoadAndZoomHandler} class.
13 */
14public class LoadAndZoomHandlerTest {
15
16 /**
17 * Rule used for tests throwing exceptions.
18 */
19 @Rule
20 public ExpectedException thrown = ExpectedException.none();
21
22 /**
23 * Setup test.
24 */
25 @BeforeClass
26 public static void setUpBeforeClass() {
27 JOSMFixture.createUnitTestFixture().init(true);
28 }
29
30 private static LoadAndZoomHandler newHandler(String url) {
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.