diff options
Diffstat (limited to 'library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java')
-rw-r--r-- | library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java | 95 |
1 files changed, 46 insertions, 49 deletions
diff --git a/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java b/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java index 6fa4c54..bcb51a8 100644 --- a/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java +++ b/library/recyclerview/test/robotest/src/com/android/setupwizardlib/template/RecyclerViewScrollHandlingDelegateTest.java @@ -26,63 +26,60 @@ import static org.robolectric.RuntimeEnvironment.application; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.OnScrollListener; - -import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -@Config(sdk = { Config.OLDEST_SDK, Config.NEWEST_SDK }) -@RunWith(SuwLibRobolectricTestRunner.class) +@Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK}) +@RunWith(RobolectricTestRunner.class) public class RecyclerViewScrollHandlingDelegateTest { - @Mock - private RequireScrollMixin mRequireScrollMixin; - - private RecyclerView mRecyclerView; - private RecyclerViewScrollHandlingDelegate mDelegate; - private ArgumentCaptor<OnScrollListener> mListenerCaptor; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - mRecyclerView = spy(new RecyclerView(application)); - doReturn(20).when(mRecyclerView).computeVerticalScrollRange(); - doReturn(0).when(mRecyclerView).computeVerticalScrollExtent(); - doReturn(0).when(mRecyclerView).computeVerticalScrollOffset(); - mListenerCaptor = ArgumentCaptor.forClass(OnScrollListener.class); - doNothing().when(mRecyclerView).addOnScrollListener(mListenerCaptor.capture()); - - mDelegate = new RecyclerViewScrollHandlingDelegate(mRequireScrollMixin, mRecyclerView); - mRecyclerView.layout(0, 0, 50, 50); - } - - @Test - public void testRequireScroll() { - mDelegate.startListening(); - verify(mRequireScrollMixin).notifyScrollabilityChange(true); - } - - @Test - public void testScrolledToBottom() { - mDelegate.startListening(); - verify(mRequireScrollMixin).notifyScrollabilityChange(true); - - doReturn(20).when(mRecyclerView).computeVerticalScrollOffset(); - mListenerCaptor.getValue().onScrolled(mRecyclerView, 0, 20); - - verify(mRequireScrollMixin).notifyScrollabilityChange(false); - } - - @Test - public void testClickScrollButton() { - mDelegate.pageScrollDown(); - verify(mRecyclerView).smoothScrollBy(anyInt(), eq(50)); - } + @Mock private RequireScrollMixin mRequireScrollMixin; + + private RecyclerView mRecyclerView; + private RecyclerViewScrollHandlingDelegate mDelegate; + private ArgumentCaptor<OnScrollListener> mListenerCaptor; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + mRecyclerView = spy(new RecyclerView(application)); + doReturn(20).when(mRecyclerView).computeVerticalScrollRange(); + doReturn(0).when(mRecyclerView).computeVerticalScrollExtent(); + doReturn(0).when(mRecyclerView).computeVerticalScrollOffset(); + mListenerCaptor = ArgumentCaptor.forClass(OnScrollListener.class); + doNothing().when(mRecyclerView).addOnScrollListener(mListenerCaptor.capture()); + + mDelegate = new RecyclerViewScrollHandlingDelegate(mRequireScrollMixin, mRecyclerView); + mRecyclerView.layout(0, 0, 50, 50); + } + + @Test + public void testRequireScroll() { + mDelegate.startListening(); + verify(mRequireScrollMixin).notifyScrollabilityChange(true); + } + + @Test + public void testScrolledToBottom() { + mDelegate.startListening(); + verify(mRequireScrollMixin).notifyScrollabilityChange(true); + + doReturn(20).when(mRecyclerView).computeVerticalScrollOffset(); + mListenerCaptor.getValue().onScrolled(mRecyclerView, 0, 20); + + verify(mRequireScrollMixin).notifyScrollabilityChange(false); + } + + @Test + public void testClickScrollButton() { + mDelegate.pageScrollDown(); + verify(mRecyclerView).smoothScrollBy(anyInt(), eq(50)); + } } |