Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #66 from datalorax/auth_intercept
Browse files Browse the repository at this point in the history
Fixes #54: Add hashCode and equals to AuthenticationInterceptor
  • Loading branch information
joaopsilva committed Feb 8, 2018
2 parents 31fd444 + d3ef4f3 commit 71556ef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class BinanceApiServiceGenerator {

private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

private static Retrofit.Builder builder =
new Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Objects;

/**
* A request interceptor that injects the API Key Header into requests, and signs messages, whenever required.
Expand Down Expand Up @@ -74,4 +75,18 @@ private static String bodyToString(RequestBody request) {
throw new RuntimeException(e);
}
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final AuthenticationInterceptor that = (AuthenticationInterceptor) o;
return Objects.equals(apiKey, that.apiKey) &&
Objects.equals(secret, that.secret);
}

@Override
public int hashCode() {
return Objects.hash(apiKey, secret);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.binance.api.client.impl;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* @author andy coates
* created 08/02/2018.
*/
public class BinanceApiServiceGeneratorTest {
@Test
public void shouldOnlyAddAuthInterceptorOnce() throws Exception {
// Given:
BinanceApiServiceGenerator.createService(BinanceApiService.class, "someKey", "someValue");
final int initialSize = BinanceApiServiceGenerator.httpClient.interceptors().size();

// When:
BinanceApiServiceGenerator.createService(BinanceApiService.class, "someKey", "someValue");

// Then
assertEquals(BinanceApiServiceGenerator.httpClient.interceptors().size(), initialSize);
}
}

0 comments on commit 71556ef

Please sign in to comment.