use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class NotesRepositoryTest method testSyncErrorsLiveData.
@Test
public void testSyncErrorsLiveData() throws InterruptedException, IOException {
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "1337", account.getUrl(), ""));
assertThrows("The very first time, this LiveData should never have been set", RuntimeException.class, () -> NotesTestingUtil.getOrAwaitValue(repo.getSyncErrors()));
repo.scheduleSync(account, true);
assertEquals("In our scenario, we expect 4 failed note syncs to be handled.", 4, getOrAwaitValue(repo.getSyncErrors()).size());
}
use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class NotesRepositoryTest method testSyncStatusLiveData.
@Test
public void testSyncStatusLiveData() throws InterruptedException, IOException {
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "1337", account.getUrl(), ""));
assertFalse(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
repo.addCallbackPull(account, () -> {
try {
assertTrue(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
} catch (InterruptedException e) {
e.printStackTrace();
fail(e.getMessage());
}
});
repo.scheduleSync(account, false);
assertFalse(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
}
use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class NotesRepositoryTest method setupDB.
@Before
public void setupDB() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException {
final var context = ApplicationProvider.getApplicationContext();
db = Room.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class).allowMainThreadQueries().build();
final var constructor = NotesRepository.class.getDeclaredConstructor(Context.class, NotesDatabase.class, ExecutorService.class, ExecutorService.class, ExecutorService.class, ApiProvider.class);
constructor.setAccessible(true);
final var executor = MoreExecutors.newDirectExecutorService();
final var apiProviderSpy = mock(ApiProvider.class);
final var notesApiSpy = mock(NotesAPI.class);
repo = constructor.newInstance(context, db, executor, executor, executor, apiProviderSpy);
doReturn(notesApiSpy).when(apiProviderSpy).getNotesAPI(any(), any(), any());
when(notesApiSpy.getNotesIDs()).thenReturn(Observable.just(Collections.emptyList()));
when(notesApiSpy.getNote(anyLong())).thenReturn(Observable.just(ParsedResponse.of(new Note())));
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount("彼得@äöüß.example.com", "彼得", "1337", "https://äöüß.example.com", ""));
repo.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities(), null, new IResponseCallback<>() {
@Override
public void onSuccess(Account result) {
}
@Override
public void onError(@NonNull Throwable t) {
fail(t.getMessage());
}
});
account = repo.getAccountByName("彼得@äöüß.example.com");
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount("test@example.org", "test", "1337", "https://example.org", ""));
repo.addAccount("https://example.org", "test", "test@example.org", new Capabilities(), "Herbert", new IResponseCallback<>() {
@Override
public void onSuccess(Account result) {
}
@Override
public void onError(@NonNull Throwable t) {
fail(t.getMessage());
}
});
secondAccount = repo.getAccountByName("test@example.org");
Arrays.stream(new Note[] { new Note(1, 1001L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, VOID, account.getId(), "", 0), new Note(2, null, Calendar.getInstance(), "T", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), new Note(3, 1003L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), new Note(4, null, Calendar.getInstance(), "T", "C", "Music", false, null, VOID, account.getId(), "", 0), new Note(5, 1005L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_EDITED, account.getId(), "", 0), new Note(6, 1006L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_DELETED, account.getId(), "", 0), new Note(7, null, Calendar.getInstance(), "T", "C", "Music", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), new Note(8, 1008L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), new Note(9, 1009L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_DELETED, secondAccount.getId(), "", 0) }).forEach(note -> db.getNoteDao().addNote(note));
}
Aggregations