mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-02 23:01:58 -04:00
Memory leak and spotBugs fixes
This commit is contained in:
@@ -170,6 +170,8 @@ public class DatabaseTest
|
||||
}
|
||||
|
||||
assertTrue(cursor.isAfterLast());
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,6 +229,8 @@ public class DatabaseTest
|
||||
}
|
||||
|
||||
assertTrue(cursor.isAfterLast());
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
private void setupDatabaseVersion1(SQLiteDatabase database)
|
||||
|
||||
@@ -224,6 +224,8 @@ public class ImportExportTest
|
||||
{
|
||||
SQLiteDatabase database = db.getWritableDatabase();
|
||||
database.execSQL("delete from " + DBHelper.LoyaltyCardDbIds.TABLE);
|
||||
database.execSQL("delete from " + DBHelper.LoyaltyCardDbGroups.TABLE);
|
||||
database.execSQL("delete from " + DBHelper.LoyaltyCardDbIdsGroups.TABLE);
|
||||
database.close();
|
||||
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
@@ -454,6 +456,8 @@ public class ImportExportTest
|
||||
assertEquals(false, result);
|
||||
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,6 +553,8 @@ public class ImportExportTest
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertEquals(0, card.starStatus);
|
||||
assertNull(card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -582,6 +588,8 @@ public class ImportExportTest
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertEquals(0, card.starStatus);
|
||||
assertNull(card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -606,6 +614,8 @@ public class ImportExportTest
|
||||
boolean result = MultiFormatImporter.importData(db, inStream, DataFormat.CSV);
|
||||
assertEquals(false, result);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -639,6 +649,8 @@ public class ImportExportTest
|
||||
assertEquals("", card.barcodeType);
|
||||
assertEquals(0, card.starStatus);
|
||||
assertEquals(1, (long) card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -672,10 +684,10 @@ public class ImportExportTest
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertEquals(1, card.starStatus);
|
||||
assertEquals(1, (long) card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void importWithNoStarredFieldV1() throws IOException
|
||||
{
|
||||
@@ -707,6 +719,8 @@ public class ImportExportTest
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertEquals(0, card.starStatus);
|
||||
assertEquals(1, (long) card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -760,5 +774,7 @@ public class ImportExportTest
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertEquals(0, card.starStatus);
|
||||
assertEquals(1, (long) card.headerColor);
|
||||
|
||||
clearDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ public class LoyaltyCardCursorAdapterTest
|
||||
View view = createView(cursor);
|
||||
|
||||
checkView(view, card.store, card.note, false);
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,6 +109,8 @@ public class LoyaltyCardCursorAdapterTest
|
||||
View view = createView(cursor);
|
||||
|
||||
checkView(view, card.store, card.note, false);
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,6 +129,8 @@ public class LoyaltyCardCursorAdapterTest
|
||||
setFontSizes(30, 31);
|
||||
view = createView(cursor);
|
||||
checkView(view, card.store, card.note, true);
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,7 +140,6 @@ public class LoyaltyCardCursorAdapterTest
|
||||
db.insertLoyaltyCard("storeB", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, 1);
|
||||
db.insertLoyaltyCard("storeC", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, 1);
|
||||
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
cursor.moveToFirst();
|
||||
View view = createView(cursor);
|
||||
@@ -150,5 +155,7 @@ public class LoyaltyCardCursorAdapterTest
|
||||
view = createView(cursor);
|
||||
star = view.findViewById(R.id.star);
|
||||
assertEquals(View.GONE, star.getVisibility());
|
||||
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,8 @@ public class LoyaltyCardViewActivityTest
|
||||
}
|
||||
assertNotNull(card.headerColor);
|
||||
assertNotNull(card.headerTextColor);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,6 +289,8 @@ public class LoyaltyCardViewActivityTest
|
||||
noteField.setText("note");
|
||||
activity.findViewById(R.id.fabSave).performClick();
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -416,6 +420,8 @@ public class LoyaltyCardViewActivityTest
|
||||
activityController.resume();
|
||||
|
||||
checkAllFields(activity, ViewMode.UPDATE_CARD, "store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -432,6 +438,8 @@ public class LoyaltyCardViewActivityTest
|
||||
activityController.resume();
|
||||
|
||||
checkAllFields(activity, ViewMode.VIEW_CARD, "store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -453,6 +461,8 @@ public class LoyaltyCardViewActivityTest
|
||||
captureBarcodeWithResult(activity, true);
|
||||
|
||||
checkAllFields(activity, ViewMode.UPDATE_CARD, "store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -488,6 +498,8 @@ public class LoyaltyCardViewActivityTest
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(false, activity.hasChanged);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -512,6 +524,8 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals("Block Rotation", menu.findItem(R.id.action_lock_unlock).getTitle().toString());
|
||||
assertEquals("Share", menu.findItem(R.id.action_share).getTitle().toString());
|
||||
assertEquals("Add to favorites", menu.findItem(R.id.action_star_unstar).getTitle().toString());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -550,6 +564,8 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals(false, activity.isFinishing());
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -568,6 +584,8 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals(false, activity.isFinishing());
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -585,6 +603,8 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
// Save and check the loyalty card
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, BARCODE_TYPE, false);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -602,6 +622,8 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
// Save and check the loyalty card
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, activity.getApplicationContext().getString(R.string.noBarcode), false);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -629,6 +651,8 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
// Check if the special NO_BARCODE string doesn't get saved
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, activity.getApplicationContext().getString(R.string.noBarcode), false);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -665,6 +689,8 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -701,6 +727,8 @@ public class LoyaltyCardViewActivityTest
|
||||
String title = item.getTitle().toString();
|
||||
assertEquals(title, activity.getString(R.string.lockScreen));
|
||||
}
|
||||
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,6 +759,8 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
shadowOf(activity).clickMenuItem(R.id.action_star_unstar);
|
||||
assertEquals("Add to favorites", menu.findItem(R.id.action_star_unstar).getTitle().toString());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -794,6 +824,8 @@ public class LoyaltyCardViewActivityTest
|
||||
// Pressing back when not in full screen should finish activity
|
||||
activity.onBackPressed();
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -111,6 +111,8 @@ public class MainActivityTest
|
||||
assertEquals(1, list.getAdapter().getCount());
|
||||
Cursor cursor = (Cursor)list.getAdapter().getItem(0);
|
||||
assertNotNull(cursor);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,6 +163,8 @@ public class MainActivityTest
|
||||
cursor = (Cursor)list.getAdapter().getItem(3);
|
||||
assertNotNull(cursor);
|
||||
assertEquals("storeB",cursor.getString(cursor.getColumnIndex("store")));
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,6 +213,8 @@ public class MainActivityTest
|
||||
activityController.pause();
|
||||
activityController.resume();
|
||||
assertEquals(0, groupTabs.getTabCount());
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -434,5 +440,7 @@ public class MainActivityTest
|
||||
assertEquals(View.VISIBLE, list.getVisibility());
|
||||
|
||||
assertEquals(2, list.getCount());
|
||||
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user