always reset singleton if running a unit test

This commit is contained in:
Vincent Breitmoser
2018-07-04 22:09:52 +02:00
parent 51551eb0c7
commit 5b4f6cebf7
2 changed files with 12 additions and 5 deletions

View File

@@ -37,6 +37,8 @@ public final class Constants {
public static final boolean DEBUG_SYNC_REMOVE_CONTACTS = false;
public static final boolean DEBUG_KEYSERVER_SYNC = false;
public static final boolean IS_RUNNING_UNITTEST = isRunningUnitTest();
public static final String TAG = DEBUG ? "Keychain D" : "Keychain";
public static final String PACKAGE_NAME = "org.sufficientlysecure.keychain";
@@ -211,4 +213,12 @@ public final class Constants {
public static final KeyFormat SECURITY_TOKEN_V2_DEC = new RSAKeyFormat(2048, ELEN, RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS);
public static final KeyFormat SECURITY_TOKEN_V2_AUTH = new RSAKeyFormat(2048, ELEN, RSAKeyFormat.RSAAlgorithmFormat.CRT_WITH_MODULUS);
private static boolean isRunningUnitTest() {
try {
Class.forName("org.sufficientlysecure.keychain.KeychainTestRunner");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

View File

@@ -58,15 +58,12 @@ public class KeychainDatabase {
private static KeychainDatabase sInstance;
public static KeychainDatabase getInstance(Context context) {
if (sInstance == null || Constants.IS_RUNNING_UNITTEST) {
sInstance = new KeychainDatabase(context.getApplicationContext());
}
return sInstance;
}
@VisibleForTesting
public static void resetSingleton() {
sInstance = null;
}
public interface Tables {
String KEY_RINGS_PUBLIC = "keyrings_public";
String KEYS = "keys";