Skip to content

Commit 53e1d25

Browse files
SP-56 Unit Tests - PayoutInstructionBtcSummaryDeserializer
1 parent 742fe5b commit 53e1d25

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2019 BitPay
3+
*/
4+
5+
package com.bitpay.sdk.util;
6+
7+
import com.bitpay.sdk.model.Payout.PayoutInstructionBtcSummary;
8+
import com.fasterxml.jackson.core.JsonParser;
9+
import com.fasterxml.jackson.databind.DeserializationContext;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import com.fasterxml.jackson.databind.node.DoubleNode;
12+
import com.fasterxml.jackson.databind.node.ObjectNode;
13+
import java.io.IOException;
14+
import org.junit.jupiter.api.Assertions;
15+
import org.junit.jupiter.api.Test;
16+
import org.mockito.Mockito;
17+
18+
public class PayoutInstructionBtcSummaryDeserializerTest {
19+
20+
@Test
21+
public void it_should_deserialize_btc() throws IOException {
22+
// given
23+
PayoutInstructionBtcSummaryDeserializer testedClass = new PayoutInstructionBtcSummaryDeserializer();
24+
JsonParser jsonParser = Mockito.mock(JsonParser.class);
25+
ObjectMapper objectMapper = Mockito.mock(ObjectMapper.class);
26+
ObjectNode node = Mockito.mock(ObjectNode.class);
27+
DoubleNode paid = Mockito.mock(DoubleNode.class);
28+
DoubleNode unpaid = Mockito.mock(DoubleNode.class);
29+
DeserializationContext deserializationContext = Mockito.mock(DeserializationContext.class);
30+
Mockito.when(jsonParser.getCodec()).thenReturn(objectMapper);
31+
Mockito.when(objectMapper.readTree(jsonParser)).thenReturn(node);
32+
Mockito.when(node.get("paid")).thenReturn(paid);
33+
Mockito.when(node.get("unpaid")).thenReturn(unpaid);
34+
Mockito.when(paid.asText()).thenReturn("2.0");
35+
Mockito.when(unpaid.asText()).thenReturn("4.0");
36+
37+
// when
38+
PayoutInstructionBtcSummary result = testedClass.deserialize(jsonParser, deserializationContext);
39+
40+
// then
41+
Assertions.assertEquals(2.0, result.getPaid());
42+
Assertions.assertEquals(4.0, result.getUnpaid());
43+
}
44+
}

0 commit comments

Comments
 (0)