• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.settings;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.when;
21 
22 import android.widget.LinearLayout;
23 import android.widget.ScrollView;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.robolectric.annotation.Config;
30 
31 @RunWith(SettingsRobolectricTestRunner.class)
32 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
33 public class MasterClearTest {
34     private MasterClear mMasterClear;
35     @Mock
36     private ScrollView mScrollView;
37     @Mock
38     private LinearLayout mLinearLayout;
39 
40     @Before
setUp()41     public void setUp() {
42         MockitoAnnotations.initMocks(this);
43         mMasterClear = new MasterClear();
44 
45         // Make scrollView only have one child
46         when(mScrollView.getChildAt(0)).thenReturn(mLinearLayout);
47         when(mScrollView.getChildCount()).thenReturn(1);
48     }
49 
50     @Test
testHasReachedBottom_NotScrollDown_returnFalse()51     public void testHasReachedBottom_NotScrollDown_returnFalse() {
52         initScrollView(100, 0, 200);
53 
54         assertThat(mMasterClear.hasReachedBottom(mScrollView)).isFalse();
55     }
56 
57     @Test
testHasReachedBottom_CanNotScroll_returnTrue()58     public void testHasReachedBottom_CanNotScroll_returnTrue() {
59         initScrollView(100, 0, 80);
60 
61         assertThat(mMasterClear.hasReachedBottom(mScrollView)).isTrue();
62     }
63 
64     @Test
testHasReachedBottom_ScrollToBottom_returnTrue()65     public void testHasReachedBottom_ScrollToBottom_returnTrue() {
66         initScrollView(100, 100, 200);
67 
68         assertThat(mMasterClear.hasReachedBottom(mScrollView)).isTrue();
69     }
70 
initScrollView(int height, int scrollY, int childBottom)71     private void initScrollView(int height, int scrollY, int childBottom) {
72         when(mScrollView.getHeight()).thenReturn(height);
73         when(mScrollView.getScrollY()).thenReturn(scrollY);
74         when(mLinearLayout.getBottom()).thenReturn(childBottom);
75     }
76 }
77