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

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

convert more unit tests to JOSMTestRules

  • Property svn:eol-style set to native
File size: 3.2 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;
21
22/**
23 * Unit tests for class {@link SignpostAdapters}.
24 */
25public 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}
Note: See TracBrowser for help on using the repository browser.