Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2020-12-28 00:43:02 +0300
committerStefan Niedermann <info@niedermann.it>2020-12-28 00:43:38 +0300
commit34de0bf21e30622c1a6b752df20014e059f70014 (patch)
tree148214040ed68de1cf2368b83a837a67f78bb753 /app/src/test/java/it/niedermann/nextcloud/deck
parent99226e21adc488bdcbb8ca1179afe172ced22dd6 (diff)
Add testDeleteAccount
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/test/java/it/niedermann/nextcloud/deck')
-rw-r--r--app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java79
1 files changed, 44 insertions, 35 deletions
diff --git a/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java b/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java
index 63234b45a..7ba41e98c 100644
--- a/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java
+++ b/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java
@@ -17,6 +17,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import it.niedermann.nextcloud.deck.api.IResponseCallback;
+import it.niedermann.nextcloud.deck.api.LastSyncUtil;
import it.niedermann.nextcloud.deck.exceptions.OfflineException;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.full.FullBoard;
@@ -42,7 +43,7 @@ import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.whenNew;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({SyncManager.class, DeckLog.class})
+@PrepareForTest({SyncManager.class, DeckLog.class, LastSyncUtil.class})
public class SyncManagerTest {
@Rule
@@ -63,6 +64,7 @@ public class SyncManagerTest {
@Before
public void prepareDoAsync() {
PowerMockito.mockStatic(DeckLog.class);
+ PowerMockito.mockStatic(LastSyncUtil.class);
PowerMockito
.replace(PowerMockito.method(SyncManager.class, "doAsync", Runnable.class))
.with((obj, method, arguments) -> {
@@ -71,40 +73,6 @@ public class SyncManagerTest {
});
}
- /**
- * When {@link SyncManager#synchronizeBoard(IResponseCallback, long)} is triggered, it should
- * pass the given {@link IResponseCallback} to the {@link SyncHelper} and trigger a
- * {@link SyncHelper#doSyncFor(AbstractSyncDataProvider)}.
- * {@link OfflineException} should be caught and passed to the {@link IResponseCallback}
- */
- @Test
- public void testSynchronizeBoard() throws Exception {
- final SyncHelper syncHelper = mock(SyncHelper.class);
-
- when(dataBaseAdapter.getFullBoardByLocalIdDirectly(anyLong(), anyLong())).thenReturn(new FullBoard());
- when(syncHelper.setResponseCallback(any())).thenReturn(syncHelper);
- doNothing().when(syncHelper).doSyncFor(any());
- whenNew(SyncHelper.class).withAnyArguments().thenReturn(syncHelper);
-
- IResponseCallback<Boolean> responseCallback = spy(new IResponseCallback<Boolean>(new Account(1L)) {
- @Override
- public void onResponse(Boolean response) {
-
- }
- });
-
- syncManager.synchronizeBoard(responseCallback, 1L);
-
- verify(syncHelper, times(1)).setResponseCallback(responseCallback);
- verify(syncHelper, times(1)).doSyncFor(any(StackDataProvider.class));
-
- doThrow(OfflineException.class).when(syncHelper).doSyncFor(any());
-
- syncManager.synchronizeBoard(responseCallback, 1L);
-
- verify(responseCallback, times(1)).onError(any(OfflineException.class));
- }
-
@Test
public void testHasAccounts() throws InterruptedException {
when(dataBaseAdapter.hasAccounts()).thenReturn(new MutableLiveData<>(true));
@@ -148,4 +116,45 @@ public class SyncManagerTest {
assertNull(TestUtil.getOrAwaitValue(syncManager.readAccount("test@example.com")));
verify(dataBaseAdapter, times(1)).readAccount("test@example.com");
}
+
+ @Test
+ public void testDeleteAccount() throws InterruptedException {
+ doNothing().when(dataBaseAdapter).deleteAccount(anyLong());
+ syncManager.deleteAccount(1337L);
+ verify(dataBaseAdapter, times(1)).deleteAccount(1337L);
+ }
+
+ /**
+ * When {@link SyncManager#synchronizeBoard(IResponseCallback, long)} is triggered, it should
+ * pass the given {@link IResponseCallback} to the {@link SyncHelper} and trigger a
+ * {@link SyncHelper#doSyncFor(AbstractSyncDataProvider)}.
+ * {@link OfflineException} should be caught and passed to the {@link IResponseCallback}
+ */
+ @Test
+ public void testSynchronizeBoard() throws Exception {
+ final SyncHelper syncHelper = mock(SyncHelper.class);
+
+ when(dataBaseAdapter.getFullBoardByLocalIdDirectly(anyLong(), anyLong())).thenReturn(new FullBoard());
+ when(syncHelper.setResponseCallback(any())).thenReturn(syncHelper);
+ doNothing().when(syncHelper).doSyncFor(any());
+ whenNew(SyncHelper.class).withAnyArguments().thenReturn(syncHelper);
+
+ IResponseCallback<Boolean> responseCallback = spy(new IResponseCallback<Boolean>(new Account(1L)) {
+ @Override
+ public void onResponse(Boolean response) {
+
+ }
+ });
+
+ syncManager.synchronizeBoard(responseCallback, 1L);
+
+ verify(syncHelper, times(1)).setResponseCallback(responseCallback);
+ verify(syncHelper, times(1)).doSyncFor(any(StackDataProvider.class));
+
+ doThrow(OfflineException.class).when(syncHelper).doSyncFor(any());
+
+ syncManager.synchronizeBoard(responseCallback, 1L);
+
+ verify(responseCallback, times(1)).onError(any(OfflineException.class));
+ }
}