This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package pl.izmajlowiczl.bsj.delete_me; | |
| import android.text.format.DateUtils; | |
| import org.junit.Before; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import org.robolectric.RobolectricTestRunner; | |
| import java.util.Calendar; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| testOptions.unitTests.all { | |
| testLogging { | |
| events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' | |
| exceptionFormat 'full' | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package pl.expensive.db; | |
| import android.database.Cursor; | |
| import android.database.sqlite.SQLiteDatabase; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class DatabaseSchemaTestHelper { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface WalletsStorage { | |
| /** | |
| * List all stored {@link Wallet}s. Result is null safe | |
| * | |
| * @return Collection of all stored Wallets or Collections.emptyList() for empty result. | |
| */ | |
| Collection<Wallet> list(); | |
| /** | |
| * Stores {@link Wallet} object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void storeSingleWallet() { | |
| Wallet bankWallet = Wallet.create(randomUUID(), "bank"); | |
| storage.insert(bankWallet); | |
| assertThat(getStoredWalletNames()) | |
| .containsExactly("bank"); | |
| } | |
| private List<String> getStoredWalletNames() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void listWallets() { | |
| Wallet bankWallet = Wallet.create(randomUUID(), "bank"); | |
| Wallet ccWallet = Wallet.create(randomUUID(), "credit card"); | |
| db.execSQL(storeWalletSql(bankWallet)); | |
| db.execSQL(storeWalletSql(ccWallet)); | |
| assertThat(storage.list()).containsExactly(bankWallet, ccWallet); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void storeWallets() { | |
| Wallet wallet = Wallet.create(UUID.randomUUID(), "Test-Walet"); | |
| model.insert(wallet); | |
| assertThat(model.list()) | |
| .containsExactly(wallet); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test fun columnsForCategoryTable() { | |
| val columns = getTableColumns(database.readableDatabase, "tbl_category") | |
| assertThat(columns).containsExactly("uuid", "name", "color") | |
| } | |
| @Test fun createDefaultCategoriesTable() { | |
| assertThat(database.readableDatabase.doesTableExist("tbl_category")).isTrue() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun SQLiteDatabase.doesTableExist(tableName: String): Boolean { | |
| val sql = "SELECT name FROM sqlite_master WHERE type='table';" | |
| val c = rawQuery(sql, null) | |
| while (c.moveToNext()) { | |
| if (c.getString(0) == tableName) return true | |
| else continue | |
| } | |
| return false | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun SQLiteDatabase.doesTableExistIncludingTemps(tableName: String): Boolean { | |
| val sql = """SELECT name | |
| FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) | |
| WHERE type='table';""" | |
| val c = rawQuery(sql, null) | |
| while (c.moveToNext()) { | |
| if (c.getString(0) == tableName) return true else continue | |
| } |