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

Last change on this file since 18893 was 18893, checked in by taylor.smock, 7 months ago

Fix #16567: Upgrade to JUnit 5

JOSMTestRules and JOSMTestFixture can reset the default JOSM profile, which can
be unexpected for new contributors. This updates all tests to use JUnit 5 and
the new JUnit 5 annotations.

This also renames MapCSSStyleSourceFilterTest to MapCSSStyleSourceFilterPerformanceTest
to match the naming convention for performance tests and fixes some lint issues.

This was tested by running all tests individually and together.

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.oauth;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertThrows;
8
9import java.io.IOException;
10import java.net.MalformedURLException;
11import java.net.URL;
12
13import org.junit.jupiter.api.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.annotations.HTTPS;
18import org.openstreetmap.josm.tools.HttpClient;
19
20import net.trajano.commons.testing.UtilityClassTestUtil;
21
22/**
23 * Unit tests for class {@link SignpostAdapters}.
24 */
25@HTTPS
26class 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}
Note: See TracBrowser for help on using the repository browser.