Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maven test dependencies outside of rocker (#1432)
- Loading branch information
Showing
7 changed files
with
274 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
starter-core/src/main/java/io/micronaut/starter/feature/test/Mockk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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 io.micronaut.starter.feature.test; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.starter.application.ApplicationType; | ||
import io.micronaut.starter.application.generator.GeneratorContext; | ||
import io.micronaut.starter.build.dependencies.Dependency; | ||
import io.micronaut.starter.feature.DefaultFeature; | ||
import io.micronaut.starter.feature.Feature; | ||
import io.micronaut.starter.options.BuildTool; | ||
import io.micronaut.starter.options.Language; | ||
import io.micronaut.starter.options.Options; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Set; | ||
|
||
@Singleton | ||
public class Mockk implements MockingFeature, DefaultFeature { | ||
public static final String ARTIFACT_ID_MOCKK = "mockk"; | ||
public static final String NAME_MOCKK = "mockk"; | ||
public static final String GROUP_ID_IO_MOCKK = "io.mockk"; | ||
|
||
@Override | ||
@NonNull | ||
public String getName() { | ||
return NAME_MOCKK; | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
return "Mockk"; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getDescription() { | ||
return "Mocking library for Kotlin"; | ||
} | ||
|
||
@Override | ||
public String getThirdPartyDocumentation() { | ||
return "https://mockk.io"; | ||
} | ||
|
||
@Override | ||
public void apply(GeneratorContext generatorContext) { | ||
// Only for Maven, these dependencies are applied by the Micronaut Gradle Plugin | ||
if (generatorContext.getBuildTool() == BuildTool.MAVEN) { | ||
generatorContext.addDependency(Dependency.builder() | ||
.lookupArtifactId(ARTIFACT_ID_MOCKK) | ||
.test()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isVisible() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean shouldApply(ApplicationType applicationType, Options options, Set<Feature> selectedFeatures) { | ||
return options.getBuildTool() == BuildTool.MAVEN && | ||
options.getLanguage() == Language.KOTLIN && | ||
options.getTestFramework().isKotlinTestFramework(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
starter-core/src/test/groovy/io/micronaut/starter/feature/test/MockkSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.micronaut.starter.feature.test | ||
|
||
import io.micronaut.starter.ApplicationContextSpec | ||
import io.micronaut.starter.BuildBuilder | ||
import io.micronaut.starter.application.ApplicationType | ||
import io.micronaut.starter.feature.Category | ||
import io.micronaut.starter.feature.Feature | ||
import io.micronaut.starter.feature.Features | ||
import io.micronaut.starter.fixture.CommandOutputFixture | ||
import io.micronaut.starter.options.BuildTool | ||
import io.micronaut.starter.options.JdkVersion | ||
import io.micronaut.starter.options.Language | ||
import io.micronaut.starter.options.Options | ||
import io.micronaut.starter.options.TestFramework | ||
import io.micronaut.starter.util.VersionInfo | ||
import spock.lang.Shared | ||
import spock.lang.Subject | ||
import spock.lang.Unroll | ||
|
||
class MockkSpec extends ApplicationContextSpec implements CommandOutputFixture { | ||
@Shared | ||
@Subject | ||
Mockk mockk = beanContext.getBean(Mockk) | ||
|
||
void 'test readme.md with feature mockk contains links to 3rd party docs'() { | ||
when: | ||
Options options = new Options(Language.KOTLIN, TestFramework.JUNIT, BuildTool.MAVEN, JdkVersion.JDK_11, Collections.emptyMap()) | ||
Map<String, String> output = generate(ApplicationType.DEFAULT, options, ['mockk']) | ||
String readme = output["README.md"] | ||
|
||
then: | ||
readme | ||
readme.contains("https://mockk.io") | ||
} | ||
|
||
void "test mockk belongs to Dev Tools category"() { | ||
expect: | ||
Category.DEV_TOOLS == mockk.category | ||
} | ||
|
||
@Unroll | ||
void 'mockk feature should not be applied for languages other than Kotlin'(Language language) { | ||
given: | ||
Set<Feature> features = [mockk] as Set<Feature> | ||
expect: | ||
!mockk.shouldApply(ApplicationType.DEFAULT, new Options(language, TestFramework.KOTEST, BuildTool.MAVEN), features) | ||
|
||
where: | ||
language << Language.values() - Language.KOTLIN | ||
} | ||
|
||
@Unroll | ||
void 'test mockk feature is added automatically for Maven and Kotest for language=#language'(Language language) { | ||
when: | ||
String template = new BuildBuilder(beanContext, BuildTool.MAVEN) | ||
.jdkVersion(JdkVersion.JDK_11) | ||
.language(language) | ||
.features([]) | ||
.testFramework(TestFramework.KOTEST) | ||
.render() | ||
|
||
then: | ||
template.contains(""" | ||
<dependency> | ||
<groupId>io.mockk</groupId> | ||
<artifactId>mockk</artifactId> | ||
""") | ||
|
||
where: | ||
language << [Language.KOTLIN] | ||
} | ||
} |