From 1f1fc94d2227eade0bfaa493eb605aecf02a6ec0 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Tue, 18 Aug 2020 11:57:35 -0300 Subject: [PATCH] Fix flakey robolectric test. --- app/build.gradle | 20 ++++++++++++++----- ...rchivedConversationListDataSourceTest.java | 17 +++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b50d6a303..4d16bc9d8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -358,11 +358,11 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.assertj:assertj-core:3.11.1' - testImplementation 'org.mockito:mockito-core:1.9.5' - testImplementation 'org.powermock:powermock-api-mockito:1.6.5' - testImplementation 'org.powermock:powermock-module-junit4:1.6.5' - testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.5' - testImplementation 'org.powermock:powermock-classloading-xstream:1.6.5' + testImplementation 'org.mockito:mockito-core:2.8.9' + testImplementation 'org.powermock:powermock-api-mockito2:1.7.4' + testImplementation 'org.powermock:powermock-module-junit4:1.7.4' + testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.4' + testImplementation 'org.powermock:powermock-classloading-xstream:1.7.4' testImplementation 'androidx.test:core:1.2.0' testImplementation ('org.robolectric:robolectric:4.2') { @@ -455,3 +455,13 @@ def getLastCommitTimestamp() { return os.toString() + "000" } } + +tasks.withType(Test) { + testLogging { + events "failed" + exceptionFormat "full" + showCauses true + showExceptions true + showStackTraces true + } +} diff --git a/app/src/test/java/org/thoughtcrime/securesms/conversationlist/UnarchivedConversationListDataSourceTest.java b/app/src/test/java/org/thoughtcrime/securesms/conversationlist/UnarchivedConversationListDataSourceTest.java index ad32c1ea9..669235e5b 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/conversationlist/UnarchivedConversationListDataSourceTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/conversationlist/UnarchivedConversationListDataSourceTest.java @@ -1,10 +1,10 @@ package org.thoughtcrime.securesms.conversationlist; import android.app.Application; -import android.content.ContentResolver; -import android.content.Context; import android.database.Cursor; +import androidx.test.core.app.ApplicationProvider; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,8 +33,8 @@ import static org.powermock.api.mockito.PowerMockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE, application = Application.class) -@PowerMockIgnore({ "org.powermock.*", "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" }) -@PrepareForTest({ApplicationDependencies.class, DatabaseFactory.class, ThreadDatabase.class}) +@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" }) +@PrepareForTest({ ApplicationDependencies.class, DatabaseFactory.class }) public class UnarchivedConversationListDataSourceTest { @Rule @@ -42,21 +42,18 @@ public class UnarchivedConversationListDataSourceTest { private ConversationListDataSource.UnarchivedConversationListDataSource testSubject; - private ThreadDatabase threadDatabase; + private ThreadDatabase threadDatabase; @Before public void setUp() { mockStatic(ApplicationDependencies.class); mockStatic(DatabaseFactory.class); - final Context context = mock(Context.class); - final ContentResolver contentResolver = mock(ContentResolver.class); - threadDatabase = mock(ThreadDatabase.class); + threadDatabase = mock(ThreadDatabase.class); when(DatabaseFactory.getThreadDatabase(any())).thenReturn(threadDatabase); - when(context.getContentResolver()).thenReturn(contentResolver); - testSubject = new ConversationListDataSource.UnarchivedConversationListDataSource(context, mock(Invalidator.class)); + testSubject = new ConversationListDataSource.UnarchivedConversationListDataSource(ApplicationProvider.getApplicationContext(), mock(Invalidator.class)); } @Test