3

我想测试我的班级是否在包裹中写入了正确的数据,所以我编写了以下测试:

@Test
public void parcelOutAndIn() {
    Trip trip = new Trip("id123", new Date());

    Parcel parcel = Parcel.obtain();
    trip.writeToParcel(parcel, 0);
    Trip tripResult = new Trip(parcel);

    Assert.assertThat(tripResult.getId(), equalTo(trip.getId()));
    Assert.assertThat(tripResult.getStartTime(), equalTo(trip.getStartTime()));
}

我的 writeToParcel 看起来像这样:

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(id);
    parcel.writeSerializable(startTime);
}

我有以下错误:

java.lang.NoSuchMethodError: java.util.Arrays.checkOffsetAndCount

我能做些什么?它是 Robolectric 中的错误吗?我使用 Robolectric 2.1.1。

堆栈跟踪:

java.lang.NoSuchMethodError: java.util.Arrays.checkOffsetAndCount(III)V
at android.os.Parcel.writeByteArray(Parcel.java:472)
at android.os.Parcel.writeByteArray(Parcel.java:457)
at android.os.Parcel.writeSerializable(Parcel.java:1277)
at de.telekom.connectedcar.shuttle.driver.model.Trip.writeToParcel(Trip.java:92)
at de.telekom.connectedcar.shuttle.driver.model.TripTest.parcelOutAndInUsingCreator(TripTest.java:48)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
4

1 回答 1

3

不幸的是,Roboelectric 的 ShadowParcel 不包括 writeByteArray() 方法的实现。

这里有一个活跃的拉取请求:https ://github.com/robolectric/robolectric/pull/474

于 2013-07-26T20:17:15.453 回答