View Javadoc
1   package org.oxerr.okcoin.rest.dto;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.fail;
5   
6   import java.io.IOException;
7   import java.math.BigDecimal;
8   
9   import org.junit.Test;
10  import org.oxerr.okcoin.rest.OKCoinException;
11  
12  import com.fasterxml.jackson.core.JsonParseException;
13  import com.fasterxml.jackson.databind.JsonMappingException;
14  
15  public class UserInfoTest extends UnmarshalTest {
16  
17  	@Test
18  	public void test() throws JsonParseException, JsonMappingException, IOException {
19  		UserInfo userInfo = readValue(
20  				"userinfo.json",
21  				UserInfo.class);
22  
23  		assertEquals(new BigDecimal("1000"), userInfo.getInfo().getFunds().getFree().get("cny"));
24  		assertEquals(new BigDecimal("10"), userInfo.getInfo().getFunds().getFree().get("btc"));
25  		assertEquals(new BigDecimal("0"), userInfo.getInfo().getFunds().getFree().get("ltc"));
26  
27  		assertEquals(new BigDecimal("1000"), userInfo.getInfo().getFunds().getFrozen().get("cny"));
28  		assertEquals(new BigDecimal("10"), userInfo.getInfo().getFunds().getFrozen().get("btc"));
29  		assertEquals(new BigDecimal("0"), userInfo.getInfo().getFunds().getFrozen().get("ltc"));
30  	}
31  
32  	@Test
33  	public void testError() throws JsonParseException, JsonMappingException,
34  			IOException {
35  		try {
36  			readValue("userinfo-error.json", UserInfo.class);
37  			fail("A JsonMappingException should be thrown.");
38  		} catch (JsonMappingException e) {
39  			assertEquals(10000, ((OKCoinException) e.getCause()).getErrorCode().intValue());
40  		}
41  	}
42  
43  }