1+ package protect .card_locker ;
2+
13import android .os .Parcel ;
24import android .os .Parcelable ;
35
911import java .util .Currency ;
1012import java .util .Date ;
1113
12- import static org .junit .Assert .assertEquals ;
13- import static org .junit .Assert .assertFalse ;
14- import static org .junit .Assert .assertNotNull ;
15- import static org .junit .Assert .assertNull ;
16- import static org .junit .Assert .assertTrue ;
14+ import com .google .zxing .BarcodeFormat ;
15+
16+ import static org .junit .Assert .*;
1717
1818@ RunWith (MockitoJUnitRunner .class )
1919public class LoyaltyCardTest {
2020
21- /**
22- * Test the parcelable implementation of the LoyaltyCard class.
23- *
24- * This test creates a LoyaltyCard object, writes it to a Parcel, and then
25- * recreates the object from the Parcel. It asserts that the original and
26- * recreated objects have the same values for all their fields.
27- *
28- * @throws AssertionError if any of the assertions fail
29- */
3021 @ Test
3122 public void testParcelable () {
32-
3323 Date validFrom = new Date ();
3424 Date expiry = new Date ();
3525 BigDecimal balance = new BigDecimal ("100.00" );
3626 Currency currency = Currency .getInstance ("USD" );
37- LoyaltyCard card = new LoyaltyCard (1 , "Store A" , "Note A" , validFrom , expiry , balance , currency , "12345" , "67890" , CatimaBarcode .QR_CODE , 0xFF0000 , 1 , System .currentTimeMillis (), 10 , 0 );
27+ LoyaltyCard card = new LoyaltyCard (1 , "Store A" , "Note A" , validFrom , expiry , balance , currency , "12345" , "67890" , CatimaBarcode .fromBarcode ( BarcodeFormat . QR_CODE ) , 0xFF0000 , 1 , System .currentTimeMillis (), 10 , 0 );
3828
3929 Parcel parcel = Parcel .obtain ();
4030 card .writeToParcel (parcel , card .describeContents ());
@@ -52,7 +42,7 @@ public void testParcelable() {
5242 assertEquals (card .balanceType , createdFromParcel .balanceType );
5343 assertEquals (card .cardId , createdFromParcel .cardId );
5444 assertEquals (card .barcodeId , createdFromParcel .barcodeId );
55- assertEquals (card .barcodeType , createdFromParcel .barcodeType );
45+ assertEquals (card .barcodeType . name () , createdFromParcel .barcodeType . name () );
5646 assertEquals (card .headerColor , createdFromParcel .headerColor );
5747 assertEquals (card .starStatus , createdFromParcel .starStatus );
5848 assertEquals (card .lastUsed , createdFromParcel .lastUsed );
@@ -67,7 +57,7 @@ public void testIsDuplicate_sameObject() {
6757 Date now = new Date ();
6858 BigDecimal balance = new BigDecimal ("50.00" );
6959 Currency currency = Currency .getInstance ("EUR" );
70- LoyaltyCard card1 = new LoyaltyCard (1 , "Store B" , "Note B" , now , now , balance , currency , "22222" , "33333" , CatimaBarcode .PDF_417 , 0x00FF00 , 1 , System .currentTimeMillis (), 5 , 1 );
60+ LoyaltyCard card1 = new LoyaltyCard (1 , "Store B" , "Note B" , now , now , balance , currency , "22222" , "33333" , CatimaBarcode .fromBarcode ( BarcodeFormat . PDF_417 ) , 0x00FF00 , 1 , System .currentTimeMillis (), 5 , 1 );
7161
7262 assertTrue (LoyaltyCard .isDuplicate (card1 , card1 ));
7363 }
@@ -78,8 +68,8 @@ public void testIsDuplicate_differentObjects() {
7868 BigDecimal balance1 = new BigDecimal ("50.00" );
7969 BigDecimal balance2 = new BigDecimal ("75.00" );
8070 Currency currency = Currency .getInstance ("EUR" );
81- LoyaltyCard card1 = new LoyaltyCard (2 , "Store C" , "Note C" , now , now , balance1 , currency , "44444" , "55555" , CatimaBarcode .DATA_MATRIX , 0x0000FF , 0 , System .currentTimeMillis (), 15 , 1 );
82- LoyaltyCard card2 = new LoyaltyCard (2 , "Store C" , "Note C" , now , now , balance2 , currency , "44444" , "55555" , CatimaBarcode .DATA_MATRIX , 0x0000FF , 0 , System .currentTimeMillis (), 15 , 1 );
71+ LoyaltyCard card1 = new LoyaltyCard (2 , "Store C" , "Note C" , now , now , balance1 , currency , "44444" , "55555" , CatimaBarcode .fromBarcode ( BarcodeFormat . DATA_MATRIX ) , 0x0000FF , 0 , System .currentTimeMillis (), 15 , 1 );
72+ LoyaltyCard card2 = new LoyaltyCard (2 , "Store C" , "Note C" , now , now , balance2 , currency , "44444" , "55555" , CatimaBarcode .fromBarcode ( BarcodeFormat . DATA_MATRIX ) , 0x0000FF , 0 , System .currentTimeMillis (), 15 , 1 );
8373
8474 assertFalse (LoyaltyCard .isDuplicate (card1 , card2 ));
8575 }
@@ -89,7 +79,7 @@ public void testToString() {
8979 Date now = new Date ();
9080 BigDecimal balance = new BigDecimal ("100.00" );
9181 Currency currency = Currency .getInstance ("USD" );
92- LoyaltyCard card = new LoyaltyCard (3 , "Store D" , "Note D" , now , now , balance , currency , "66666" , "77777" , CatimaBarcode .AZTEC , null , 2 , System .currentTimeMillis (), 20 , 2 );
82+ LoyaltyCard card = new LoyaltyCard (3 , "Store D" , "Note D" , now , now , balance , currency , "66666" , "77777" , CatimaBarcode .fromBarcode ( BarcodeFormat . AZTEC ) , null , 2 , System .currentTimeMillis (), 20 , 2 );
9383
9484 String expected = String .format (
9585 "LoyaltyCard{%n id=%s,%n store=%s,%n note=%s,%n validFrom=%s,%n expiry=%s,%n"
0 commit comments