Methods Summary |
---|
private void | focusSearch()
mRecyclerView.focusSearch(1);
|
private void | layout()
mRecyclerView.layout(0, 0, 320, 320);
|
private void | measure()
mRecyclerView.measure(View.MeasureSpec.AT_MOST | 320, View.MeasureSpec.AT_MOST | 240);
|
protected void | setUp()
super.setUp();
mRecyclerView = new RecyclerView(mContext);
|
public void | testAdapterChangeCallbacks()
MockLayoutManager layoutManager = new MockLayoutManager();
mRecyclerView.setLayoutManager(layoutManager);
MockAdapter adapterOld = new MockAdapter(1);
mRecyclerView.setAdapter(adapterOld);
layoutManager.assertPrevNextAdapters(null, adapterOld);
MockAdapter adapterNew = new MockAdapter(2);
mRecyclerView.setAdapter(adapterNew);
layoutManager.assertPrevNextAdapters("switching adapters should trigger correct callbacks"
, adapterOld, adapterNew);
mRecyclerView.setAdapter(null);
layoutManager.assertPrevNextAdapters(
"Setting adapter null should trigger correct callbacks",
adapterNew, null);
|
public void | testFocusWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
focusSearch();
|
public void | testLayout()
MockLayoutManager layoutManager = new MockLayoutManager();
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(new MockAdapter(3));
layout();
assertEquals("when both layout manager and activity is set, recycler view should call"
+ " layout manager's layout method", 1, layoutManager.mLayoutCount);
|
public void | testLayoutWithoutAdapter()
MockLayoutManager layoutManager = new MockLayoutManager();
mRecyclerView.setLayoutManager(layoutManager);
layout();
assertEquals("layout manager should not be called if there is no adapter attached",
0, layoutManager.mLayoutCount);
|
public void | testLayoutWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
|
public void | testMeasureWithoutLayoutManager()
measure();
|
public void | testObservingAdapters()
MockAdapter adapterOld = new MockAdapter(1);
mRecyclerView.setAdapter(adapterOld);
assertTrue("attached adapter should have observables", adapterOld.hasObservers());
MockAdapter adapterNew = new MockAdapter(2);
mRecyclerView.setAdapter(adapterNew);
assertFalse("detached adapter should lose observable", adapterOld.hasObservers());
assertTrue("new adapter should have observers", adapterNew.hasObservers());
mRecyclerView.setAdapter(null);
assertNull("adapter should be removed successfully", mRecyclerView.getAdapter());
assertFalse("when adapter is removed, observables should be removed too",
adapterNew.hasObservers());
|
public void | testSavedState()
MockLayoutManager mlm = new MockLayoutManager();
mRecyclerView.setLayoutManager(mlm);
mRecyclerView.setAdapter(new MockAdapter(3));
layout();
Parcelable savedState = mRecyclerView.onSaveInstanceState();
// we append a suffix to the parcelable to test out of bounds
String parcelSuffix = UUID.randomUUID().toString();
Parcel parcel = Parcel.obtain();
savedState.writeToParcel(parcel, 0);
parcel.writeString(parcelSuffix);
// reset for reading
parcel.setDataPosition(0);
// re-create
savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel);
RecyclerView restored = new RecyclerView(mContext);
MockLayoutManager mlmRestored = new MockLayoutManager();
restored.setLayoutManager(mlmRestored);
restored.setAdapter(new MockAdapter(3));
restored.onRestoreInstanceState(savedState);
assertEquals("Parcel reading should not go out of bounds", parcelSuffix,
parcel.readString());
assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail());
assertEquals("uuid in layout manager should be preserved properly", mlm.mUuid,
mlmRestored.mUuid);
assertNotSame("stateless parameter should not be preserved", mlm.mLayoutCount,
mlmRestored.mLayoutCount);
layout();
|
public void | testSavedStateWithStatelessLayoutManager()
mRecyclerView.setLayoutManager(new MockLayoutManager() {
@Override
public Parcelable onSaveInstanceState() {
return null;
}
});
mRecyclerView.setAdapter(new MockAdapter(3));
Parcel parcel = Parcel.obtain();
String parcelSuffix = UUID.randomUUID().toString();
Parcelable savedState = mRecyclerView.onSaveInstanceState();
savedState.writeToParcel(parcel, 0);
parcel.writeString(parcelSuffix);
// reset position for reading
parcel.setDataPosition(0);
RecyclerView restored = new RecyclerView(mContext);
restored.setLayoutManager(new MockLayoutManager());
mRecyclerView.setAdapter(new MockAdapter(3));
// restore
savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel);
restored.onRestoreInstanceState(savedState);
assertEquals("Parcel reading should not go out of bounds", parcelSuffix,
parcel.readString());
assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail());
|
public void | testScrollToPositionWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
mRecyclerView.scrollToPosition(5);
|
public void | testScrollWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
mRecyclerView.scrollBy(10, 10);
|
public void | testSmoothScrollToPositionWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
mRecyclerView.smoothScrollToPosition(5);
|
public void | testSmoothScrollWithoutLayoutManager()
mRecyclerView.setAdapter(new MockAdapter(20));
measure();
layout();
mRecyclerView.smoothScrollBy(10, 10);
|