1 /* 2 * Copyright (C) 2021 The Dagger Authors. 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 import com.google.common.truth.Expect 18 import java.io.File 19 import org.gradle.testkit.runner.BuildResult 20 import org.gradle.testkit.runner.GradleRunner 21 import org.gradle.testkit.runner.TaskOutcome 22 import org.junit.Before 23 import org.junit.Rule 24 import org.junit.Test 25 import org.junit.rules.TemporaryFolder 26 27 // Verifies the aggregated task is configured correctly in a multi-module flavored project. 28 class VariantsConfigurationTest { 29 @get:Rule 30 val testProjectDir = TemporaryFolder() 31 32 @get:Rule 33 val expect: Expect = Expect.create() 34 35 @Before setupnull36 fun setup() { 37 val projectRoot = testProjectDir.root 38 File("src/test/data/flavored-project").copyRecursively(projectRoot) 39 } 40 41 @Test verifyFlavorConfiguration_demoDebugnull42 fun verifyFlavorConfiguration_demoDebug() { 43 val result = runGradleTasks(":app:assembleMinApi21DemoDebug") 44 expect.that(result.task(":app:assembleMinApi21DemoDebug")!!.outcome) 45 .isEqualTo(TaskOutcome.SUCCESS) 46 } 47 48 @Test verifyFlavorConfiguration_fullReleasenull49 fun verifyFlavorConfiguration_fullRelease() { 50 val result = runGradleTasks(":app:assembleMinApi24FullRelease") 51 expect.that(result.task(":app:assembleMinApi24FullRelease")!!.outcome) 52 .isEqualTo(TaskOutcome.SUCCESS) 53 } 54 runGradleTasksnull55 private fun runGradleTasks(vararg args: String): BuildResult { 56 return GradleRunner.create() 57 .withProjectDir(testProjectDir.root) 58 .withArguments(*args) 59 .withPluginClasspath() 60 .forwardOutput() 61 .build() 62 } 63 } 64