25
25
26
26
public class TransactionTest extends TestCase {
27
27
28
- public static final Transaction TRANSACTION_1 = new Transaction ("order1" , "android.test.purchased" , "com.example" , Transaction .PurchaseState .PURCHASED , "notificationId" , new Date ().getTime (), "developerPayload" );
29
- public static final Transaction TRANSACTION_2 = new Transaction ("order2" , "product_2" , "com.example" , Transaction .PurchaseState .PURCHASED , "notificationId" , new Date ().getTime (), "developerPayload" );
30
- public static final Transaction TRANSACTION_2_REFUNDED = new Transaction ("order4" , "product_2" , "com.example" , Transaction .PurchaseState .REFUNDED , "notificationId" , new Date ().getTime (), "developerPayload" );
31
- public static final Transaction TRANSACTION_1_REFUNDED = new Transaction ("order3" , "android.test.purchased" , "com.example" , Transaction .PurchaseState .REFUNDED , "notificationId" , new Date ().getTime (), "developerPayload" );
28
+ public static final Transaction TRANSACTION_1 = new Transaction ("order1" , "android.test.purchased" , "com.example" , Transaction .PurchaseState .PURCHASED , "notificationId" , new Date ().getTime (), "developerPayload" , "signature" , "signedData" );
29
+ public static final Transaction TRANSACTION_2 = new Transaction ("order2" , "product_2" , "com.example" , Transaction .PurchaseState .PURCHASED , "notificationId" , new Date ().getTime (), "developerPayload" , "signature" , "signedData" );
30
+ public static final Transaction TRANSACTION_2_REFUNDED = new Transaction ("order4" , "product_2" , "com.example" , Transaction .PurchaseState .REFUNDED , "notificationId" , new Date ().getTime (), "developerPayload" , "signature" , "signedData" );
31
+ public static final Transaction TRANSACTION_1_REFUNDED = new Transaction ("order3" , "android.test.purchased" , "com.example" , Transaction .PurchaseState .REFUNDED , "notificationId" , new Date ().getTime (), "developerPayload" , "signature" , "signedData" );
32
32
public static void assertEquals (Transaction a , Transaction b ) {
33
33
assertTrue (a .equals (b ));
34
34
}
35
35
36
- @ SmallTest
37
- public void testParseAllFields () throws Exception {
36
+ private void testParseAllFields (Transaction transaction ) throws Exception {
38
37
JSONObject json = new JSONObject ();
39
- json .put (Transaction .ORDER_ID , TRANSACTION_1 .orderId );
40
- json .put (Transaction .PRODUCT_ID , TRANSACTION_1 .productId );
41
- json .put (Transaction .PACKAGE_NAME , TRANSACTION_1 .packageName );
42
- json .put (Transaction .PURCHASE_STATE , TRANSACTION_1 .purchaseState .ordinal ());
43
- json .put (Transaction .NOTIFICATION_ID , TRANSACTION_1 .notificationId );
44
- json .put (Transaction .PURCHASE_TIME , TRANSACTION_1 .purchaseTime );
45
- json .put (Transaction .DEVELOPER_PAYLOAD , TRANSACTION_1 .developerPayload );
38
+ json .put (Transaction .ORDER_ID , transaction .orderId );
39
+ json .put (Transaction .PRODUCT_ID , transaction .productId );
40
+ json .put (Transaction .PACKAGE_NAME , transaction .packageName );
41
+ json .put (Transaction .PURCHASE_STATE , transaction .purchaseState .ordinal ());
42
+ json .put (Transaction .NOTIFICATION_ID , transaction .notificationId );
43
+ json .put (Transaction .PURCHASE_TIME , transaction .purchaseTime );
44
+ json .put (Transaction .DEVELOPER_PAYLOAD , transaction .developerPayload );
46
45
final Transaction parsed = Transaction .parse (json );
47
- assertEquals (TRANSACTION_1 , parsed );
46
+ assertEquals (transaction .orderId , parsed .orderId );
47
+ assertEquals (transaction .productId , parsed .productId );
48
+ assertEquals (transaction .packageName , parsed .packageName );
49
+ assertEquals (transaction .purchaseState , parsed .purchaseState );
50
+ assertEquals (transaction .notificationId , parsed .notificationId );
51
+ assertEquals (transaction .purchaseTime , parsed .purchaseTime );
52
+ assertEquals (transaction .developerPayload , parsed .developerPayload );
53
+ assertNull (parsed .signature );
54
+ assertNull (parsed .signedData );
55
+ }
56
+
57
+ @ SmallTest
58
+ public void testParseAllFields () throws Exception {
59
+ testParseAllFields (TRANSACTION_1 );
60
+ testParseAllFields (TRANSACTION_2 );
48
61
}
49
62
50
63
@ SmallTest
@@ -62,6 +75,8 @@ public void testParseOnlyMandatoryFields() throws Exception {
62
75
assertNull (parsed .notificationId );
63
76
assertEquals (TRANSACTION_1 .purchaseTime , parsed .purchaseTime );
64
77
assertNull (parsed .developerPayload );
78
+ assertNull (parsed .signature );
79
+ assertNull (parsed .signedData );
65
80
}
66
81
67
82
@ SmallTest
@@ -76,11 +91,14 @@ public void testPurchaseStateOrdinal() throws Exception {
76
91
public void testEquals () throws Exception {
77
92
assertTrue (TRANSACTION_1 .equals (TRANSACTION_1 ));
78
93
assertTrue (TRANSACTION_1 .equals (TRANSACTION_1 .clone ()));
79
- assertFalse (TRANSACTION_1 .equals (TRANSACTION_2_REFUNDED ));
94
+ assertTrue (TRANSACTION_1 .clone ().equals (TRANSACTION_1 ));
95
+ assertFalse (TRANSACTION_1 .equals (TRANSACTION_2 ));
96
+ assertFalse (TRANSACTION_2 .equals (TRANSACTION_1 ));
80
97
}
81
98
82
99
@ SmallTest
83
100
public void testClone () throws Exception {
84
101
assertEquals (TRANSACTION_1 , TRANSACTION_1 .clone ());
102
+ assertEquals (TRANSACTION_2 , TRANSACTION_2 .clone ());
85
103
}
86
104
}
0 commit comments