Ticket #24951: 24951.patch

File 24951.patch, 3.7 KB (added by DanProgs <Abenteurer.2901@…>, 4 hours ago)
  • test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java

    ### Eclipse Workspace Patch 1.0
    #P josm
    diff --git test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java
    index f742a38..c960509 100644
     
    88import static org.junit.jupiter.api.Assertions.assertTrue;
    99
    1010import java.net.MalformedURLException;
    11 import java.net.URL;
     11import java.net.URI;
    1212
    1313import javax.swing.JOptionPane;
    1414
    … …  
    5959    }
    6060
    6161    private static HttpClient apiRequest() throws MalformedURLException {
    62         return HttpClient.create(new URL(API_URL + "/0.6/changeset/create"), "PUT");
     62        return HttpClient.create(URI.create(API_URL + "/0.6/changeset/create").toURL(), "PUT");
    6363    }
    6464
    6565    /**
    6666     * Stores the advanced OAuth parameters the way the authentication preferences do, that is under the API URL.
    6767     */
    6868    private static OAuth20Parameters rememberParameters() {
    69         OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI);
     69        final OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI);
    7070        parameters.rememberPreferences();
    7171        return parameters;
    7272    }
    … …  
    8181     */
    8282    @Test
    8383    void testOAuthParametersComeFromTheApiUrl() throws Exception {
    84         OAuth20Parameters parameters = rememberParameters();
     84        final OAuth20Parameters parameters = rememberParameters();
    8585        // a token is needed, otherwise the connection would try to obtain one
    8686        OAuthAccessTokenHolder.getInstance().setAccessToken(API_URL, new OAuth20Token(parameters,
    8787                "{\"token_type\":\"bearer\", \"access_token\":\"a-token\"}"));
    8888
    89         TestConnection connection = new TestConnection();
     89        final TestConnection connection = new TestConnection();
    9090        assertNull(connection.parameters());
    91         HttpClient client = apiRequest();
     91        final HttpClient client = apiRequest();
    9292        connection.addOAuth20AuthorizationHeader(client);
    9393
    9494        assertEquals(CLIENT_ID, connection.parameters().getClientId());
    … …  
    110110        Config.getPref().putInt("message.oauth.oauth20.obtain.automatically.value", JOptionPane.NO_OPTION);
    111111
    112112        // no parameters remembered for this API, and it has no client id built into JOSM
    113         HttpClient client = apiRequest();
    114         MissingOAuthAccessTokenException thrown = assertThrows(MissingOAuthAccessTokenException.class,
     113        final HttpClient client = apiRequest();
     114        final MissingOAuthAccessTokenException thrown = assertThrows(MissingOAuthAccessTokenException.class,
    115115                () -> new TestConnection().addOAuth20AuthorizationHeader(client));
    116116        assertNotNull(thrown.getMessage(), "gave up only after asking the user, rather than for the missing client id");
    117117        assertTrue(thrown.getMessage().contains(API_URL), thrown.getMessage());
    … …  
    125125     */
    126126    @Test
    127127    void testExistingTokenSignsTheConnection() throws Exception {
    128         OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI);
     128        final OAuth20Parameters parameters = new OAuth20Parameters(CLIENT_ID, null, API_URL, API_URL, REDIRECT_URI);
    129129        OAuthAccessTokenHolder.getInstance().setAccessToken(API_URL, new OAuth20Token(parameters,
    130130                "{\"token_type\":\"bearer\", \"access_token\":\"another-token\"}"));
    131131
    132         HttpClient client = apiRequest();
     132        final HttpClient client = apiRequest();
    133133        new TestConnection().addOAuth20AuthorizationHeader(client);
    134134        assertEquals("Bearer another-token", client.getRequestHeader("Authorization"));
    135135    }