1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.oauth;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
8 |
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.net.MalformedURLException;
|
---|
11 | import java.net.URL;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.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.annotations.HTTPS;
|
---|
18 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
19 |
|
---|
20 | import net.trajano.commons.testing.UtilityClassTestUtil;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests for class {@link SignpostAdapters}.
|
---|
24 | */
|
---|
25 | @HTTPS
|
---|
26 | class SignpostAdaptersTest {
|
---|
27 |
|
---|
28 | private static HttpClient newClient() throws MalformedURLException {
|
---|
29 | return HttpClient.create(new URL("https://www.openstreetmap.org"));
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Tests that {@code SignpostAdapters} satisfies utility class criteria.
|
---|
34 | * @throws ReflectiveOperationException if an error occurs
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | void testUtilityClass() throws ReflectiveOperationException {
|
---|
38 | UtilityClassTestUtil.assertUtilityClassWellDefined(SignpostAdapters.class);
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Unit test of method {@link SignpostAdapters.OAuthConsumer#wrap}.
|
---|
43 | * @throws MalformedURLException never
|
---|
44 | */
|
---|
45 | @Test
|
---|
46 | void testOAuthConsumerWrap() throws MalformedURLException {
|
---|
47 | assertNotNull(new OAuthConsumer("", "").wrap(newClient()));
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Unit test of method {@link SignpostAdapters.HttpRequest#getMessagePayload}.
|
---|
52 | * @throws IOException never
|
---|
53 | */
|
---|
54 | @Test
|
---|
55 | void testHttpRequestGetMessagePayload() throws IOException {
|
---|
56 | assertNull(new HttpRequest(newClient()).getMessagePayload());
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Unit test of method {@link SignpostAdapters.HttpRequest#setRequestUrl}.
|
---|
61 | */
|
---|
62 | @Test
|
---|
63 | void testHttpRequestSetRequestUrl() {
|
---|
64 | assertThrows(IllegalStateException.class, () -> new HttpRequest(newClient()).setRequestUrl(null));
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Unit test of method {@link SignpostAdapters.HttpRequest#getAllHeaders}.
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | void testHttpRequestGetAllHeaders() {
|
---|
72 | assertThrows(IllegalStateException.class, () -> new HttpRequest(newClient()).getAllHeaders());
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Unit test of method {@link SignpostAdapters.HttpRequest#unwrap}.
|
---|
77 | */
|
---|
78 | @Test
|
---|
79 | void testHttpRequestUnwrap() {
|
---|
80 | assertThrows(IllegalStateException.class, () -> new HttpRequest(newClient()).unwrap());
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Unit test of method {@link SignpostAdapters.HttpResponse#getReasonPhrase()}.
|
---|
85 | * @throws Exception never
|
---|
86 | */
|
---|
87 | @Test
|
---|
88 | 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 | */
|
---|
95 | @Test
|
---|
96 | void testHttpResponseUnwrap() {
|
---|
97 | assertThrows(IllegalStateException.class, () -> new HttpResponse(new HttpRequest(newClient()).request.connect()).unwrap());
|
---|
98 | }
|
---|
99 | }
|
---|