|
| 1 | +/* |
| 2 | + * Copyright 2024 the original author or 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 | +package org.gradle.internal.enterprise |
| 18 | + |
| 19 | +import org.gradle.api.configuration.BuildFeatures |
| 20 | +import org.gradle.api.internal.configuration.DefaultBuildFeature |
| 21 | +import org.gradle.api.invocation.Gradle |
| 22 | +import org.gradle.api.invocation.GradleLifecycle |
| 23 | +import org.gradle.internal.enterprise.impl.DefaultDevelocityBuildLifecycleService |
| 24 | +import org.gradle.util.TestUtil |
| 25 | +import spock.lang.Specification |
| 26 | + |
| 27 | +class DevelocityBuildLifecycleServiceTest extends Specification { |
| 28 | + |
| 29 | + def 'uses #correctApi API for `beforeProject` logic execution if IsolatedProjects enabled=#ipEnabled'() { |
| 30 | + given: |
| 31 | + def gradle = Mock(Gradle) { |
| 32 | + _ * getLifecycle() >> Mock(GradleLifecycle) |
| 33 | + } |
| 34 | + def buildFeatures = Mock(BuildFeatures) { |
| 35 | + _ * getIsolatedProjects() >> new DefaultBuildFeature( |
| 36 | + TestUtil.providerFactory().provider { ipEnabled }, |
| 37 | + TestUtil.providerFactory().provider { ipEnabled } |
| 38 | + ) |
| 39 | + } |
| 40 | + def service = new DefaultDevelocityBuildLifecycleService(gradle, buildFeatures) |
| 41 | + |
| 42 | + when: |
| 43 | + service.beforeProject {/*do something*/ } |
| 44 | + |
| 45 | + then: |
| 46 | + if (ipEnabled) { |
| 47 | + 0 * gradle.allprojects(_) |
| 48 | + 1 * gradle.lifecycle.beforeProject(_) |
| 49 | + } else { |
| 50 | + 1 * gradle.allprojects(_) |
| 51 | + 0 * gradle.lifecycle.beforeProject(_) |
| 52 | + } |
| 53 | + |
| 54 | + where: |
| 55 | + ipEnabled | correctApi |
| 56 | + true | "GradleLifecycle#beforeProject" |
| 57 | + false | "Gradle#allprojects" |
| 58 | + } |
| 59 | +} |
0 commit comments