source: josm/trunk/test/unit/org/openstreetmap/josm/data/oauth/SignpostAdaptersTest.java@ 10201

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

add more unit tests

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.oauth;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7
8import java.io.IOException;
9import java.net.MalformedURLException;
10import java.net.URL;
11
12import org.junit.BeforeClass;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpRequest;
16import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpResponse;
17import org.openstreetmap.josm.data.oauth.SignpostAdapters.OAuthConsumer;
18import org.openstreetmap.josm.tools.HttpClient;
19
20/**
21 * Unit tests for class {@link SignpostAdapters}.
22 */
23public class SignpostAdaptersTest {
24
25 /**
26 * Setup test.
27 */
28 @BeforeClass
29 public static void setUpBeforeClass() {
30 JOSMFixture.createUnitTestFixture().init();
31 }
32
33 private static HttpClient newClient() throws MalformedURLException {
34 return HttpClient.create(new URL("https://www.openstreetmap.org"));
35 }
36
37 /**
38 * Unit test of method {@link SignpostAdapters.OAuthConsumer#wrap}.
39 * @throws MalformedURLException never
40 */
41 @Test
42 public void testOAuthConsumerWrap() throws MalformedURLException {
43 assertNotNull(new OAuthConsumer("", "").wrap(newClient()));
44 }
45
46 /**
47 * Unit test of method {@link SignpostAdapters.HttpRequest#getMessagePayload}.
48 * @throws IOException never
49 */
50 @Test
51 public void testHttpRequestGetMessagePayload() throws IOException {
52 assertNull(new HttpRequest(newClient()).getMessagePayload());
53 }
54
55 /**
56 * Unit test of method {@link SignpostAdapters.HttpRequest#setRequestUrl}.
57 * @throws IOException never
58 */
59 @Test(expected = IllegalStateException.class)
60 public void testHttpRequestSetRequestUrl() throws IOException {
61 new HttpRequest(newClient()).setRequestUrl(null);
62 }
63
64 /**
65 * Unit test of method {@link SignpostAdapters.HttpRequest#getAllHeaders}.
66 * @throws IOException never
67 */
68 @Test(expected = IllegalStateException.class)
69 public void testHttpRequestGetAllHeaders() throws IOException {
70 new HttpRequest(newClient()).getAllHeaders();
71 }
72
73 /**
74 * Unit test of method {@link SignpostAdapters.HttpRequest#unwrap}.
75 * @throws IOException never
76 */
77 @Test(expected = IllegalStateException.class)
78 public void testHttpRequestUnwrap() throws IOException {
79 new HttpRequest(newClient()).unwrap();
80 }
81
82 /**
83 * Unit test of method {@link SignpostAdapters.HttpResponse#getReasonPhrase()}.
84 * @throws Exception never
85 */
86 @Test
87 public void testHttpResponseGetReasonPhrase() throws Exception {
88 assertEquals("OK", new HttpResponse(new HttpRequest(newClient()).request.connect()).getReasonPhrase());
89 }
90
91 /**
92 * Unit test of method {@link SignpostAdapters.HttpResponse#unwrap}.
93 * @throws IOException never
94 */
95 @Test(expected = IllegalStateException.class)
96 public void testHttpResponseUnwrap() throws IOException {
97 new HttpResponse(new HttpRequest(newClient()).request.connect()).unwrap();
98 }
99}
Note: See TracBrowser for help on using the repository browser.