1 /* 2 * Copyright (C) 2024 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.launcher3.pageindicators 18 19 import android.content.Context 20 import androidx.test.core.app.ApplicationProvider 21 import com.android.launcher3.util.ActivityContextWrapper 22 import junit.framework.TestCase.assertEquals 23 import org.junit.Test 24 import org.mockito.Mockito 25 26 class PageIndicatorDotsTest { 27 28 private val context: Context = 29 ActivityContextWrapper(ApplicationProvider.getApplicationContext()) 30 private val pageIndicatorDots: PageIndicatorDots = Mockito.spy(PageIndicatorDots(context)) 31 32 @Test setActiveMarker should set the active page to the parameter passednull33 fun `setActiveMarker should set the active page to the parameter passed`() { 34 pageIndicatorDots.setActiveMarker(2) 35 36 assertEquals(2, pageIndicatorDots.activePage) 37 } 38 39 @Test setActiveMarker should set the active page to the parameter passed divided by two in two panel layoutsnull40 fun `setActiveMarker should set the active page to the parameter passed divided by two in two panel layouts`() { 41 pageIndicatorDots.mIsTwoPanels = true 42 43 pageIndicatorDots.setActiveMarker(5) 44 45 assertEquals(2, pageIndicatorDots.activePage) 46 } 47 48 @Test 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 pagenull49 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`() { 50 pageIndicatorDots.setMarkersCount(3) 51 52 assertEquals(3, pageIndicatorDots.numPages) 53 } 54 55 @Test for setMarkersCount if the last page gets removed we want to go to the previous pagenull56 fun `for setMarkersCount if the last page gets removed we want to go to the previous page`() { 57 pageIndicatorDots.setActiveMarker(2) 58 59 pageIndicatorDots.setMarkersCount(2) 60 61 assertEquals(1, pageIndicatorDots.activePage) 62 assertEquals(pageIndicatorDots.activePage.toFloat(), pageIndicatorDots.currentPosition) 63 } 64 } 65