Skip to content

Commit

Permalink
Second review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sedouard committed Nov 16, 2017
1 parent 030d934 commit da4197d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
22 changes: 11 additions & 11 deletions src/main/java/com/stripe/net/StripeResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@

public class StripeResponse {

int responseCode;
String responseBody;
int code;
String body;
StripeHeaders headers;

public StripeResponse(int responseCode, String responseBody) {
this.responseCode = responseCode;
this.responseBody = responseBody;
public StripeResponse(int code, String body) {
this.code = code;
this.body = body;
this.headers = null;
}

public StripeResponse(int responseCode, String responseBody, Map<String, List<String>> responseHeaders) {
this.responseCode = responseCode;
this.responseBody = responseBody;
this.headers = new StripeHeaders(responseHeaders);
public StripeResponse(int code, String body, Map<String, List<String>> headers) {
this.code = code;
this.body = body;
this.headers = new StripeHeaders(headers);
}

public int code() {
return responseCode;
return this.code;
}

public String body() {
return responseBody;
return this.body;
}

public StripeHeaders headers() {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/stripe/functional/StripeResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public void testResponseIncluded() throws
APIConnectionException,
CardException {
String idempotencyKey = Long.toString(System.currentTimeMillis());
RequestOptions includeResponseRequestOptions = RequestOptions.builder()
RequestOptions requestOptions = RequestOptions.builder()
.setStripeVersion(Stripe.apiVersion)
.setIdempotencyKey(idempotencyKey)
.build();
Customer cus = Customer.create(defaultCustomerParams, includeResponseRequestOptions);
cus = Customer.retrieve(cus.getId(), includeResponseRequestOptions);
Customer cus = Customer.create(defaultCustomerParams, requestOptions);
cus = Customer.retrieve(cus.getId(), requestOptions);
StripeResponse resp = cus.getLastResponse();
assertThat(resp, instanceOf(StripeResponse.class));
assertEquals(200, resp.code());
Expand Down
21 changes: 8 additions & 13 deletions src/test/java/com/stripe/net/StripeHeadersTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.stripe.net;

import com.stripe.BaseStripeTest;
import com.stripe.Stripe;
import com.stripe.net.StripeHeaders;

import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -20,13 +16,13 @@ public class StripeHeadersTest extends BaseStripeTest {

private Map<String, List<String>> generateHeaderMap () {
Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
List<String> bearerHeader = new ArrayList<String>();
bearerHeader.add("Bearer");
bearerHeader.add("sk_live_12345");
List<String> multiValueHeader = new ArrayList<String>();
multiValueHeader.add("FirstValue");
multiValueHeader.add("SecondValue");
List<String> requestIdHeader = new ArrayList<String>();
requestIdHeader.add("req_12345");
headerMap.put("Request-Id", requestIdHeader);
headerMap.put("Authorization", bearerHeader);
headerMap.put("Multi-Val", multiValueHeader);
headerMap.put("Empty-Header", new ArrayList<String>());
return headerMap;
}
Expand All @@ -35,21 +31,20 @@ private Map<String, List<String>> generateHeaderMap () {
public void testGet() {
StripeHeaders headers = new StripeHeaders(generateHeaderMap());
assertEquals("req_12345", headers.get("Request-Id"));
assertEquals("Bearer", headers.get("Authorization"));
assertEquals("FirstValue", headers.get("Multi-Val"));
}

@Test
public void testValues() {
StripeHeaders headers = new StripeHeaders(generateHeaderMap());
assertEquals(2, headers.values("Authorization").size());
assertEquals("Bearer", headers.values("Authorization").get(0));
assertEquals("sk_live_12345", headers.values("Authorization").get(1));
assertEquals(2, headers.values("Multi-Val").size());
assertEquals("FirstValue", headers.values("Multi-Val").get(0));
assertEquals("SecondValue", headers.values("Multi-Val").get(1));
}

@Test
public void testGetEmpty() {
StripeHeaders headers = new StripeHeaders(generateHeaderMap());
assertEquals(null, headers.get("Empty-Header"));
}

}

0 comments on commit da4197d

Please sign in to comment.