Skip to content

Commit

Permalink
Merge pull request #27 from mt/deserialize-previous_attributes
Browse files Browse the repository at this point in the history
Fix 1-off error in deserializeJsonArray()
  • Loading branch information
ebroder committed Feb 15, 2013
2 parents 39f9fb0 + f0e9735 commit 2958220
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/stripe/model/EventDataDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Object[] deserializeJsonArray(JsonArray arr) {
int i = 0;
while (elemIter.hasNext()) {
JsonElement elem = elemIter.next();
elems[++i] = deserializeJsonElement(elem);
elems[i++] = deserializeJsonElement(elem);
}
return elems;
}
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/stripe/model/EventDataDeserializerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.stripe.model;

import com.google.gson.Gson;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;

public class EventDataDeserializerTest {

private static Gson gson = com.stripe.net.APIResource.gson;

@Test
public void deserializePreviousAttributes() throws IOException {

String json = resource("previous_attributes.json");
EventData ed = gson.fromJson(json,EventData.class);

assertThat(ed.getPreviousAttributes().get("fee"), notNullValue());
}



private String resource(String path) throws IOException {
InputStream resource = getClass().getResourceAsStream(path);

ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
byte[] buf = new byte [1024];

for( int i = resource.read(buf); i > 0; i = resource.read(buf)) {
os.write(buf,0,i);
}


return os.toString("utf8");


}
}
50 changes: 50 additions & 0 deletions src/test/resources/com/stripe/model/previous_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{"object":{
"id":"ch_1EqUp1gsDwETBV",
"object":"charge",
"created":1360113273,
"livemode":true,
"paid":true,
"amount":19200,
"currency":"usd",
"refunded":true,
"fee":0,
"fee_details":[
{
"amount":452,
"currency":"usd",
"type":"stripe_fee",
"description":"Stripe processing fees",
"application":null,
"amount_refunded":452
}
],
"card":{
"object":"card",
"last4":"9999",
"type":"MasterCard",
"exp_month":1,
"exp_year":3000,
"fingerprint":"YTHoNT67aqtBzHev",
"country":"US",
"name":"xxxxx xxxxx",
"address_city":null,
"cvc_check":"pass"
},
"customer":"cus_1EqUMhiOJLbXyi",
"invoice":"in_1EqUCLGCSCuXyT",
"dispute":null,
"disputed":false
}, "previous_attributes":{
"refunded":false,
"fee":452,
"fee_details":[
{
"amount":452,
"currency":"usd",
"type":"stripe_fee",
"description":"Stripe processing fees",
"application":null,
"amount_refunded":0
}
]
}}

0 comments on commit 2958220

Please sign in to comment.