Skip to content

Commit cf0e90e

Browse files
committed
More test coverage for the JavaModuleDependenciesBridge
1 parent dc00d60 commit cf0e90e

File tree

3 files changed

+89
-32
lines changed

3 files changed

+89
-32
lines changed

src/test/groovy/org/gradlex/javamodule/testing/test/CustomizationTest.groovy

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,4 @@ class CustomizationTest extends Specification {
5353
then:
5454
result.task(":app:test").outcome == TaskOutcome.SUCCESS
5555
}
56-
57-
def "repetitive blackbox calls on the same test suite have no effect"() {
58-
given:
59-
appBuildFile << '''
60-
javaModuleTesting.blackbox(testing.suites["test"])
61-
javaModuleTesting.blackbox(testing.suites["test"])
62-
'''
63-
appModuleInfoFile << '''
64-
module org.gradlex.test.app {
65-
}
66-
'''
67-
appTestModuleInfoFile << '''
68-
module org.gradlex.test.app.test {
69-
requires org.junit.jupiter.api;
70-
}
71-
'''
72-
73-
when:
74-
def result = runTests()
75-
76-
then:
77-
result.task(":app:test").outcome == TaskOutcome.SUCCESS
78-
}
7956
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.gradlex.javamodule.testing.test
2+
3+
import org.gradle.testkit.runner.TaskOutcome
4+
import org.gradlex.javamodule.testing.test.fixture.GradleBuild
5+
import spock.lang.Ignore
6+
import spock.lang.Specification
7+
8+
class JavaModuleDependenciesBridgeTest extends Specification {
9+
10+
@Delegate
11+
GradleBuild build = new GradleBuild()
12+
13+
def "respects moduleNameToGA mappings"() {
14+
given:
15+
appBuildFile << '''
16+
javaModuleDependencies {
17+
moduleNameToGA.put("com.example.lib", "com.example:lib")
18+
}
19+
javaModuleTesting.whitebox(testing.suites["test"]) {
20+
requires.add("org.junit.jupiter.api")
21+
requires.add("com.example.lib")
22+
opensTo.add("org.junit.platform.commons")
23+
}
24+
'''
25+
appModuleInfoFile << '''
26+
module com.example.app {
27+
}
28+
'''
29+
libModuleInfoFile << '''
30+
module com.example.lib {
31+
}
32+
'''
33+
34+
when:
35+
def result = runTests()
36+
37+
then:
38+
result.task(":app:test").outcome == TaskOutcome.SUCCESS
39+
}
40+
41+
@Ignore // See: https://github.com/gradlex-org/java-module-testing/issues/3
42+
def "respects moduleNamePrefixToGroup mappings"() {
43+
given:
44+
appBuildFile << '''
45+
javaModuleDependencies {
46+
moduleNamePrefixToGroup.put("com.example.", "com.example")
47+
}
48+
javaModuleTesting.whitebox(testing.suites["test"]) {
49+
requires.add("org.junit.jupiter.api")
50+
requires.add("com.example.lib")
51+
opensTo.add("org.junit.platform.commons")
52+
}
53+
'''
54+
appModuleInfoFile << '''
55+
module com.example.app {
56+
}
57+
'''
58+
libModuleInfoFile << '''
59+
module com.example.lib {
60+
}
61+
'''
62+
63+
when:
64+
def result = runTests()
65+
66+
then:
67+
result.task(":app:test").outcome == TaskOutcome.SUCCESS
68+
}
69+
}

src/test/groovy/org/gradlex/javamodule/testing/test/fixture/GradleBuild.groovy

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class GradleBuild {
1313
final File appBuildFile
1414
final File appModuleInfoFile
1515
final File appTestModuleInfoFile
16+
final File libBuildFile
17+
final File libModuleInfoFile
1618

1719
final String gradleVersionUnderTest = System.getProperty("gradleVersionUnderTest")
1820

@@ -22,33 +24,33 @@ class GradleBuild {
2224
this.appBuildFile = file("app/build.gradle.kts")
2325
this.appModuleInfoFile = file("app/src/main/java/module-info.java")
2426
this.appTestModuleInfoFile = file("app/src/test/java/module-info.java")
27+
this.libBuildFile = file("lib/build.gradle.kts")
28+
this.libModuleInfoFile = file("lib/src/main/java/module-info.java")
2529

2630
settingsFile << '''
31+
pluginManagement {
32+
plugins { id("org.gradlex.java-module-dependencies") version "1.0" }
33+
}
2734
dependencyResolutionManagement { repositories.mavenCentral() }
35+
includeBuild(".")
2836
rootProject.name = "test-project"
29-
include("app")
37+
include("app", "lib")
3038
'''
3139
appBuildFile << '''
3240
plugins {
33-
id("org.gradlex.java-module-dependencies") version "1.0"
41+
id("org.gradlex.java-module-dependencies")
3442
id("org.gradlex.java-module-testing")
3543
id("application")
3644
}
45+
group = "com.example"
3746
dependencies {
3847
testImplementation(platform("org.junit:junit-bom:5.9.0"))
3948
}
4049
application {
4150
mainModule.set("org.gradlex.test.app")
4251
mainClass.set("org.gradlex.test.app.Main")
4352
}
44-
tasks.register("printRuntimeJars") {
45-
doLast { println(configurations.runtimeClasspath.get().files.map { it.name }) }
46-
}
47-
tasks.register("printCompileJars") {
48-
doLast { println(configurations.compileClasspath.get().files.map { it.name }) }
49-
}
5053
'''
51-
5254
file("app/src/test/java/com/example/AppTest.java") << '''
5355
package com.example;
5456
@@ -61,6 +63,15 @@ class GradleBuild {
6163
}
6264
}
6365
'''
66+
67+
libBuildFile << '''
68+
plugins {
69+
id("org.gradlex.java-module-dependencies")
70+
id("org.gradlex.java-module-testing")
71+
id("java-library")
72+
}
73+
group = "com.example"
74+
'''
6475
}
6576

6677
File file(String path) {

0 commit comments

Comments
 (0)