diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-27 21:40:25 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-27 21:40:25 +0300 |
commit | 3f0f1f0b951bf488bc56acb41e6af7c2ddb699f6 (patch) | |
tree | 5f7a4ab40f64818f3fec818158a0778de1b04e43 /app/src/test/java/it/niedermann/nextcloud/deck | |
parent | fcc0b5bff1754b2f87f9707cedf93c3c3e1bb0dc (diff) |
Mock doAsync() method
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.java | 18 |
1 files changed, 16 insertions, 2 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 c0ac2a96b..975053989 100644 --- a/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java +++ b/app/src/test/java/it/niedermann/nextcloud/deck/SyncManagerTest.java @@ -6,12 +6,15 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; @@ -25,7 +28,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@RunWith(PowerMockRunner.class) +@PrepareForTest({SyncManager.class}) public class SyncManagerTest { @Rule @@ -41,6 +45,16 @@ public class SyncManagerTest { @InjectMocks private SyncManager syncManager; + @Before + public void prepareDoAsync() { + PowerMockito + .replace(PowerMockito.method(SyncManager.class, "doAsync", Runnable.class)) + .with((obj, method, arguments) -> { + ((Runnable) arguments[0]).run(); + return null; + }); + } + @Test public void testHasAccounts() throws InterruptedException { when(dataBaseAdapter.hasAccounts()).thenReturn(new MutableLiveData<>(true)); |