mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-01-17 19:38:03 -05:00
Load translations (TODO: tests)
This commit is contained in:
@@ -149,17 +149,16 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
headerTextColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR, record, true);
|
||||
}
|
||||
|
||||
JSONObject extras;
|
||||
ExtrasHelper extras;
|
||||
|
||||
try
|
||||
{
|
||||
extras = new JSONObject(extractString(DBHelper.LoyaltyCardDbIds.EXTRAS, record, ""));
|
||||
extras = new ExtrasHelper().fromJSON(new JSONObject(extractString(DBHelper.LoyaltyCardDbIds.EXTRAS, record, "{}")));
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
throw new FormatException("Invalid JSON in extras field: " + ex);
|
||||
}
|
||||
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class DBHelper extends SQLiteOpenHelper
|
||||
@@ -77,7 +78,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
|
||||
public long insertLoyaltyCard(final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor, final JSONObject extras)
|
||||
final Integer headerTextColor, final ExtrasHelper extras) throws JSONException
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -87,7 +88,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toJSON().toString());
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return newId;
|
||||
}
|
||||
@@ -95,7 +96,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
|
||||
final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor, final JSONObject extras)
|
||||
final Integer headerTextColor, final ExtrasHelper extras) throws JSONException
|
||||
{
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(LoyaltyCardDbIds.ID, id);
|
||||
@@ -105,7 +106,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toJSON().toString());
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return (newId != -1);
|
||||
}
|
||||
@@ -114,7 +115,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
public boolean updateLoyaltyCard(final int id, final String store, final String note,
|
||||
final String cardId, final String barcodeType,
|
||||
final Integer headerColor, final Integer headerTextColor,
|
||||
final JSONObject extras)
|
||||
final ExtrasHelper extras) throws JSONException
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -124,7 +125,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toString());
|
||||
contentValues.put(LoyaltyCardDbIds.EXTRAS, extras.toJSON().toString());
|
||||
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues,
|
||||
LoyaltyCardDbIds.ID + "=?",
|
||||
new String[]{Integer.toString(id)});
|
||||
|
||||
54
app/src/main/java/protect/card_locker/ExtrasHelper.java
Normal file
54
app/src/main/java/protect/card_locker/ExtrasHelper.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class ExtrasHelper {
|
||||
private HashMap<String, LinkedHashMap<String, String>> extras = new HashMap<>();
|
||||
|
||||
public ExtrasHelper fromJSON(JSONObject json) throws JSONException
|
||||
{
|
||||
Iterator<String> languages = json.keys();
|
||||
|
||||
while(languages.hasNext())
|
||||
{
|
||||
String language = languages.next();
|
||||
Iterator<String> keys = json.getJSONObject(language).keys();
|
||||
|
||||
while(keys.hasNext())
|
||||
{
|
||||
String key = keys.next();
|
||||
addLanguageValue(language, key, json.getJSONObject(language).getString(key));
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSONObject toJSON() throws JSONException
|
||||
{
|
||||
return new JSONObject(extras);
|
||||
}
|
||||
|
||||
public void addLanguageValue(String language, String key, String value)
|
||||
{
|
||||
if(!extras.containsKey(language))
|
||||
{
|
||||
extras.put(language, new LinkedHashMap<String, String>());
|
||||
}
|
||||
|
||||
LinkedHashMap<String, String> values = extras.get(language);
|
||||
values.put(key, value);
|
||||
|
||||
extras.put(language, values);
|
||||
}
|
||||
|
||||
public HashMap<String, String> getAllValues(String language)
|
||||
{
|
||||
return extras.get(language);
|
||||
}
|
||||
}
|
||||
@@ -47,10 +47,10 @@ public class ImportURIHelper {
|
||||
Integer headerColor = Integer.parseInt(uri.getQueryParameter(HEADER_COLOR));
|
||||
Integer headerTextColor = Integer.parseInt(uri.getQueryParameter(HEADER_TEXT_COLOR));
|
||||
// Extras was added in a later version, so don't crash if it doesn't exist
|
||||
JSONObject extras = new JSONObject();
|
||||
ExtrasHelper extras = new ExtrasHelper();
|
||||
if(uri.getQueryParameter(EXTRAS) != null)
|
||||
{
|
||||
extras = new JSONObject(uri.getQueryParameter(EXTRAS));
|
||||
extras = new ExtrasHelper().fromJSON(new JSONObject(uri.getQueryParameter(EXTRAS)));
|
||||
}
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
} catch (NullPointerException | NumberFormatException | JSONException ex) {
|
||||
|
||||
@@ -23,11 +23,11 @@ public class LoyaltyCard
|
||||
public final Integer headerTextColor;
|
||||
|
||||
@Nullable
|
||||
public final JSONObject extras;
|
||||
public final ExtrasHelper extras;
|
||||
|
||||
public LoyaltyCard(final int id, final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor, final Integer headerTextColor,
|
||||
final JSONObject extras)
|
||||
final ExtrasHelper extras)
|
||||
{
|
||||
this.id = id;
|
||||
this.store = store;
|
||||
@@ -64,13 +64,13 @@ public class LoyaltyCard
|
||||
}
|
||||
|
||||
int extrasColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.EXTRAS);
|
||||
JSONObject extras = new JSONObject();
|
||||
ExtrasHelper extras = new ExtrasHelper();
|
||||
|
||||
if(cursor.isNull(extrasColumn) == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
extras = new JSONObject(cursor.getString(extrasColumn));
|
||||
extras = new ExtrasHelper().fromJSON(new JSONObject(cursor.getString(extrasColumn)));
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
String importLoyaltyCardType = null;
|
||||
Integer headingColorValue = null;
|
||||
Integer headingStoreTextColorValue = null;
|
||||
JSONObject extras = new JSONObject();
|
||||
ExtrasHelper extras = new ExtrasHelper();
|
||||
|
||||
DBHelper db;
|
||||
ImportURIHelper importUriHelper;
|
||||
@@ -400,7 +400,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void doSave()
|
||||
private void doSave() throws JSONException
|
||||
{
|
||||
String store = storeFieldEdit.getText().toString();
|
||||
String note = noteFieldEdit.getText().toString();
|
||||
@@ -492,7 +492,14 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
return true;
|
||||
|
||||
case R.id.action_save:
|
||||
doSave();
|
||||
try {
|
||||
doSave();
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
Toast.makeText(this, R.string.failedSavingCard, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,10 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
@@ -220,7 +222,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
if(loyaltyCard != null && loyaltyCard.extras.length() > 0)
|
||||
if(loyaltyCard != null && !loyaltyCard.extras.getAllValues(Locale.getDefault().getLanguage()).isEmpty())
|
||||
{
|
||||
MenuItem item = menu.findItem(R.id.action_view_extras);
|
||||
item.setVisible(true);
|
||||
@@ -302,12 +304,10 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
{
|
||||
StringBuilder items = new StringBuilder();
|
||||
|
||||
Iterator<String> iter = loyaltyCard.extras.keys();
|
||||
while(iter.hasNext())
|
||||
HashMap<String, String> extraValues = loyaltyCard.extras.getAllValues(Locale.getDefault().getLanguage());
|
||||
for(String key : extraValues.keySet())
|
||||
{
|
||||
String key = iter.next();
|
||||
String value = loyaltyCard.extras.getString(key);
|
||||
items.append(key + ": " + value + "\n");
|
||||
items.append(extraValues.get(key) + "\n");
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
|
||||
@@ -14,8 +14,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -24,14 +24,52 @@ import java.util.zip.ZipInputStream;
|
||||
public class PkpassImporter {
|
||||
private Context context;
|
||||
|
||||
public PkpassImporter(Context context) {
|
||||
private HashMap<String, HashMap<String, String>> translations = new HashMap<>();
|
||||
|
||||
public PkpassImporter(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private JSONObject appendFieldDictionaryValues(JSONObject original, JSONObject pkpassJSON, String styleKey, String arrayName) throws JSONException
|
||||
private String readZipInputStream(ZipInputStream zipInputStream) throws IOException
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int c = zipInputStream.read(); c != -1; c = zipInputStream.read())
|
||||
{
|
||||
sb.append((char) c);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// FIXME: Probably very fragile
|
||||
private void parseTranslations(String language, String iOSTranslationFileContent)
|
||||
{
|
||||
if(!translations.containsKey(language))
|
||||
{
|
||||
translations.put(language, new HashMap<String, String>());
|
||||
}
|
||||
|
||||
HashMap<String, String> values = translations.get(language);
|
||||
|
||||
for (String entry : iOSTranslationFileContent.trim().split(";"))
|
||||
{
|
||||
String[] parts = entry.split(" = ", 2);
|
||||
|
||||
// Remove all spaces around the key and value
|
||||
String key = parts[0].trim();
|
||||
String value = parts[1].trim();
|
||||
|
||||
// iOS .string files quote everything in double quotes, we don't need to keep those
|
||||
values.put(key.substring(1, key.length()-1), value.substring(1, value.length()-1));
|
||||
}
|
||||
|
||||
translations.put(language, values);
|
||||
}
|
||||
|
||||
private ExtrasHelper appendData(ExtrasHelper extrasHelper, JSONObject pkpassJSON, String styleKey, String arrayName) throws JSONException
|
||||
{
|
||||
// https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/FieldDictionary.html#//apple_ref/doc/uid/TP40012026-CH4-SW1
|
||||
// TODO: Do something with label
|
||||
|
||||
JSONArray fields;
|
||||
// These are all optional, so don't throw an exception if they don't exist
|
||||
@@ -41,16 +79,52 @@ public class PkpassImporter {
|
||||
}
|
||||
catch (JSONException ex)
|
||||
{
|
||||
return original;
|
||||
return extrasHelper;
|
||||
}
|
||||
|
||||
for(int i = 0; i < fields.length(); i++)
|
||||
{
|
||||
JSONObject fieldObject = fields.getJSONObject(i);
|
||||
original.put(fieldObject.getString("key"), fieldObject.getString("value"));
|
||||
String key = fieldObject.getString("key");
|
||||
String label = fieldObject.getString("label");
|
||||
String value = fieldObject.getString("value");
|
||||
|
||||
// Label is optional
|
||||
if(label == null)
|
||||
{
|
||||
label = key;
|
||||
}
|
||||
|
||||
// Add the completely untranslated stuff as fallback
|
||||
extrasHelper.addLanguageValue("", key, label + ": " + value);
|
||||
|
||||
// Try to find translations
|
||||
for(String language : translations.keySet())
|
||||
{
|
||||
String translatedLabel = label;
|
||||
if(translations.get(language).containsKey(label))
|
||||
{
|
||||
translatedLabel = translations.get(language).get(label);
|
||||
}
|
||||
|
||||
String translatedValue = value;
|
||||
if(translations.get(language).containsKey(value))
|
||||
{
|
||||
translatedValue = translations.get(language).get(value);
|
||||
}
|
||||
|
||||
String formattedValue = translatedValue;
|
||||
|
||||
if(!translatedLabel.isEmpty())
|
||||
{
|
||||
formattedValue = translatedLabel + ": " + translatedValue;
|
||||
}
|
||||
|
||||
extrasHelper.addLanguageValue(language, key, formattedValue);
|
||||
}
|
||||
}
|
||||
|
||||
return original;
|
||||
return extrasHelper;
|
||||
}
|
||||
|
||||
public boolean isPkpass(String type) {
|
||||
@@ -63,30 +137,37 @@ public class PkpassImporter {
|
||||
|
||||
public LoyaltyCard fromInputStream(InputStream inputStream) throws IOException, JSONException
|
||||
{
|
||||
String passJSONString = null;
|
||||
|
||||
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
|
||||
|
||||
ZipEntry entry;
|
||||
|
||||
// We first want to parse the translations
|
||||
while ((entry = zipInputStream.getNextEntry()) != null) {
|
||||
if (!entry.getName().equals("pass.json")) {
|
||||
continue;
|
||||
if (entry.getName().endsWith("pass.strings"))
|
||||
{
|
||||
// Example: en.lproj/pass.strings
|
||||
String language = entry.getName().substring(0, entry.getName().indexOf("."));
|
||||
|
||||
parseTranslations(language, readZipInputStream(zipInputStream));
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int c = zipInputStream.read(); c != -1; c = zipInputStream.read()) {
|
||||
sb.append((char) c);
|
||||
else if (entry.getName().equals("pass.json"))
|
||||
{
|
||||
passJSONString = readZipInputStream(zipInputStream);
|
||||
}
|
||||
|
||||
String readData = sb.toString();
|
||||
|
||||
return fromPassJSON(new JSONObject(readData));
|
||||
}
|
||||
|
||||
return null;
|
||||
if(passJSONString == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return fromPassJSON(new JSONObject(passJSONString));
|
||||
}
|
||||
|
||||
public LoyaltyCard fromPassJSON(JSONObject json) throws JSONException {
|
||||
|
||||
public LoyaltyCard fromPassJSON(JSONObject json) throws JSONException
|
||||
{
|
||||
String store = json.getString("organizationName");
|
||||
String note = json.getString("description");
|
||||
|
||||
@@ -202,12 +283,12 @@ public class PkpassImporter {
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/LowerLevel.html#//apple_ref/doc/uid/TP40012026-CH3-SW14
|
||||
JSONObject extras = new JSONObject();
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "headerFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "primaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "secondaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "auxiliaryFields");
|
||||
appendFieldDictionaryValues(extras, json, styleKey, "backFields");
|
||||
ExtrasHelper extras = new ExtrasHelper();
|
||||
extras = appendData(extras, json, styleKey, "headerFields");
|
||||
extras = appendData(extras, json, styleKey, "primaryFields");
|
||||
extras = appendData(extras, json, styleKey, "secondaryField");
|
||||
extras = appendData(extras, json, styleKey, "auxiliaryFields");
|
||||
extras = appendData(extras, json, styleKey, "backFields");
|
||||
|
||||
return new LoyaltyCard(-1, store, note, cardId, barcodeType, headerColor, headerTextColor, extras);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<string name="noCardExistsError">Could not lookup loyalty card</string>
|
||||
<string name="failedParsingImportUriError">Could not parse the import Uri</string>
|
||||
<string name="failedShowingExtras">Could not show extra information: data not correctly formatted</string>
|
||||
<string name="failedSavingCard">Could not save card</string>
|
||||
|
||||
<string name="cardIdFormat">%1$s: %2$s</string>
|
||||
<string name="storeNameAndNoteFormat" translatable="false">%1$s - %2$s</string>
|
||||
|
||||
@@ -30,19 +30,20 @@ public class DatabaseTest
|
||||
|
||||
private static final Integer DEFAULT_HEADER_COLOR = Color.BLACK;
|
||||
private static final Integer DEFAULT_HEADER_TEXT_COLOR = Color.WHITE;
|
||||
private static JSONObject DEFAULT_EXTRAS;
|
||||
private static ExtrasHelper DEFAULT_EXTRAS;
|
||||
|
||||
@Before
|
||||
public void setUp() throws JSONException
|
||||
{
|
||||
DEFAULT_EXTRAS = new JSONObject("{\"testkey\": \"testvalue\"}");
|
||||
DEFAULT_EXTRAS = new ExtrasHelper();
|
||||
DEFAULT_EXTRAS.addLanguageValue("en", "key", "value");
|
||||
|
||||
Activity activity = Robolectric.setupActivity(MainActivity.class);
|
||||
db = new DBHelper(activity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRemoveOneGiftCard()
|
||||
public void addRemoveOneGiftCard() throws JSONException
|
||||
{
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, DEFAULT_EXTRAS);
|
||||
@@ -64,7 +65,7 @@ public class DatabaseTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateGiftCard()
|
||||
public void updateGiftCard() throws JSONException
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR, DEFAULT_EXTRAS);
|
||||
boolean result = (id != -1);
|
||||
@@ -85,7 +86,7 @@ public class DatabaseTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateMissingGiftCard()
|
||||
public void updateMissingGiftCard() throws JSONException
|
||||
{
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -96,9 +97,9 @@ public class DatabaseTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyGiftCardValues()
|
||||
public void emptyGiftCardValues() throws JSONException
|
||||
{
|
||||
long id = db.insertLoyaltyCard("", "", "", "", null, null, new JSONObject());
|
||||
long id = db.insertLoyaltyCard("", "", "", "", null, null, new ExtrasHelper());
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -122,7 +123,7 @@ public class DatabaseTest
|
||||
for(int index = CARDS_TO_ADD-1; index >= 0; index--)
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
|
||||
BarcodeFormat.UPC_A.toString(), index, index*2, new JSONObject("{\"testkey" + index + "\":\"testvalue" + index + "\"}"));
|
||||
BarcodeFormat.UPC_A.toString(), index, index*2, DEFAULT_EXTRAS);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
@@ -145,7 +146,7 @@ public class DatabaseTest
|
||||
assertEquals(BarcodeFormat.UPC_A.toString(), cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE)));
|
||||
assertEquals(index, cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR)));
|
||||
assertEquals(index*2, cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR)));
|
||||
assertEquals("{\"testkey" + index + "\":\"testvalue" + index + "\"}", cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.EXTRAS)));
|
||||
assertEquals("{\"en\": {\"key\": \"value\"}}", cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.EXTRAS)));
|
||||
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
@@ -45,12 +45,13 @@ public class ImportExportTest
|
||||
|
||||
private final String BARCODE_DATA = "428311627547";
|
||||
private final String BARCODE_TYPE = BarcodeFormat.UPC_A.name();
|
||||
private JSONObject EXTRAS;
|
||||
private ExtrasHelper EXTRAS;
|
||||
|
||||
@Before
|
||||
public void setUp() throws JSONException
|
||||
{
|
||||
EXTRAS = new JSONObject("{\"key1\": \"value1\"}");
|
||||
EXTRAS = new ExtrasHelper();
|
||||
EXTRAS.addLanguageValue("en", "key", "value");
|
||||
|
||||
activity = Robolectric.setupActivity(MainActivity.class);
|
||||
db = new DBHelper(activity);
|
||||
@@ -66,7 +67,7 @@ public class ImportExportTest
|
||||
* an index in the store name.
|
||||
* @param cardsToAdd
|
||||
*/
|
||||
private void addLoyaltyCards(int cardsToAdd)
|
||||
private void addLoyaltyCards(int cardsToAdd) throws JSONException
|
||||
{
|
||||
// Add in reverse order to test sorting
|
||||
for(int index = cardsToAdd; index > 0; index--)
|
||||
@@ -124,7 +125,7 @@ public class ImportExportTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleCardsExportImport() throws IOException
|
||||
public void multipleCardsExportImport() throws IOException, JSONException
|
||||
{
|
||||
final int NUM_CARDS = 10;
|
||||
|
||||
@@ -159,7 +160,7 @@ public class ImportExportTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importExistingCardsNotReplace() throws IOException
|
||||
public void importExistingCardsNotReplace() throws IOException, JSONException
|
||||
{
|
||||
final int NUM_CARDS = 10;
|
||||
|
||||
@@ -192,7 +193,7 @@ public class ImportExportTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void corruptedImportNothingSaved() throws IOException
|
||||
public void corruptedImportNothingSaved() throws IOException, JSONException
|
||||
{
|
||||
final int NUM_CARDS = 10;
|
||||
|
||||
@@ -237,7 +238,7 @@ public class ImportExportTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useImportExportTask() throws FileNotFoundException
|
||||
public void useImportExportTask() throws FileNotFoundException, JSONException
|
||||
{
|
||||
final int NUM_CARDS = 10;
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ public class ImportURITest {
|
||||
public void ensureNoDataLoss() throws InvalidObjectException, JSONException
|
||||
{
|
||||
// Generate card
|
||||
db.insertLoyaltyCard("store", "note", BarcodeFormat.UPC_A.toString(), LoyaltyCardDbIds.BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject("{\"key\": \"value\"}"));
|
||||
ExtrasHelper extrasHelper = new ExtrasHelper();
|
||||
extrasHelper.addLanguageValue("en", "key", "value");
|
||||
db.insertLoyaltyCard("store", "note", BarcodeFormat.UPC_A.toString(), LoyaltyCardDbIds.BARCODE_TYPE, Color.BLACK, Color.WHITE, extrasHelper);
|
||||
|
||||
// Get card
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -82,9 +83,9 @@ public class LoyaltyCardCursorAdapterTest
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCursorAdapterEmptyNote()
|
||||
public void TestCursorAdapterEmptyNote() throws JSONException
|
||||
{
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -96,9 +97,9 @@ public class LoyaltyCardCursorAdapterTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCursorAdapterWithNote()
|
||||
public void TestCursorAdapterWithNote() throws JSONException
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -110,9 +111,9 @@ public class LoyaltyCardCursorAdapterTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCursorAdapterFontSizes()
|
||||
public void TestCursorAdapterFontSizes() throws JSONException
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
|
||||
@@ -358,13 +358,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithLoyaltyCardEditModeCheckDisplay() throws IOException
|
||||
public void startWithLoyaltyCardEditModeCheckDisplay() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -374,13 +374,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithLoyaltyCardViewModeCheckDisplay() throws IOException
|
||||
public void startWithLoyaltyCardViewModeCheckDisplay() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -390,13 +390,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithLoyaltyCardWithBarcodeUpdateBarcode() throws IOException
|
||||
public void startWithLoyaltyCardWithBarcodeUpdateBarcode() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -411,13 +411,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithLoyaltyCardWithReceiptUpdateReceiptCancel() throws IOException
|
||||
public void startWithLoyaltyCardWithReceiptUpdateReceiptCancel() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -437,13 +437,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMenu() throws IOException
|
||||
public void checkMenu() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -482,13 +482,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithoutParametersViewBack()
|
||||
public void startWithoutParametersViewBack() throws JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -500,13 +500,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithoutColors()
|
||||
public void startWithoutColors() throws JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -518,13 +518,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startLoyaltyCardWithoutColorsSave() throws IOException
|
||||
public void startLoyaltyCardWithoutColorsSave() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -535,13 +535,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startCheckFontSizes()
|
||||
public void startCheckFontSizes() throws JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
final int STORE_FONT_SIZE = 50;
|
||||
final int CARD_FONT_SIZE = 40;
|
||||
@@ -575,7 +575,7 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkScreenOrientationLockSetting()
|
||||
public void checkScreenOrientationLockSetting() throws JSONException
|
||||
{
|
||||
for(boolean locked : new boolean[] {false, true})
|
||||
{
|
||||
@@ -583,7 +583,7 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
settings.edit()
|
||||
@@ -612,13 +612,13 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMoreInfoNoExtras()
|
||||
public void checkMoreInfoNoExtras() throws JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.resume();
|
||||
@@ -637,7 +637,10 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, new JSONObject("{\"key\": \"value\"}"));
|
||||
ExtrasHelper extrasHelper = new ExtrasHelper();
|
||||
extrasHelper.addLanguageValue("en", "key", "value");
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, extrasHelper);
|
||||
|
||||
activityController.start();
|
||||
activityController.resume();
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -95,7 +96,7 @@ public class MainActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addOneLoyaltyCard()
|
||||
public void addOneLoyaltyCard() throws JSONException
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();
|
||||
|
||||
@@ -110,7 +111,7 @@ public class MainActivityTest
|
||||
assertEquals(0, list.getCount());
|
||||
|
||||
DBHelper db = new DBHelper(mainActivity);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
assertEquals(View.VISIBLE, helpText.getVisibility());
|
||||
assertEquals(View.GONE, noMatchingCardsText.getVisibility());
|
||||
@@ -129,7 +130,7 @@ public class MainActivityTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFiltering()
|
||||
public void testFiltering() throws JSONException
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();
|
||||
|
||||
@@ -142,8 +143,8 @@ public class MainActivityTest
|
||||
ListView list = mainActivity.findViewById(R.id.list);
|
||||
|
||||
DBHelper db = new DBHelper(mainActivity);
|
||||
db.insertLoyaltyCard("The First Store", "Initial note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("The Second Store", "Secondary note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new JSONObject());
|
||||
db.insertLoyaltyCard("The First Store", "Initial note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
db.insertLoyaltyCard("The Second Store", "Secondary note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE, new ExtrasHelper());
|
||||
|
||||
activityController.pause();
|
||||
activityController.resume();
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -53,39 +54,46 @@ public class PkpassTest {
|
||||
assertEquals(String.valueOf(Color.rgb(255, 255, 255)), card.headerTextColor.toString());
|
||||
|
||||
// Check if all the extras got parsed correctly
|
||||
JSONObject extras = card.extras;
|
||||
assertEquals(7, extras.length());
|
||||
ExtrasHelper extras = card.extras;
|
||||
assertEquals(7, extras.getAllValues("en").keySet().size());
|
||||
|
||||
// Check all 7 values
|
||||
Iterator<String> extrasKeys = extras.keys();
|
||||
Iterator<Map.Entry<String, String>> extrasKeys = extras.getAllValues("en").entrySet().iterator();
|
||||
|
||||
// 1
|
||||
assertEquals("staffNumber", extrasKeys.next());
|
||||
assertEquals("001", extras.get("staffNumber"));
|
||||
Map.Entry<String, String> entry = extrasKeys.next();
|
||||
assertEquals("staffNumber", entry.getKey());
|
||||
assertEquals("001", entry.getValue());
|
||||
|
||||
// 2
|
||||
assertEquals("staffName", extrasKeys.next());
|
||||
assertEquals("Peter Brooke", extras.get("staffName"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("staffName", entry.getKey());
|
||||
assertEquals("Peter Brooke", entry.getValue());
|
||||
|
||||
// 3
|
||||
assertEquals("telephoneExt", extrasKeys.next());
|
||||
assertEquals("9779", extras.get("telephoneExt"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("telephoneExt", entry.getKey());
|
||||
assertEquals("9779", entry.getValue());
|
||||
|
||||
// 4
|
||||
assertEquals("jobTitle", extrasKeys.next());
|
||||
assertEquals("Chief Pass Creator", extras.get("jobTitle"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("jobTitle", entry.getKey());
|
||||
assertEquals("Chief Pass Creator", entry.getValue());
|
||||
|
||||
// 5
|
||||
assertEquals("expiryDate", extrasKeys.next());
|
||||
assertEquals("2013-12-31T00:00-23:59", extras.get("expiryDate"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("expiryDate", entry.getKey());
|
||||
assertEquals("2013-12-31T00:00-23:59", entry.getValue());
|
||||
|
||||
// 6
|
||||
assertEquals("managersName", extrasKeys.next());
|
||||
assertEquals("Paul Bailey", extras.get("managersName"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("managersName", entry.getKey());
|
||||
assertEquals("Paul Bailey", entry.getValue());
|
||||
|
||||
// 7
|
||||
assertEquals("managersExt", extrasKeys.next());
|
||||
assertEquals("9673", extras.get("managersExt"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("managersExt", entry.getKey());
|
||||
assertEquals("9673", entry.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,82 +115,100 @@ public class PkpassTest {
|
||||
assertEquals(String.valueOf(Color.parseColor("#AA0061")), card.headerTextColor.toString());
|
||||
|
||||
// Check if all the extras got parsed correctly
|
||||
JSONObject extras = card.extras;
|
||||
assertEquals(18, extras.length());
|
||||
ExtrasHelper extras = card.extras;
|
||||
assertEquals(18, extras.getAllValues("en").size());
|
||||
|
||||
// Check all 18 values
|
||||
Iterator<String> extrasKeys = extras.keys();
|
||||
Iterator<Map.Entry<String, String>> extrasKeys = extras.getAllValues("en").entrySet().iterator();
|
||||
|
||||
// 1
|
||||
assertEquals("gate", extrasKeys.next());
|
||||
assertEquals("B61", extras.get("gate"));
|
||||
Map.Entry<String, String> entry = extrasKeys.next();
|
||||
assertEquals("gate", entry.getKey());
|
||||
assertEquals("B61", entry.getValue());
|
||||
|
||||
// 2
|
||||
assertEquals("seat", extrasKeys.next());
|
||||
assertEquals("16E", extras.get("seat"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("seat", entry.getKey());
|
||||
assertEquals("16E", entry.getValue());
|
||||
|
||||
// 3
|
||||
assertEquals("origin", extrasKeys.next());
|
||||
assertEquals("CGN", extras.get("origin"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("origin", entry.getKey());
|
||||
assertEquals("CGN", entry.getValue());
|
||||
|
||||
// 4
|
||||
assertEquals("destination", extrasKeys.next());
|
||||
assertEquals("DBV", extras.get("destination"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("destination", entry.getKey());
|
||||
assertEquals("DBV", entry.getValue());
|
||||
|
||||
// 5
|
||||
assertEquals("name", extrasKeys.next());
|
||||
assertEquals("John Doe", extras.get("name"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("name", entry.getKey());
|
||||
assertEquals("John Doe", entry.getValue());
|
||||
|
||||
// 6
|
||||
assertEquals("status", extrasKeys.next());
|
||||
assertEquals("-", extras.get("status"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("status", entry.getKey());
|
||||
assertEquals("-", entry.getValue());
|
||||
|
||||
// 7
|
||||
assertEquals("boardinggroup", extrasKeys.next());
|
||||
assertEquals("GROUP 1", extras.get("boardinggroup"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("boardinggroup", entry.getKey());
|
||||
assertEquals("GROUP 1", entry.getValue());
|
||||
|
||||
// 8
|
||||
assertEquals("tarif", extrasKeys.next());
|
||||
assertEquals("SMART", extras.get("tarif"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("tarif", entry.getKey());
|
||||
assertEquals("SMART", entry.getValue());
|
||||
|
||||
// 9
|
||||
assertEquals("flightNumber", extrasKeys.next());
|
||||
assertEquals("EW 954", extras.get("flightNumber"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("flightNumber", entry.getKey());
|
||||
assertEquals("EW 954", entry.getValue());
|
||||
|
||||
// 10
|
||||
assertEquals("departureDate", extrasKeys.next());
|
||||
assertEquals("08/09/2019", extras.get("departureDate"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("departureDate", entry.getKey());
|
||||
assertEquals("08/09/2019", entry.getValue());
|
||||
|
||||
// 11
|
||||
assertEquals("boarding", extrasKeys.next());
|
||||
assertEquals("05:00", extras.get("boarding"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("boarding", entry.getKey());
|
||||
assertEquals("05:00", entry.getValue());
|
||||
|
||||
// 12
|
||||
assertEquals("closure", extrasKeys.next());
|
||||
assertEquals("05:15", extras.get("closure"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("closure", entry.getKey());
|
||||
assertEquals("05:15", entry.getValue());
|
||||
|
||||
// 13
|
||||
assertEquals("info", extrasKeys.next());
|
||||
assertEquals("info_content_str", extras.get("info"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("info", entry.getKey());
|
||||
assertEquals("info_content_str", entry.getValue());
|
||||
|
||||
// 14
|
||||
assertEquals("recordlocator", extrasKeys.next());
|
||||
assertEquals("JBZPPP", extras.get("recordlocator"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("recordlocator", entry.getKey());
|
||||
assertEquals("JBZPPP", entry.getValue());
|
||||
|
||||
// 15
|
||||
assertEquals("sequence", extrasKeys.next());
|
||||
assertEquals("73", extras.get("sequence"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("sequence", entry.getKey());
|
||||
assertEquals("73", entry.getValue());
|
||||
|
||||
// 16
|
||||
assertEquals("notice", extrasKeys.next());
|
||||
assertEquals("notice_content_str", extras.get("notice"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("notice", entry.getKey());
|
||||
assertEquals("notice_content_str", entry.getValue());
|
||||
|
||||
// 17
|
||||
assertEquals("baggage", extrasKeys.next());
|
||||
assertEquals("baggage_content_str", extras.get("baggage"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("baggage", entry.getKey());
|
||||
assertEquals("baggage_content_str", entry.getValue());
|
||||
|
||||
// 18
|
||||
assertEquals("contact", extrasKeys.next());
|
||||
assertEquals("contact_content_str", extras.get("contact"));
|
||||
entry = extrasKeys.next();
|
||||
assertEquals("contact", entry.getKey());
|
||||
assertEquals("contact_content_str", entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user