1
+ package com .github .binarywang .wxpay .bean .request ;
2
+
3
+ import com .google .gson .Gson ;
4
+ import org .testng .annotations .Test ;
5
+
6
+ import java .util .Arrays ;
7
+
8
+ import static org .assertj .core .api .Assertions .assertThat ;
9
+
10
+ /**
11
+ * @author <a href="https://github.com/binarywang">Binary Wang</a>
12
+ * created on 2024-12-19
13
+ */
14
+ public class CombineCloseRequestTest {
15
+
16
+ @ Test
17
+ public void testSerialization () {
18
+ CombineCloseRequest request = new CombineCloseRequest ();
19
+ request .setCombineAppid ("wxd678efh567hg6787" );
20
+ request .setCombineOutTradeNo ("P20150806125346" );
21
+
22
+ CombineCloseRequest .SubOrders subOrder = new CombineCloseRequest .SubOrders ();
23
+ subOrder .setMchid ("1900000109" );
24
+ subOrder .setOutTradeNo ("20150806125346" );
25
+ subOrder .setSubMchid ("1230000109" );
26
+ subOrder .setSubAppid ("wxd678efh567hg6999" );
27
+
28
+ request .setSubOrders (Arrays .asList (subOrder ));
29
+
30
+ Gson gson = new Gson ();
31
+ String json = gson .toJson (request );
32
+
33
+ // Verify that the JSON contains the new fields
34
+ assertThat (json ).contains ("\" sub_mchid\" :\" 1230000109\" " );
35
+ assertThat (json ).contains ("\" sub_appid\" :\" wxd678efh567hg6999\" " );
36
+ assertThat (json ).contains ("\" combine_appid\" :\" wxd678efh567hg6787\" " );
37
+ assertThat (json ).contains ("\" mchid\" :\" 1900000109\" " );
38
+ assertThat (json ).contains ("\" out_trade_no\" :\" 20150806125346\" " );
39
+
40
+ // Verify deserialization works
41
+ CombineCloseRequest deserializedRequest = gson .fromJson (json , CombineCloseRequest .class );
42
+ assertThat (deserializedRequest .getCombineAppid ()).isEqualTo ("wxd678efh567hg6787" );
43
+ assertThat (deserializedRequest .getSubOrders ()).hasSize (1 );
44
+ assertThat (deserializedRequest .getSubOrders ().get (0 ).getSubMchid ()).isEqualTo ("1230000109" );
45
+ assertThat (deserializedRequest .getSubOrders ().get (0 ).getSubAppid ()).isEqualTo ("wxd678efh567hg6999" );
46
+ }
47
+ }
0 commit comments