#1170 Fix unit tests

This commit is contained in:
Stefan Niedermann 2021-04-24 13:39:18 +02:00
parent d40f5dfa76
commit bf836f98e2
4 changed files with 45 additions and 193 deletions

View file

@ -134,21 +134,21 @@ public class NotesRepository {
public static synchronized NotesRepository getInstance(@NonNull Context context) {
if (instance == null) {
instance = new NotesRepository(context);
instance = new NotesRepository(context, NotesDatabase.getInstance(context.getApplicationContext()));
}
return instance;
}
private NotesRepository(final Context context) {
private NotesRepository(@NonNull final Context context, @NonNull final NotesDatabase db) {
this.context = context.getApplicationContext();
this.db = NotesDatabase.getInstance(this.context);
this.db = db;
this.defaultNonEmptyTitle = NoteUtil.generateNonEmptyNoteTitle("", this.context);
this.syncOnlyOnWifiKey = context.getApplicationContext().getResources().getString(R.string.pref_key_wifi_only);
// Registers BroadcastReceiver to track network connection changes.
context.getApplicationContext().registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context.getApplicationContext());
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context.getApplicationContext());
prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
syncOnlyOnWifi = prefs.getBoolean(syncOnlyOnWifiKey, false);

View file

@ -53,7 +53,7 @@ public class NotesDaoTest {
.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class)
.allowMainThreadQueries()
.build();
db.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null));
db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null)));
account = db.getAccountDao().getAccountByName("彼得@äöüß.example.com");
}
@ -410,7 +410,7 @@ public class NotesDaoTest {
}
private Account setupSecondAccount() throws NextcloudHttpRequestFailedException {
db.addAccount("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null));
db.getAccountDao().insert(new Account("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null)));
return db.getAccountDao().getAccountByName("test@example.org");
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long