Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.car.ui.pagedrecyclerview; |
| 18 | |
| 19 | import static androidx.recyclerview.widget.LinearSmoothScroller.SNAP_TO_START; |
| 20 | |
| 21 | import static com.google.common.truth.Truth.assertThat; |
| 22 | |
| 23 | import android.content.Context; |
| 24 | |
| 25 | import com.android.car.ui.CarUiRobolectricTestRunner; |
| 26 | |
| 27 | import org.junit.Before; |
| 28 | import org.junit.Test; |
| 29 | import org.junit.runner.RunWith; |
| 30 | import org.robolectric.RuntimeEnvironment; |
| 31 | |
| 32 | @RunWith(CarUiRobolectricTestRunner.class) |
| 33 | public class PagedSmoothScrollerTest { |
| 34 | |
| 35 | private Context mContext; |
| 36 | private PagedSmoothScroller mPagedSmoothScroller; |
| 37 | |
| 38 | @Before |
| 39 | public void setUp() { |
| 40 | mContext = RuntimeEnvironment.application; |
| 41 | mPagedSmoothScroller = new PagedSmoothScroller(mContext); |
| 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void calculateTimeForScrolling_shouldInitializeAllValues() { |
| 46 | assertThat(mPagedSmoothScroller.mMillisecondsPerInch).isNotEqualTo(0); |
| 47 | assertThat(mPagedSmoothScroller.mDecelerationTimeDivisor).isNotEqualTo(0); |
| 48 | assertThat(mPagedSmoothScroller.mMillisecondsPerPixel).isNotEqualTo(0); |
| 49 | assertThat(mPagedSmoothScroller.mInterpolator).isNotNull(); |
| 50 | assertThat(mPagedSmoothScroller.mDensityDpi).isNotEqualTo(0); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void getVerticalSnapPreference_shouldReturnSnapToStart() { |
| 55 | assertThat(mPagedSmoothScroller.getVerticalSnapPreference()).isEqualTo(SNAP_TO_START); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void calculateTimeForScrolling_shouldReturnMultiplierOfMillisecondsPerPixel() { |
| 60 | assertThat(mPagedSmoothScroller.calculateTimeForScrolling(20)).isEqualTo( |
| 61 | (int) Math.ceil(Math.abs(20) * mPagedSmoothScroller.mMillisecondsPerPixel)); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void calculateTimeForDeceleration_shouldReturnNotBeZero() { |
| 66 | assertThat(mPagedSmoothScroller.calculateTimeForDeceleration(20)).isNotEqualTo(0); |
| 67 | } |
| 68 | } |