Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Theme_MaterialComponents by default in tests #5668

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class ColorPickerDialogTest {
}

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `The dialog should be dismissed after clicking on a device back button`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AudioButtonTest {

@Before
public void setup() {
Activity activity = RobolectricHelpers.createThemedActivity(FragmentActivity.class, com.google.android.material.R.style.Theme_MaterialComponents);
Activity activity = RobolectricHelpers.createThemedActivity(FragmentActivity.class);
button = new AudioButton(activity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public <T extends ViewModel> T create(@NonNull Class<T> modelClass, @NonNull Cre
};

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(com.google.android.material.R.style.Theme_MaterialComponents, new FragmentFactoryBuilder()
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(new FragmentFactoryBuilder()
.forClass(AudioRecordingControllerFragment.class, () -> new AudioRecordingControllerFragment(viewModelFactory))
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public class AudioRecordingFormErrorDialogFragmentTest {
private StubAudioRecorder audioRecorder;

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Before
public void setup() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
public class BackgroundAudioHelpDialogFragmentTest {

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Test
public void hasOkButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.odk.collect.shared.settings.Settings
class PenColorPickerDialogTest {

@get:Rule
val launcherRule = FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `dialog should be cancelable`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public <T extends ViewModel> T create(@NonNull Class<T> modelClass, @NonNull Cre

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents,
new FragmentFactoryBuilder()
.forClass(BackgroundAudioPermissionDialogFragment.class, () -> new BackgroundAudioPermissionDialogFragment(viewModelFactory))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class FormEntryMenuDelegateTest {

@Before
public void setup() {
activity = RobolectricHelpers.createThemedActivity(AppCompatActivity.class, com.google.android.material.R.style.Theme_MaterialComponents);
activity = RobolectricHelpers.createThemedActivity(AppCompatActivity.class);
FormController formController = mock(FormController.class);
answersProvider = mock(AnswersProvider.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
public class FormLoadingDialogFragmentTest {

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Test
public void dialogIsNotCancellable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
public class RefreshFormListDialogFragmentTest {

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Test
public void dialogIsNotCancellable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public <T extends ViewModel> T create(@NonNull Class<T> modelClass, @NonNull Cre

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents,
new FragmentFactoryBuilder()
.forClass(SaveFormProgressDialogFragment.class, () -> new SaveFormProgressDialogFragment(viewModelFactory))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class DeleteBlankFormFragmentTest {

@get:Rule
val fragmentScenarioLauncherRule = FragmentScenarioLauncherRule(
defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents,
defaultFactory = FragmentFactoryBuilder()
FragmentFactoryBuilder()
.forClass(DeleteBlankFormFragment::class) {
DeleteBlankFormFragment(viewModelFactory, menuHost)
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class FormsDownloadResultDialogTest {
val listener = mock<FormsDownloadResultDialog.FormDownloadResultDialogListener>()

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `The dialog should be dismissed after clicking out of it's area or on device back button`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class PermissionsDialogFragmentTest {
.build()

@get:Rule
val launcherRule = FragmentScenarioLauncherRule(
defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents,
defaultFactory = fragmentFactory
)
val launcherRule = FragmentScenarioLauncherRule(fragmentFactory)

@Test
fun clickingOK_asksForPermissions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoMoreInteractions
import org.mockito.kotlin.whenever
import org.odk.collect.android.R
import org.odk.collect.android.injection.config.AppDependencyModule
import org.odk.collect.android.preferences.ProjectPreferencesViewModel
import org.odk.collect.android.support.CollectHelpers
Expand All @@ -38,8 +37,7 @@ class AdminPasswordDialogFragmentTest {
lateinit var factory: ProjectPreferencesViewModel.Factory

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.junit.runner.RunWith
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoMoreInteractions
import org.odk.collect.android.R
import org.odk.collect.android.injection.config.AppDependencyModule
import org.odk.collect.android.preferences.ProjectPreferencesViewModel
import org.odk.collect.android.support.CollectHelpers
Expand All @@ -40,8 +39,7 @@ class ChangeAdminPasswordDialogTest {
lateinit var factory: ProjectPreferencesViewModel.Factory

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class ResetProgressDialogTest {
private val context = ApplicationProvider.getApplicationContext<Context>()

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `The dialog should not be dismissed after clicking out of its area or on device back button`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public class ServerAuthDialogFragmentTest {
private final Settings generalSettings = TestSettingsProvider.getUnprotectedSettings();

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Test
public void prefillsUsernameAndPassword() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ProjectDisplayPreferencesFragmentTest {
lateinit var projectsRepository: ProjectsRepository

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import org.robolectric.shadows.ShadowToast
class ManualProjectCreatorDialogTest {

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `Password should be protected`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.odk.collect.android.R
import org.odk.collect.android.activities.AboutActivity
import org.odk.collect.android.injection.config.AppDependencyModule
import org.odk.collect.android.mainmenu.CurrentProjectViewModel
Expand Down Expand Up @@ -61,7 +60,6 @@ class ProjectSettingsDialogTest {

@get:Rule
val launcherRule = FragmentScenarioLauncherRule(
defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents,
defaultFactory = FragmentFactoryBuilder()
.forClass(ProjectSettingsDialog::class) { ProjectSettingsDialog(viewModelFactory) }
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class QrCodeProjectCreatorDialogTest {
private val permissionsProvider = FakePermissionsProvider()

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static AppDependencyComponent overrideAppDependencyModule(AppDependencyMo
}

public static <T extends FragmentActivity> T createThemedActivity(Class<T> clazz) {
return RobolectricHelpers.createThemedActivity(clazz, com.google.android.material.R.style.Theme_MaterialComponents);
return RobolectricHelpers.createThemedActivity(clazz);
}

public static FragmentActivity createThemedActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class SelectOneFromMapDialogFragmentTest {
@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(
defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents,
FragmentFactoryBuilder()
.forClass(SelectOneFromMapDialogFragment::class.java) {
SelectOneFromMapDialogFragment(viewModelFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class DateTimeWidgetUtilsTest {
public void setUp() {
dateTimeWidgetUtils = new DateTimeWidgetUtils();

activity = RobolectricHelpers.createThemedActivity(WidgetTestActivity.class, com.google.android.material.R.style.Theme_MaterialComponents);
activity = RobolectricHelpers.createThemedActivity(WidgetTestActivity.class);
datePickerDetails = mock(DatePickerDetails.class);

when(datePickerDetails.getDatePickerType()).thenReturn(GREGORIAN);
Expand Down
1 change: 1 addition & 0 deletions fragmentstest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
dependencies {
implementation Dependencies.kotlin_stdlib
implementation Dependencies.androidx_test_espresso_core
implementation Dependencies.android_material

//noinspection FragmentGradleConfiguration
debugApi(Dependencies.androidx_fragment_testing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import org.junit.rules.ExternalResource
* scenarios in a test.
*/
class FragmentScenarioLauncherRule @JvmOverloads constructor(
@StyleRes private val defaultThemeResId: Int? = null,
private val defaultFactory: FragmentFactory? = null
private val defaultFactory: FragmentFactory? = null,
@StyleRes private val defaultThemeResId: Int = com.google.android.material.R.style.Theme_MaterialComponents
) : ExternalResource() {

private val scenarios = mutableListOf<FragmentScenario<*>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class GeoPointDialogFragmentTest {
}

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GeoPolySettingsDialogFragmentTest {

@Before
public void setup() {
FragmentActivity activity = RobolectricHelpers.createThemedActivity(FragmentActivity.class, com.google.android.material.R.style.Theme_MaterialComponents);
FragmentActivity activity = RobolectricHelpers.createThemedActivity(FragmentActivity.class);
fragmentManager = activity.getSupportFragmentManager();
dialogFragment = new GeoPolySettingsDialogFragment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class SelectionMapFragmentTest {

@get:Rule
val launcherRule = FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents,
object : FragmentFactory() {
override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
return SelectionMapFragment(data, onBackPressedDispatcher = { onBackPressedDispatcher })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class MaterialAlertDialogFragmentTest {
}

@get:Rule
val launcherRule =
FragmentScenarioLauncherRule(defaultThemeResId = com.google.android.material.R.style.Theme_MaterialComponents)
val launcherRule = FragmentScenarioLauncherRule()

@Test
fun `dialog should be cancelable`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
public class MaterialProgressDialogFragmentTest {

@Rule
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule(
com.google.android.material.R.style.Theme_MaterialComponents
);
public FragmentScenarioLauncherRule launcherRule = new FragmentScenarioLauncherRule();

@Test
public void setTitle_updatesTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PermissionsDialogCreatorTest {

@Before
fun setup() {
activity = createThemedActivity(FragmentActivity::class.java, com.google.android.material.R.style.Theme_MaterialComponents)
activity = createThemedActivity(FragmentActivity::class.java)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ object RobolectricHelpers {
var services: MutableMap<Class<*>, ServiceScenario<*>> = HashMap()

@JvmStatic
fun <T : FragmentActivity> createThemedActivity(clazz: Class<T>, theme: Int): T {
@JvmOverloads
fun <T : FragmentActivity> createThemedActivity(
clazz: Class<T>,
theme: Int = com.google.android.material.R.style.Theme_MaterialComponents
): T {
val activity = Robolectric.buildActivity(clazz)
activity.get()!!.setTheme(theme)
return activity.setup().get()
Expand Down