1

我有一个 ListView,它的元素是懒惰地获取的(当你滚动到列表中的最后一个元素时,会触发一个新的获取,完成后,新元素会添加到列表的末尾)。我的 ListView 适配器由一个Product对象支持:

public class Product {
    private String name;

    public String getName() {
      return name;
    }
}

例如,具有给定名称的元素位于第 25 位。我怎样才能实现这种滚动列表的行为,直到该项目在适配器中可用,以便我可以使用:onData(Matcher<Object> dataMatcher)安全?因为现在,使用时onData( ... )出现以下异常:

android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:70)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at android.support.test.espresso.DataInteraction.load(DataInteraction.java:151)
at android.support.test.espresso.DataInteraction.perform(DataInteraction.java:128)
at com.example.main.MainPageTest.testLazyList(MainPageTest.java:69)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:257)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:228)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1873)
Caused by: java.lang.RuntimeException: No data found matching: Product with name: "sdasd" contained values: <[Data: Product{name='Sony PlayStation 4 500GB'} (class: com.example.Product) token: 0, Data: Product{name='Samsung UE48H6400'} (class: com.example.Product) token: 1, Data: Product{name='Grand Theft Auto V (Gra PC)'} (class: com.example.Product) token: 2, Data: Product{name='Samsung UE55H6400'} (class: com.example.Product) token: 3, Data: Product{name='Zelmer Aquawelt 919.0 ST'} (class: com.example.Product) token: 4, Data: Product{name='Panasonic TX-47AS650E'} (class: com.example.Product) token: 5, Data: Product{name='LG 42LB650V'} (class: com.example.Product) token: 6, Data: Product{name='Samsung UE40H6400'} (class: com.example.Product) token: 7, Data: Product{name='Panasonic TX-48AS640E'} (class: com.example.Product) token: 8, Data: Product{name='Panasonic TX-42AS650E'} (class: com.example.Product) token: 9, Data: Product{name='Samsung UE50H6400'} (class: com.example.Product) token: 10, Data: Product{name='Zelmer ZVC425HT'} (class: com.example.Product) token: 11, Data: Product{name='Calvin Klein Euphoria Woman Woda perfumowana 100 ml spray'} (class: com.example.Product) token: 12, Data: Product{name='Sony KDL-50W829B'} (class: com.example.Product) token: 13, Data: Product{name='Samsung UE40H6200'} (class: com.example.Product) token: 14, Data: Product{name='Sony KDL-40W605B'} (class: com.example.Product) token: 15, Data: Product{name='Panasonic TX-55AS640E'} (class: com.example.Product) token: 16, Data: Product{name='LG 42LB5800'} (class: com.example.Product) token: 17]>
at android.support.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:96)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
4

0 回答 0