Skip to content

Commit

Permalink
Merge pull request #53 from paypay/codacy-issues
Browse files Browse the repository at this point in the history
codacy issues fixed
  • Loading branch information
Shreyansh Pandey committed Sep 25, 2020
2 parents 6459312 + 653b891 commit b8f11b1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/main/java/jp/ne/paypay/ApiClient.java
Expand Up @@ -188,19 +188,19 @@ public Authentication getAuthentication(String authName) {
}

/**
* Helper method to set API key for the first HTTP Hmac authentication.
* Helper method to set API key for the first HTTP HMAC authentication.
*
* @param apiKey apiKey
* @throws RuntimeException If HMAC authentication not configured
*/
public void setApiKey(String apiKey) {
public void setApiKey(String apiKey) throws ApiException {
for (Authentication auth : authentications.values()) {
if (auth instanceof HmacAuth) {
((HmacAuth) auth).setApiKey(apiKey);
return;
}
}
throw new RuntimeException("HMAC authentication not configured: API key");
throw new ApiException("HMAC authentication not configured: API key");
}

/**
Expand Down Expand Up @@ -229,14 +229,14 @@ private void setRequestParameters(String requestUrl, String method, Object reque
* @param apiSecret apiSecret
* @throws RuntimeException If HMAC authentication not configured
*/
public void setApiSecretKey(String apiSecret) {
public void setApiSecretKey(String apiSecret) throws ApiException {
for (Authentication auth : authentications.values()) {
if (auth instanceof HmacAuth) {
((HmacAuth) auth).setApiSecretKey(apiSecret);
return;
}
}
throw new RuntimeException("HMAC authentication not configured: API Secret key");
throw new ApiException("HMAC authentication not configured: API Secret key");
}

/**
Expand Down Expand Up @@ -718,7 +718,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, List<P
* @throws ApiException If fail to serialize the request body object
*/
public Request buildRequest(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames) throws ApiException {
updateParamsForAuth(authNames, queryParams, headerParams);
updateParamsForAuth(authNames, queryParams, headerParams);

final String url = buildUrl(path, queryParams, collectionQueryParams);
final Request.Builder reqBuilder = new Request.Builder().url(url);
Expand Down Expand Up @@ -822,10 +822,10 @@ public void processHeaderParams(Map<String, String> headerParams, Request.Builde
* @param queryParams List of query parameters
* @param headerParams Map of header parameters
*/
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) throws ApiException {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
if (auth == null) throw new ApiException("Authentication undefined: " + authName);
auth.applyToParams(queryParams, headerParams);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jp/ne/paypay/example/PaymentApiExample.java
Expand Up @@ -31,7 +31,7 @@
public class PaymentApiExample {


public static void main(String[] args) {
public static void main(String[] args) throws ApiException{
ApiClient apiClient = new Configuration().getDefaultApiClient();
apiClient.setProductionMode(false);
apiClient.setApiKey("API_KEY");
Expand Down
Expand Up @@ -15,7 +15,7 @@
public class PendingPaymentApiExample extends PaymentApiExample {


public static void main(String[] args) {
public static void main(String[] args) throws ApiException {
ApiClient apiClient = new Configuration().getDefaultApiClient();
apiClient.setProductionMode(false);
apiClient.setApiKey("API_KEY");
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/jp/ne/paypay/api/ApiClientTest.java
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.reflect.TypeToken;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
Expand Down Expand Up @@ -39,7 +38,7 @@

public class ApiClientTest {

ApiClient apiClient = new ApiClient();
private ApiClient apiClient = new ApiClient();

@Mock
private Call call;
Expand All @@ -49,7 +48,7 @@ void init(){
MockitoAnnotations.openMocks(this);
}
@Test
public void configTest(){
public void configTest() throws ApiException{
Configuration configuration = new Configuration();
apiClient.setProductionMode(false);
apiClient.setApiKey("api-key");
Expand Down Expand Up @@ -122,7 +121,6 @@ public void selectHeaderAcceptTest(){
String selectHeaderAccept = apiClient.selectHeaderAccept(accepts);
Assert.assertEquals(selectHeaderAccept, "application/json");
selectHeaderAccept = apiClient.selectHeaderAccept(new String[1]);
System.out.println(selectHeaderAccept);
Assert.assertEquals("null", selectHeaderAccept);
accepts[0] = "application/text";
selectHeaderAccept = apiClient.selectHeaderAccept(accepts);
Expand All @@ -135,7 +133,6 @@ public void selectHeaderContentTypeTest(){
String headerContentType = apiClient.selectHeaderContentType(accepts);
Assert.assertEquals(headerContentType, "application/json");
headerContentType = apiClient.selectHeaderContentType(new String[0]);
System.out.println(headerContentType);
Assert.assertEquals("application/json;charset=UTF-8", headerContentType);
accepts[0] = "application/text";
headerContentType = apiClient.selectHeaderContentType(accepts);
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/jp/ne/paypay/api/WalletApiTest.java
Expand Up @@ -23,11 +23,10 @@ public class WalletApiTest {
@Mock
private final WalletApi api = Mockito.spy(new WalletApi());
private ResultInfo resultInfo;
private ApiClient apiClient;

@BeforeEach
public void setUp(){
apiClient = Mockito.mock(ApiClient.class);
ApiClient apiClient = Mockito.mock(ApiClient.class);
api.setApiClient(apiClient);
resultInfo = new ResultInfo();
resultInfo.setMessage("SUCCESS");
Expand Down

0 comments on commit b8f11b1

Please sign in to comment.