Skip to content

Commit

Permalink
Fix AssetDeserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Jun 12, 2017
1 parent 6569eb3 commit 4b3ed9c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AssetDeserializer implements JsonDeserializer<Asset> {
@Override
public Asset deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String type = json.getAsJsonObject().get("asset_type").getAsString();
if (type == "native") {
if (type.equals("native")) {
return new AssetTypeNative();
} else {
String code = json.getAsJsonObject().get("asset_code").getAsString();
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.stellar.sdk.responses;

import junit.framework.TestCase;
import org.junit.Test;
import org.stellar.sdk.Asset;
import org.stellar.sdk.AssetTypeCreditAlphaNum;

public class AssetDeserializerTest extends TestCase {
@Test
public void testDeserializeNative() {
String json = "{\"asset_type\": \"native\"}";
Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class);
assertEquals(asset.getType(), "native");
}

@Test
public void testDeserializeCredit() {
String json = "{\n" +
" \"asset_type\": \"credit_alphanum4\",\n" +
" \"asset_code\": \"CNY\",\n" +
" \"asset_issuer\": \"GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX\"\n" +
"}";
Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class);
assertEquals(asset.getType(), "credit_alphanum4");
AssetTypeCreditAlphaNum creditAsset = (AssetTypeCreditAlphaNum) asset;
assertEquals(creditAsset.getCode(), "CNY");
assertEquals(creditAsset.getIssuer().getAccountId(), "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX");
}
}

0 comments on commit 4b3ed9c

Please sign in to comment.