@Test public void unwrapPosition_withBadAdapter() throws Exception { RecyclerView.Adapter adapter = new BadUnwrapPositionAdapter(new TestAdapter()); DebugWrapperAdapter debugAdapter = new DebugWrapperAdapter(adapter); UnwrapPositionResult result = new UnwrapPositionResult(); thrown.expect(IllegalStateException.class); debugAdapter.unwrapPosition(result, 0); }
@Override public void unwrapPosition(@NonNull UnwrapPositionResult dest, int position) { if (((mFlags & FLAG_VERIFY_UNWRAP_POSITION) != 0) && (getWrappedAdapter() instanceof WrapperAdapter)) { final WrapperAdapter wrapperAdapter = (WrapperAdapter) getWrappedAdapter(); final UnwrapPositionResult tmpResult = new UnwrapPositionResult(); wrapperAdapter.unwrapPosition(tmpResult, position); if (tmpResult.isValid()) { final AdapterPathSegment segment = new AdapterPathSegment(tmpResult.adapter, tmpResult.tag); final int reWrappedPosition = wrapperAdapter.wrapPosition(segment, tmpResult.position); if (position != reWrappedPosition) { final String wrappedClassName = getWrappedAdapter().getClass().getSimpleName(); throw new IllegalStateException( "Found a WrapperAdapter implementation issue while executing unwrapPosition(): " + wrappedClassName + "\n" + "unwrapPosition(" + position + ") returns " + tmpResult.position + ", but " + "wrapPosition(" + tmpResult.position + ") returns " + reWrappedPosition); } } } super.unwrapPosition(dest, position); }
DebugWrapperAdapter extends SimpleWrapperAdapter<RecyclerView.ViewHolder> { @Override public void unwrapPosition(@NonNull UnwrapPositionResult dest, int position) { if (((mFlags & FLAG_VERIFY_UNWRAP_POSITION) != 0) && (getWrappedAdapter() instanceof WrapperAdapter)) { final WrapperAdapter wrapperAdapter = (WrapperAdapter) getWrappedAdapter(); final UnwrapPositionResult tmpResult = new UnwrapPositionResult(); wrapperAdapter.unwrapPosition(tmpResult, position); if (tmpResult.isValid()) { final AdapterPathSegment segment = new AdapterPathSegment(tmpResult.adapter, tmpResult.tag); final int reWrappedPosition = wrapperAdapter.wrapPosition(segment, tmpResult.position); if (position != reWrappedPosition) { final String wrappedClassName = getWrappedAdapter().getClass().getSimpleName(); throw new IllegalStateException( "Found a WrapperAdapter implementation issue while executing unwrapPosition(): " + wrappedClassName + "\n" + "unwrapPosition(" + position + ") returns " + tmpResult.position + ", but " + "wrapPosition(" + tmpResult.position + ") returns " + reWrappedPosition); } } } super.unwrapPosition(dest, position); } }
DebugWrapperAdapter extends SimpleWrapperAdapter<RecyclerView.ViewHolder> { @Override public void unwrapPosition(@NonNull UnwrapPositionResult dest, int position) { if (((mFlags & FLAG_VERIFY_UNWRAP_POSITION) != 0) && (getWrappedAdapter() instanceof WrapperAdapter)) { final WrapperAdapter wrapperAdapter = (WrapperAdapter) getWrappedAdapter(); final UnwrapPositionResult tmpResult = new UnwrapPositionResult(); wrapperAdapter.unwrapPosition(tmpResult, position); if (tmpResult.isValid()) { final AdapterPathSegment segment = new AdapterPathSegment(tmpResult.adapter, tmpResult.tag); final int reWrappedPosition = wrapperAdapter.wrapPosition(segment, tmpResult.position); if (position != reWrappedPosition) { final String wrappedClassName = getWrappedAdapter().getClass().getSimpleName(); throw new IllegalStateException( "Found a WrapperAdapter implementation issue while executing unwrapPosition(): " + wrappedClassName + "\n" + "unwrapPosition(" + position + ") returns " + tmpResult.position + ", but " + "wrapPosition(" + tmpResult.position + ") returns " + reWrappedPosition); } } } super.unwrapPosition(dest, position); } @SuppressWarnings("unchecked")  DebugWrapperAdapter(@NonNull RecyclerView.Adapter adapter); }
DebugWrapperAdapter extends SimpleWrapperAdapter<RecyclerView.ViewHolder> { @Override public void unwrapPosition(@NonNull UnwrapPositionResult dest, int position) { if (((mFlags & FLAG_VERIFY_UNWRAP_POSITION) != 0) && (getWrappedAdapter() instanceof WrapperAdapter)) { final WrapperAdapter wrapperAdapter = (WrapperAdapter) getWrappedAdapter(); final UnwrapPositionResult tmpResult = new UnwrapPositionResult(); wrapperAdapter.unwrapPosition(tmpResult, position); if (tmpResult.isValid()) { final AdapterPathSegment segment = new AdapterPathSegment(tmpResult.adapter, tmpResult.tag); final int reWrappedPosition = wrapperAdapter.wrapPosition(segment, tmpResult.position); if (position != reWrappedPosition) { final String wrappedClassName = getWrappedAdapter().getClass().getSimpleName(); throw new IllegalStateException( "Found a WrapperAdapter implementation issue while executing unwrapPosition(): " + wrappedClassName + "\n" + "unwrapPosition(" + position + ") returns " + tmpResult.position + ", but " + "wrapPosition(" + tmpResult.position + ") returns " + reWrappedPosition); } } } super.unwrapPosition(dest, position); } @SuppressWarnings("unchecked")  DebugWrapperAdapter(@NonNull RecyclerView.Adapter adapter); @Override int wrapPosition(@NonNull AdapterPathSegment pathSegment, int position); @Override void unwrapPosition(@NonNull UnwrapPositionResult dest, int position); @DebugWrapperAdapterSettingFlags int getSettingFlags(); void setSettingFlags(@DebugWrapperAdapterSettingFlags int flags); }
DebugWrapperAdapter extends SimpleWrapperAdapter<RecyclerView.ViewHolder> { @Override public void unwrapPosition(@NonNull UnwrapPositionResult dest, int position) { if (((mFlags & FLAG_VERIFY_UNWRAP_POSITION) != 0) && (getWrappedAdapter() instanceof WrapperAdapter)) { final WrapperAdapter wrapperAdapter = (WrapperAdapter) getWrappedAdapter(); final UnwrapPositionResult tmpResult = new UnwrapPositionResult(); wrapperAdapter.unwrapPosition(tmpResult, position); if (tmpResult.isValid()) { final AdapterPathSegment segment = new AdapterPathSegment(tmpResult.adapter, tmpResult.tag); final int reWrappedPosition = wrapperAdapter.wrapPosition(segment, tmpResult.position); if (position != reWrappedPosition) { final String wrappedClassName = getWrappedAdapter().getClass().getSimpleName(); throw new IllegalStateException( "Found a WrapperAdapter implementation issue while executing unwrapPosition(): " + wrappedClassName + "\n" + "unwrapPosition(" + position + ") returns " + tmpResult.position + ", but " + "wrapPosition(" + tmpResult.position + ") returns " + reWrappedPosition); } } } super.unwrapPosition(dest, position); } @SuppressWarnings("unchecked")  DebugWrapperAdapter(@NonNull RecyclerView.Adapter adapter); @Override int wrapPosition(@NonNull AdapterPathSegment pathSegment, int position); @Override void unwrapPosition(@NonNull UnwrapPositionResult dest, int position); @DebugWrapperAdapterSettingFlags int getSettingFlags(); void setSettingFlags(@DebugWrapperAdapterSettingFlags int flags); static final int FLAG_VERIFY_WRAP_POSITION; static final int FLAG_VERIFY_UNWRAP_POSITION; static final int FLAGS_ALL_DEBUG_FEATURES; }