sjwall / MaterialTapTargetPrompt

⛔️ DEPRECATED Material Design tap target for Android. https://sjwall.github.io/MaterialTapTargetPrompt/
Apache License 2.0
1.52k stars 211 forks source link

Creating MaterialTapTargetPrompt in AndroidX fragment scenario tests fail #175

Closed alixwar closed 2 years ago

alixwar commented 4 years ago

Describe the bug Seems related to: https://github.com/sjwall/MaterialTapTargetPrompt/issues/137 which is allegedly fixed.

To Reproduce Some code where MaterialTapTarget is instantiated in OnViewCreated():

    private fun initTapTarget() {
        val tapTargetPromptBuilder = MaterialTapTargetPrompt.Builder(this)
                .setClipToView(null)
                .setBackgroundColour(ContextCompat.getColor(requireContext(),
                        android.R.color.black))
                .setTarget(R.id.floatingActionButton_fragmentFoo)
                .setPrimaryText(R.string.fooText)
        tapTargetPrompt = if (tapTargetPromptBuilder.isTargetSet) {
            tapTargetPromptBuilder.create()!!
        } else {
            throw IllegalStateException("Tap target not set! The app will now crash...")
        }
    }

and of course a fragment with a floating action button...

Write a test:

@Config(sdk = [Build.VERSION_CODES.LOLLIPOP])
@RunWith(AndroidJUnit4::class)
class FooTest {

    @Test
    fun `cant initialize material tap target`() {
       FragmentScenario.launch(BlePdListFragment::class.java, Bundle(), R.style.Theme_AppCompat, null)
    }

}

Expected behavior An instance of MaterialTapTargetPrompt is created

Screenshots N/A

Stack trace

java.lang.NullPointerException
    at uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.<init>(MaterialTapTargetPrompt.java:224)
    at uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.createDefault(MaterialTapTargetPrompt.java:719)
    at uk.co.samuelwall.materialtaptargetprompt.extras.PromptOptions.create(PromptOptions.java:1498)
    at com.assaabloy.stg.cliq.go.android.main.pds.BlePdListFragment.initTapTarget(BlePdListFragment.kt:107)
    at com.assaabloy.stg.cliq.go.android.main.pds.BlePdListFragment.onViewCreated(BlePdListFragment.kt:65)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:332)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
    at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
    at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2181)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2004)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959)
    at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1830)
    at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:297)
    at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:317)
    at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:301)
    at androidx.test.core.app.ActivityScenario.lambda$onActivity$2$ActivityScenario(ActivityScenario.java:551)
    at androidx.test.core.app.ActivityScenario$$Lambda$4.run(Unknown Source)
    at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:561)
    at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:300)
    at androidx.fragment.app.testing.FragmentScenario.launch(FragmentScenario.java:213)
    at com.assaabloy.stg.cliq.go.android.main.pds.BlePdListFragmentTest.setUp(BlePdListFragmentTest.kt:55)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:256)
    at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Smartphone (please complete the following information): N/A

Additional context MaterialTapTarget version: 3.0.0 Android Gradle Plugin version: 4.0.1 compileSdk: 29 targetSdk: 29