public static void addToRequest(Crypto crypto, SecretKey key, byte[] requestBody, String signatureAlgorithm, Request request) {
        Mac mac;
        try {
            mac = crypto.mac(signatureAlgorithm);
        }  catch (NoSuchAlgorithmException e) {
            throw new ConnectException(e);
        }
        byte[] requestSignature = sign(mac, key, requestBody);
        request.header(InternalRequestSignature.SIGNATURE_HEADER, Base64.getEncoder().encodeToString(requestSignature))
               .header(InternalRequestSignature.SIGNATURE_ALGORITHM_HEADER, signatureAlgorithm);
    }
@Test
    public void addToRequestShouldAddHeadersOnValidSignatureAlgorithm() {
        Request request = mock(Request.class);
        ArgumentCaptor<String> signatureCapture = ArgumentCaptor.forClass(String.class);
        ArgumentCaptor<String> signatureAlgorithmCapture = ArgumentCaptor.forClass(String.class);
        when(request.header(
                eq(InternalRequestSignature.SIGNATURE_HEADER),
                signatureCapture.capture()
            )).thenReturn(request);
        when(request.header(
                eq(InternalRequestSignature.SIGNATURE_ALGORITHM_HEADER),
                signatureAlgorithmCapture.capture()
            )).thenReturn(request);

        InternalRequestSignature.addToRequest(crypto, KEY, REQUEST_BODY, SIGNATURE_ALGORITHM, request);

        assertEquals(ENCODED_SIGNATURE,
            signatureCapture.getValue(),
            "Request should have valid base 64-encoded signature added as header");
        assertEquals(SIGNATURE_ALGORITHM,
            signatureAlgorithmCapture.getValue(),
            "Request should have provided signature algorithm added as header");
    }