Skip to content

Commit

Permalink
Maven test dependencies outside of rocker
Browse files Browse the repository at this point in the history
Moreover, it uses mockk version from the BOM for Maven Projects. it is published by micronaut test.
  • Loading branch information
sdelamo committed Sep 18, 2022
1 parent 1506271 commit 0fe134e
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 30 deletions.
Expand Up @@ -148,38 +148,12 @@ MavenBuild mavenBuild
@dependency.template("io.micronaut", "micronaut-http-client", "test", null, false, null)
}
@if (features.testFramework().isJunit()) {
@dependency.template("org.junit.jupiter", "junit-jupiter-api", "test", null, false, null)
@dependency.template("org.junit.jupiter", "junit-jupiter-engine", "test", null, false, null)
@dependency.template("io.micronaut.test", "micronaut-test-junit5", "test", null, false, null)
@if (features.contains("hamcrest")) {
@dependency.template("org.hamcrest", "hamcrest", "test", null, false, null)
}
@if (features.contains("mockito")) {
@dependency.template("org.mockito", "mockito-core", "test", null, false, null)
}
} else if (features.testFramework().isKotlinTestFramework()) {
@dependency.template("io.mockk", "mockk", "test", "1.9.3", false, null)
@if (features.testFramework().isKoTest()) {
@dependency.template("io.micronaut.test", "micronaut-test-kotest", "test", null, false, null)
@dependency.template("io.kotest", "kotest-runner-junit5-jvm", "test", "4.2.5", false, null)
@dependency.template("io.kotest", "kotest-assertions-core-jvm", "test", "4.2.5", false, null)
}
} else if (features.testFramework().isSpock()) {
@if (!features.language().isGroovy()) {
@dependency.template("io.micronaut", "micronaut-inject-groovy", "test", null, false, null)
}
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
@dependency.template("io.micronaut.test", "micronaut-test-spock", "test", null, false, null)
}
@if (features.contains("neo4j-bolt")) {
@dependency.template("org.neo4j.test", "neo4j-harness", "test", null, false, null)
Expand Down
Expand Up @@ -36,11 +36,11 @@

@Singleton
public class Groovy implements LanguageFeature {
protected final List<GroovyApplicationFeature> applicationFeatures;
protected static final Dependency DEPENDENCY_MICRONAUT_GROOVY_RUNTIME = MicronautDependencyUtils.groovyDependency()
.artifactId("micronaut-runtime-groovy")
.compile()
.build();
protected final List<GroovyApplicationFeature> applicationFeatures;

public Groovy(List<GroovyApplicationFeature> applicationFeatures, Spock spock) {
this.applicationFeatures = applicationFeatures;
Expand Down
Expand Up @@ -15,27 +15,59 @@
*/
package io.micronaut.starter.feature.test;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.application.generator.GeneratorContext;
import io.micronaut.starter.build.dependencies.Dependency;
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.TestFramework;

import jakarta.inject.Singleton;

@Singleton
public class Junit implements TestFeature {
protected static final String GROUP_ID_JUNIT_JUPITER = "org.junit.jupiter";
protected static final String ARTIFACT_ID_JUNIT_JUPITER_API = "junit-jupiter-api";
protected static final String ARTIFACT_ID_JUNIT_JUPITER_ENGINE = "junit-jupiter-engine";

protected static final String ARTIFACT_ID_MICRONAUT_TEST_JUNIT_5 = "micronaut-test-junit5";

protected static final Dependency DEPENDENCY_JUNIT_JUPITER_API = Dependency.builder()
.groupId(GROUP_ID_JUNIT_JUPITER)
.artifactId(ARTIFACT_ID_JUNIT_JUPITER_API)
.test()
.build();

protected static final Dependency DEPENDENCY_JUNIT_JUPITER_ENGINE = Dependency.builder()
.groupId(GROUP_ID_JUNIT_JUPITER)
.artifactId(ARTIFACT_ID_JUNIT_JUPITER_ENGINE)
.test()
.build();

protected static final Dependency DEPENDENCY_MICRONAUT_TEST_JUNIT5 = MicronautDependencyUtils
.testDependency()
.artifactId(ARTIFACT_ID_MICRONAUT_TEST_JUNIT_5)
.test()
.build();

@Override
@NonNull
public String getName() {
return "junit";
}

@Override
public void doApply(GeneratorContext generatorContext) {
// no-op
// Only for Maven, these dependencies are applied by the Micronaut Gradle Plugin
if (generatorContext.getBuildTool() == BuildTool.MAVEN) {
generatorContext.addDependency(DEPENDENCY_JUNIT_JUPITER_API);
generatorContext.addDependency(DEPENDENCY_JUNIT_JUPITER_ENGINE);
generatorContext.addDependency(DEPENDENCY_MICRONAUT_TEST_JUNIT5);
}
}

@Override
public TestFramework getTestFramework() {
return TestFramework.JUNIT;
}

}
Expand Up @@ -15,16 +15,37 @@
*/
package io.micronaut.starter.feature.test;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.application.generator.GeneratorContext;
import io.micronaut.starter.build.dependencies.Dependency;
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.TestFramework;
import io.micronaut.starter.template.URLTemplate;

import jakarta.inject.Singleton;

@Singleton
public class KoTest implements TestFeature {
protected static final String ARTIFACT_ID_MICRONAUT_TEST_KOTEST = "micronaut-test-kotest";

protected static final Dependency DEPENDENCY_MICRONAUT_TEST_KOTEST = MicronautDependencyUtils
.testDependency()
.artifactId(ARTIFACT_ID_MICRONAUT_TEST_KOTEST)
.test()
.build();
protected static final String ARTIFACT_ID_KOTEST_RUNNER_JUNIT_5_JVM = "kotest-runner-junit5-jvm";

protected static final String ARTIFACT_ID_KOTEST_ASSERTIONS_CORE_JVM = "kotest-assertions-core-jvm";

protected final Mockk mockk;

public KoTest(Mockk mockk) {
this.mockk = mockk;
}

@Override
@NonNull
public String getName() {
return "kotest";
}
Expand All @@ -35,6 +56,17 @@ public void doApply(GeneratorContext generatorContext) {
generatorContext.addTemplate("koTestConfig",
new URLTemplate("src/test/kotlin/io/kotest/provided/ProjectConfig.kt",
classLoader.getResource("kotest/ProjectConfig.kt")));

// Only for Maven, these dependencies are applied by the Micronaut Gradle Plugin
if (generatorContext.getBuildTool() == BuildTool.MAVEN) {
generatorContext.addDependency(DEPENDENCY_MICRONAUT_TEST_KOTEST);
generatorContext.addDependency(Dependency.builder()
.lookupArtifactId(ARTIFACT_ID_KOTEST_RUNNER_JUNIT_5_JVM)
.test());
generatorContext.addDependency(Dependency.builder()
.lookupArtifactId(ARTIFACT_ID_KOTEST_ASSERTIONS_CORE_JVM)
.test());
}
}

@Override
Expand Down
@@ -0,0 +1,32 @@
/*
* 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.starter.application.ApplicationType;
import io.micronaut.starter.feature.Category;
import io.micronaut.starter.feature.Feature;

public interface MockingFeature extends Feature {
@Override
default boolean supports(ApplicationType applicationType) {
return true;
}

@Override
default String getCategory() {
return Category.DEV_TOOLS;
}
}
@@ -0,0 +1,83 @@
/*
* 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()
.groupId(GROUP_ID_IO_MOCKK)
.artifactId(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();
}
}


Expand Up @@ -15,22 +15,60 @@
*/
package io.micronaut.starter.feature.test;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.application.generator.GeneratorContext;
import io.micronaut.starter.build.dependencies.Dependency;
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import io.micronaut.starter.options.TestFramework;

import jakarta.inject.Singleton;

@Singleton
public class Spock implements TestFeature {
protected static final String GROUP_ID_SPOCKFRAMEWORK = "org.spockframework";
protected static final String ARTIFACT_ID_SPOCK_CORE = "spock-core";
protected static final String GROUP_ID_CODEHAUS_GROOVY = "org.codehaus.groovy";
protected static final String ARTIFACT_ID_GROOVY_ALL = "groovy-all";
protected static final Dependency DEPENDENCY_MICRONAUT_INJECT_GROOVY = MicronautDependencyUtils
.coreDependency()
.artifactId("micronaut-inject-groovy")
.test()
.build();

protected static final Dependency DEPENDENCY_MICRONAUT_TEST_SPOCK = MicronautDependencyUtils
.testDependency()
.artifactId("micronaut-test-spock")
.test()
.build();

protected static final Dependency DEPENDENCY_SPOCK_CORE_EXCLUDING_GROOVY_ALL = Dependency.builder()
.groupId(GROUP_ID_SPOCKFRAMEWORK)
.artifactId(ARTIFACT_ID_SPOCK_CORE)
.exclude(Dependency.builder()
.groupId(GROUP_ID_CODEHAUS_GROOVY)
.artifactId(ARTIFACT_ID_GROOVY_ALL)
.build())
.test()
.build();

@Override
@NonNull
public String getName() {
return "spock";
}

@Override
public void doApply(GeneratorContext generatorContext) {
// no-op
// Only for Maven, these dependencies are applied by the Micronaut Gradle Plugin
if (generatorContext.getBuildTool() == BuildTool.MAVEN) {
if (generatorContext.getLanguage() != Language.GROOVY) {
generatorContext.addDependency(DEPENDENCY_MICRONAUT_INJECT_GROOVY);
}
generatorContext.addDependency(DEPENDENCY_SPOCK_CORE_EXCLUDING_GROOVY_ALL);
generatorContext.addDependency(DEPENDENCY_MICRONAUT_TEST_SPOCK);
}
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions starter-core/src/main/resources/pom.xml
Expand Up @@ -16,6 +16,16 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
<version>4.6.4</version>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<version>4.6.4</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom-alpha</artifactId>
Expand Down

0 comments on commit 0fe134e

Please sign in to comment.