blob: c5dc78be766c1cbc236adf2c79b6833083ab2f1f [file] [log] [blame]
Priyank Singh2650d9b2019-09-25 15:55:54 -07001/*
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 Singh7361b4b2019-10-04 11:24:10 -070017package com.android.car.ui.recyclerview;
Priyank Singh2650d9b2019-09-25 15:55:54 -070018
19import static androidx.recyclerview.widget.LinearSmoothScroller.SNAP_TO_START;
20
21import static com.google.common.truth.Truth.assertThat;
22
23import android.content.Context;
24
Priyank Singh2650d9b2019-09-25 15:55:54 -070025import org.junit.Before;
26import org.junit.Test;
27import org.junit.runner.RunWith;
Ram Parameswaran39020e42020-01-23 17:50:54 -080028import org.robolectric.RobolectricTestRunner;
Priyank Singh2650d9b2019-09-25 15:55:54 -070029import org.robolectric.RuntimeEnvironment;
30
Ram Parameswaran39020e42020-01-23 17:50:54 -080031@RunWith(RobolectricTestRunner.class)
Priyank Singh7361b4b2019-10-04 11:24:10 -070032public class CarUiSmoothScrollerTest {
Priyank Singh2650d9b2019-09-25 15:55:54 -070033
34 private Context mContext;
Priyank Singh7361b4b2019-10-04 11:24:10 -070035 private CarUiSmoothScroller mCarUiSmoothScroller;
Priyank Singh2650d9b2019-09-25 15:55:54 -070036
37 @Before
38 public void setUp() {
39 mContext = RuntimeEnvironment.application;
Priyank Singh7361b4b2019-10-04 11:24:10 -070040 mCarUiSmoothScroller = new CarUiSmoothScroller(mContext);
Priyank Singh2650d9b2019-09-25 15:55:54 -070041 }
42
43 @Test
44 public void calculateTimeForScrolling_shouldInitializeAllValues() {
Priyank Singh7361b4b2019-10-04 11:24:10 -070045 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 Singh2650d9b2019-09-25 15:55:54 -070050 }
51
52 @Test
53 public void getVerticalSnapPreference_shouldReturnSnapToStart() {
Priyank Singh7361b4b2019-10-04 11:24:10 -070054 assertThat(mCarUiSmoothScroller.getVerticalSnapPreference()).isEqualTo(SNAP_TO_START);
Priyank Singh2650d9b2019-09-25 15:55:54 -070055 }
56
57 @Test
58 public void calculateTimeForScrolling_shouldReturnMultiplierOfMillisecondsPerPixel() {
Priyank Singh7361b4b2019-10-04 11:24:10 -070059 assertThat(mCarUiSmoothScroller.calculateTimeForScrolling(20)).isEqualTo(
60 (int) Math.ceil(Math.abs(20) * mCarUiSmoothScroller.mMillisecondsPerPixel));
Priyank Singh2650d9b2019-09-25 15:55:54 -070061 }
62
63 @Test
64 public void calculateTimeForDeceleration_shouldReturnNotBeZero() {
Priyank Singh7361b4b2019-10-04 11:24:10 -070065 assertThat(mCarUiSmoothScroller.calculateTimeForDeceleration(20)).isNotEqualTo(0);
Priyank Singh2650d9b2019-09-25 15:55:54 -070066 }
67}