#vulnerable code 
                                @Test
    public void testSendCertificateRequest() throws Exception {
        when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);

        try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
            conn.sendCertificateRequest(requestUrl, session);
        }

        verify(mockUrlConnection).setRequestMethod("GET");
        verify(mockUrlConnection).setRequestProperty("Accept", "application/pem-certificate-chain");
        verify(mockUrlConnection).setRequestProperty("Accept-Charset", "utf-8");
        verify(mockUrlConnection).setRequestProperty("Accept-Language", "ja-JP");
        verify(mockUrlConnection).setDoOutput(false);
        verify(mockUrlConnection).connect();
        verify(mockUrlConnection).getResponseCode();
        verify(mockUrlConnection, atLeast(0)).getHeaderFields();
        verifyNoMoreInteractions(mockUrlConnection);
    } 
                            #location 7 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testSendCertificateRequest() throws Exception {
        final String nonce1 = Base64Url.encode("foo-nonce-1-foo".getBytes());
        final String nonce2 = Base64Url.encode("foo-nonce-2-foo".getBytes());
        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
        when(mockUrlConnection.getOutputStream()).thenReturn(outputStream);

        try (DefaultConnection conn = new DefaultConnection(mockHttpConnection) {
            @Override
            public void resetNonce(Session session) {
                assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
                if (session.getNonce() == null) {
                    session.setNonce(nonce1);
                } else {
                    fail("unknown nonce");
                }
            }

            @Override
            public String getNonce() {
                assertThat(session, is(sameInstance(DefaultConnectionTest.this.session)));
                if (session.getNonce() == nonce1) {
                    return nonce2;
                } else {
                    fail("unknown nonce");
                    return null;
                }
            }
        }) {
            conn.sendCertificateRequest(requestUrl, login);
        }

        verify(mockUrlConnection).setRequestMethod("POST");
        verify(mockUrlConnection).setRequestProperty("Accept", "application/pem-certificate-chain");
        verify(mockUrlConnection).setRequestProperty("Accept-Charset", "utf-8");
        verify(mockUrlConnection).setRequestProperty("Accept-Language", "ja-JP");
        verify(mockUrlConnection).setRequestProperty("Content-Type", "application/jose+json");
        verify(mockUrlConnection).setDoOutput(true);
        verify(mockUrlConnection).connect();
        verify(mockUrlConnection).setFixedLengthStreamingMode(outputStream.toByteArray().length);
        verify(mockUrlConnection).getResponseCode();
        verify(mockUrlConnection).getOutputStream();
        verify(mockUrlConnection, atLeast(0)).getHeaderFields();
        verifyNoMoreInteractions(mockUrlConnection);
    }