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 | |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 17 | package com.android.car.ui.recyclerview; |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 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 | |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.junit.runner.RunWith; |
Ram Parameswaran | 39020e4 | 2020-01-23 17:50:54 -0800 | [diff] [blame] | 28 | import org.robolectric.RobolectricTestRunner; |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 29 | import org.robolectric.RuntimeEnvironment; |
| 30 | |
Ram Parameswaran | 39020e4 | 2020-01-23 17:50:54 -0800 | [diff] [blame] | 31 | @RunWith(RobolectricTestRunner.class) |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 32 | public class CarUiSmoothScrollerTest { |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 33 | |
| 34 | private Context mContext; |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 35 | private CarUiSmoothScroller mCarUiSmoothScroller; |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 36 | |
| 37 | @Before |
| 38 | public void setUp() { |
| 39 | mContext = RuntimeEnvironment.application; |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 40 | mCarUiSmoothScroller = new CarUiSmoothScroller(mContext); |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void calculateTimeForScrolling_shouldInitializeAllValues() { |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 45 | assertThat(mCarUiSmoothScroller.mMillisecondsPerInch).isNotEqualTo(0); |
| 46 | assertThat(mCarUiSmoothScroller.mDecelerationTimeDivisor).isNotEqualTo(0); |
| 47 | assertThat(mCarUiSmoothScroller.mMillisecondsPerPixel).isNotEqualTo(0); |
| 48 | assertThat(mCarUiSmoothScroller.mInterpolator).isNotNull(); |
| 49 | assertThat(mCarUiSmoothScroller.mDensityDpi).isNotEqualTo(0); |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Test |
| 53 | public void getVerticalSnapPreference_shouldReturnSnapToStart() { |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 54 | assertThat(mCarUiSmoothScroller.getVerticalSnapPreference()).isEqualTo(SNAP_TO_START); |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void calculateTimeForScrolling_shouldReturnMultiplierOfMillisecondsPerPixel() { |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 59 | assertThat(mCarUiSmoothScroller.calculateTimeForScrolling(20)).isEqualTo( |
| 60 | (int) Math.ceil(Math.abs(20) * mCarUiSmoothScroller.mMillisecondsPerPixel)); |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void calculateTimeForDeceleration_shouldReturnNotBeZero() { |
Priyank Singh | 7361b4b | 2019-10-04 11:24:10 -0700 | [diff] [blame] | 65 | assertThat(mCarUiSmoothScroller.calculateTimeForDeceleration(20)).isNotEqualTo(0); |
Priyank Singh | 2650d9b | 2019-09-25 15:55:54 -0700 | [diff] [blame] | 66 | } |
| 67 | } |