static void validateAccessTokenScopes(HttpURLConnection connection) {
        //check for user:email or user AND repo scopes
        String scopesHeader = connection.getHeaderField("X-OAuth-Scopes");
        if(scopesHeader == null){
            throw new ServiceException.PreconditionRequired("No scopes associated with this token. Expected scopes 'user:email, repo'.");
        }
        List<String> scopes = new ArrayList<>();
        for(String s: scopesHeader.split(",")){
            scopes.add(s.trim());
        }
        List<String> missingScopes = new ArrayList<>();
        if(!scopes.contains(USER_EMAIL_SCOPE) && !scopes.contains(USER_SCOPE)){
            missingScopes.add(USER_EMAIL_SCOPE);
        }
        if(!scopes.contains(REPO_SCOPE)){
            missingScopes.add(REPO_SCOPE);
        }
        if(!missingScopes.isEmpty()){
            throw new ServiceException.PreconditionRequired("Invalid token, its missing scopes: "+ StringUtils.join(missingScopes, ","));
        }
    }
@Test
    public void validateAccessTokenScopes() throws Exception {

        HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);

        HttpRequest httpRequest = mock(HttpRequest.class);

        try (MockedStatic<HttpRequest> mockedStatic = mockStatic(HttpRequest.class)) {
            when(HttpRequest.get(GitHubSCMSource.GITHUB_URL)).thenReturn(httpRequest);
            when(httpRequest.withAuthorizationToken(any())).thenReturn(httpRequest);
            when(httpRequest.connect()).thenReturn(httpURLConnectionMock);
            when(httpURLConnectionMock.getHeaderField("X-OAuth-Scopes")).thenReturn("user:email,repo");
            when(httpURLConnectionMock.getResponseCode()).thenReturn(200);
            HttpURLConnection httpURLConnection = GithubScm.connect(GitHubSCMSource.GITHUB_URL, "abcd");
            GithubScm.validateAccessTokenScopes(httpURLConnection);
        }
    }