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 | import net.trajano.commons.testing.UtilityClassTestUtil;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests for class {@link SignpostAdapters}.
|
---|
25 | */
|
---|
26 | public class SignpostAdaptersTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules().https();
|
---|
34 |
|
---|
35 | private static HttpClient newClient() throws MalformedURLException {
|
---|
36 | return HttpClient.create(new URL("https://www.openstreetmap.org"));
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Tests that {@code SignpostAdapters} satisfies utility class criterias.
|
---|
41 | * @throws ReflectiveOperationException if an error occurs
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void testUtilityClass() throws ReflectiveOperationException {
|
---|
45 | UtilityClassTestUtil.assertUtilityClassWellDefined(SignpostAdapters.class);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Unit test of method {@link SignpostAdapters.OAuthConsumer#wrap}.
|
---|
50 | * @throws MalformedURLException never
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void testOAuthConsumerWrap() throws MalformedURLException {
|
---|
54 | assertNotNull(new OAuthConsumer("", "").wrap(newClient()));
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Unit test of method {@link SignpostAdapters.HttpRequest#getMessagePayload}.
|
---|
59 | * @throws IOException never
|
---|
60 | */
|
---|
61 | @Test
|
---|
62 | public void testHttpRequestGetMessagePayload() throws IOException {
|
---|
63 | assertNull(new HttpRequest(newClient()).getMessagePayload());
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Unit test of method {@link SignpostAdapters.HttpRequest#setRequestUrl}.
|
---|
68 | * @throws IOException never
|
---|
69 | */
|
---|
70 | @Test(expected = IllegalStateException.class)
|
---|
71 | public void testHttpRequestSetRequestUrl() throws IOException {
|
---|
72 | new HttpRequest(newClient()).setRequestUrl(null);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Unit test of method {@link SignpostAdapters.HttpRequest#getAllHeaders}.
|
---|
77 | * @throws IOException never
|
---|
78 | */
|
---|
79 | @Test(expected = IllegalStateException.class)
|
---|
80 | public void testHttpRequestGetAllHeaders() throws IOException {
|
---|
81 | new HttpRequest(newClient()).getAllHeaders();
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Unit test of method {@link SignpostAdapters.HttpRequest#unwrap}.
|
---|
86 | * @throws IOException never
|
---|
87 | */
|
---|
88 | @Test(expected = IllegalStateException.class)
|
---|
89 | public void testHttpRequestUnwrap() throws IOException {
|
---|
90 | new HttpRequest(newClient()).unwrap();
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Unit test of method {@link SignpostAdapters.HttpResponse#getReasonPhrase()}.
|
---|
95 | * @throws Exception never
|
---|
96 | */
|
---|
97 | @Test
|
---|
98 | public void testHttpResponseGetReasonPhrase() throws Exception {
|
---|
99 | assertEquals("OK", new HttpResponse(new HttpRequest(newClient()).request.connect()).getReasonPhrase());
|
---|
100 | }
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Unit test of method {@link SignpostAdapters.HttpResponse#unwrap}.
|
---|
104 | * @throws IOException never
|
---|
105 | */
|
---|
106 | @Test(expected = IllegalStateException.class)
|
---|
107 | public void testHttpResponseUnwrap() throws IOException {
|
---|
108 | new HttpResponse(new HttpRequest(newClient()).request.connect()).unwrap();
|
---|
109 | }
|
---|
110 | }
|
---|