Merge "Test Week - Add test for PageIndicatorDots.java" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
76a048d072
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user