diff options
author | 2024-07-22 18:42:02 +0000 | |
---|---|---|
committer | 2024-07-22 18:42:02 +0000 | |
commit | 76a048d0720edae87f527e05b29b18e110a362b4 (patch) | |
tree | f63ecea6187d674fd56493a16f090803c40fea5c | |
parent | d8d153282549c2bb9e92ccc4d8363af53d885d68 (diff) | |
parent | aa1a462d0eee0f1f02613fe4550988a4497a0fb8 (diff) |
Merge "Test Week - Add test for PageIndicatorDots.java" into main
-rw-r--r-- | src/com/android/launcher3/pageindicators/PageIndicatorDots.java | 19 | ||||
-rw-r--r-- | tests/src/com/android/launcher3/pageindicators/PageIndicatorDotsTest.kt | 64 |
2 files changed, 82 insertions, 1 deletions
diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java index e44ea1d69d..a691e45097 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java @@ -43,6 +43,7 @@ import android.view.animation.Interpolator; import android.view.animation.OvershootInterpolator; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import com.android.launcher3.Insettable; import com.android.launcher3.R; @@ -131,7 +132,8 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator private float mCurrentPosition; private float mFinalPosition; private boolean mIsScrollPaused; - private boolean mIsTwoPanels; + @VisibleForTesting + boolean mIsTwoPanels; private ObjectAnimator mAnimator; private @Nullable ObjectAnimator mAlphaAnimator; @@ -477,6 +479,21 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator return sTempRect; } + @VisibleForTesting + int getActivePage() { + return mActivePage; + } + + @VisibleForTesting + int getNumPages() { + return mNumPages; + } + + @VisibleForTesting + float getCurrentPosition() { + return mCurrentPosition; + } + private class MyOutlineProver extends ViewOutlineProvider { @Override diff --git a/tests/src/com/android/launcher3/pageindicators/PageIndicatorDotsTest.kt b/tests/src/com/android/launcher3/pageindicators/PageIndicatorDotsTest.kt new file mode 100644 index 0000000000..9a8f9577c0 --- /dev/null +++ b/tests/src/com/android/launcher3/pageindicators/PageIndicatorDotsTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.pageindicators + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import com.android.launcher3.util.ActivityContextWrapper +import junit.framework.TestCase.assertEquals +import org.junit.Test +import org.mockito.Mockito + +class PageIndicatorDotsTest { + + private val context: Context = + ActivityContextWrapper(ApplicationProvider.getApplicationContext()) + private val pageIndicatorDots: PageIndicatorDots = Mockito.spy(PageIndicatorDots(context)) + + @Test + fun `setActiveMarker should set the active page to the parameter passed`() { + pageIndicatorDots.setActiveMarker(2) + + assertEquals(2, pageIndicatorDots.activePage) + } + + @Test + fun `setActiveMarker should set the active page to the parameter passed divided by two in two panel layouts`() { + pageIndicatorDots.mIsTwoPanels = true + + pageIndicatorDots.setActiveMarker(5) + + assertEquals(2, pageIndicatorDots.activePage) + } + + @Test + fun `setMarkersCount should set the number of pages to the passed parameter and if the last page gets removed we want to go to the previous page`() { + pageIndicatorDots.setMarkersCount(3) + + assertEquals(3, pageIndicatorDots.numPages) + } + + @Test + fun `for setMarkersCount if the last page gets removed we want to go to the previous page`() { + pageIndicatorDots.setActiveMarker(2) + + pageIndicatorDots.setMarkersCount(2) + + assertEquals(1, pageIndicatorDots.activePage) + assertEquals(pageIndicatorDots.activePage.toFloat(), pageIndicatorDots.currentPosition) + } +} |