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