Changeset 19654 in josm


Ignore:
Timestamp:
2026-10-22T17:10:19+02:00 (9 hours ago)
Author:
stoecker
Message:

fix #24951 - Fix Sonar issues in recent Grid Layer and OAuth - patches by DanProgs & wangi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/OsmConnectionTest.java

    r19638 r19654  
    99
    1010import java.net.MalformedURLException;
    11 import java.net.URL;
     11import java.net.URI;
    1212
    1313import javax.swing.JOptionPane;
    … …  
    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
    … …  
    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;
    … …  
    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
    … …  
    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");
    … …  
    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"));
Note: See TracChangeset for help on using the changeset viewer.