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

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

improve unit test coverage of utilities classes thanks to https://trajano.github.io/commons-testing

  • Property svn:eol-style set to native
File size: 3.6 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.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpRequest;
15import org.openstreetmap.josm.data.oauth.SignpostAdapters.HttpResponse;
16import org.openstreetmap.josm.data.oauth.SignpostAdapters.OAuthConsumer;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18import org.openstreetmap.josm.tools.HttpClient;
19
20import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
21import net.trajano.commons.testing.UtilityClassTestUtil;
22
23/**
24 * Unit tests for class {@link SignpostAdapters}.
25 */
26public 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();
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}
Note: See TracBrowser for help on using the repository browser.