1 /* <lambda>null2 * Copyright (C) 2023 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 android.tools.flicker.legacy 18 19 import android.tools.NavBar 20 import android.tools.Rotation 21 import android.tools.ScenarioBuilder 22 import android.tools.flicker.assertions.FlickerTest 23 24 /** 25 * Factory for creating JUnit4 compatible tests based on the flicker DSL 26 * 27 * This class recreates behavior from JUnit5 TestFactory that is not available on JUnit4 28 */ 29 object LegacyFlickerTestFactory { 30 /** 31 * Gets a list of test configurations. 32 * 33 * Each configuration has only a start orientation. 34 */ 35 @JvmOverloads 36 @JvmStatic 37 fun nonRotationTests( 38 supportedRotations: List<Rotation> = listOf(Rotation.ROTATION_0, Rotation.ROTATION_90), 39 supportedNavigationModes: List<NavBar> = listOf(NavBar.MODE_3BUTTON, NavBar.MODE_GESTURAL), 40 extraArgs: Map<String, Any> = emptyMap() 41 ): List<FlickerTest> { 42 return supportedNavigationModes.flatMap { navBarMode -> 43 supportedRotations.map { rotation -> 44 createFlickerTest(navBarMode, rotation, rotation, extraArgs) 45 } 46 } 47 } 48 49 /** 50 * Gets a list of test configurations. 51 * 52 * Each configuration has a start and end orientation. 53 */ 54 @JvmOverloads 55 @JvmStatic 56 fun rotationTests( 57 supportedRotations: List<Rotation> = listOf(Rotation.ROTATION_0, Rotation.ROTATION_90), 58 supportedNavigationModes: List<NavBar> = listOf(NavBar.MODE_3BUTTON, NavBar.MODE_GESTURAL), 59 extraArgs: Map<String, Any> = emptyMap() 60 ): List<FlickerTest> { 61 return supportedNavigationModes.flatMap { navBarMode -> 62 supportedRotations 63 .flatMap { start -> supportedRotations.map { end -> start to end } } 64 .filter { (start, end) -> start != end } 65 .map { (start, end) -> createFlickerTest(navBarMode, start, end, extraArgs) } 66 } 67 } 68 69 private fun createFlickerTest( 70 navBarMode: NavBar, 71 startRotation: Rotation, 72 endRotation: Rotation, 73 extraArgs: Map<String, Any> 74 ) = 75 LegacyFlickerTest( 76 ScenarioBuilder() 77 .withStartRotation(startRotation) 78 .withEndRotation(endRotation) 79 .withNavBarMode(navBarMode) 80 .withExtraConfigs(extraArgs) 81 ) 82 } 83