Skip to content

Commit 9aae276

Browse files
committed
Add acceptance tests for avaje-inject
1 parent 1369cc8 commit 9aae276

File tree

9 files changed

+254
-1
lines changed

9 files changed

+254
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.github.ascopes.jct</groupId>
9+
<artifactId>acceptance-tests</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>acceptance-tests-avaje-inject</artifactId>
15+
16+
<properties>
17+
<avaje-inject.version>8.10</avaje-inject.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>${project.groupId}</groupId>
23+
<artifactId>java-compiler-testing</artifactId>
24+
<scope>test</scope>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>io.avaje</groupId>
29+
<artifactId>avaje-inject</artifactId>
30+
<version>${avaje-inject.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>io.avaje</groupId>
36+
<artifactId>avaje-inject-generator</artifactId>
37+
<version>${avaje-inject.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.apache.groovy</groupId>
43+
<artifactId>groovy</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.slf4j</groupId>
55+
<artifactId>slf4j-simple</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.codehaus.gmavenplus</groupId>
64+
<artifactId>gmavenplus-plugin</artifactId>
65+
</plugin>
66+
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-surefire-plugin</artifactId>
70+
71+
<configuration>
72+
<failIfNoTests>true</failIfNoTests>
73+
</configuration>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2022 - 2022 Ashley Scopes
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+
package io.github.ascopes.jct.acceptancetests.avajeinject
17+
18+
19+
import io.github.ascopes.jct.compilers.JctCompiler
20+
import io.github.ascopes.jct.filemanagers.LoggingMode
21+
import io.github.ascopes.jct.junit.JavacCompilerTest
22+
import io.github.ascopes.jct.workspaces.Workspaces
23+
import org.junit.jupiter.api.DisplayName
24+
25+
import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation
26+
27+
@DisplayName("Avaje Inject acceptance tests")
28+
class AvajeInjectTest {
29+
@DisplayName("Dependency injection code gets generated as expected")
30+
@JavacCompilerTest(modules = true)
31+
void dependencyInjectionCodeGetsGeneratedAsExpected(JctCompiler compiler) {
32+
// Given
33+
try (def workspace = Workspaces.newWorkspace()) {
34+
workspace
35+
.createSourcePathPackage()
36+
.rootDirectory()
37+
.copyContentsFrom("src", "test", "resources", "code")
38+
39+
// When
40+
def compilation = compiler
41+
.diagnosticLoggingMode(LoggingMode.STACKTRACES)
42+
.compile(workspace)
43+
44+
// Then
45+
assertThatCompilation(compilation)
46+
.isSuccessfulWithoutWarnings()
47+
.classOutput()
48+
.packages()
49+
.allFilesExist(
50+
'org/example/CoffeeMaker.class',
51+
'org/example/Grinder.class',
52+
'org/example/Pump.class',
53+
'org/example/CoffeeMaker$DI.class',
54+
'org/example/Grinder$DI.class',
55+
'org/example/Pump$DI.class',
56+
)
57+
}
58+
}
59+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2022 - 2022 Ashley Scopes
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+
module org.example {
17+
exports org.example;
18+
19+
requires io.avaje.inject;
20+
21+
provides io.avaje.inject.spi.Module with org.example.ExampleModule;
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2022 - 2022 Ashley Scopes
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+
package org.example;
17+
18+
import jakarta.inject.Inject;
19+
import jakarta.inject.Singleton;
20+
21+
/**
22+
* Makes coffee.
23+
*/
24+
@Singleton
25+
public class CoffeeMaker {
26+
27+
private final Grinder grinder;
28+
private final Pump pump;
29+
30+
@Inject
31+
public CoffeeMaker(Grinder grinder, Pump pump) {
32+
this.grinder = grinder;
33+
this.pump = pump;
34+
}
35+
36+
public void makeCoffee() {
37+
// ...
38+
}
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2022 - 2022 Ashley Scopes
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+
package org.example;
17+
18+
import jakarta.inject.Singleton;
19+
20+
/**
21+
* Grinds coffee.
22+
*/
23+
@Singleton
24+
public class Grinder {
25+
// ...
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2022 - 2022 Ashley Scopes
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+
package org.example;
17+
18+
import jakarta.inject.Singleton;
19+
20+
/**
21+
* Pumps coffee.
22+
*/
23+
@Singleton
24+
public class Pump {
25+
// ...
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
junit.jupiter.execution.parallel.enabled=true
2+
junit.jupiter.execution.parallel.mode.classes.default=SAME_THREAD
3+
junit.jupiter.execution.parallel.mode.default=CONCURRENT

acceptance-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<packaging>pom</packaging>
1616

1717
<modules>
18+
<module>acceptance-tests-avaje-inject</module>
1819
<module>acceptance-tests-checkerframework</module>
1920
<module>acceptance-tests-dagger</module>
2021
<module>acceptance-tests-error-prone</module>

java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public JctCompilationImpl build() {
149149
);
150150

151151
var outputLines = writer.toString().lines().collect(Collectors.toList());
152-
152+
153153
if (result == CompilationResult.SKIPPED) {
154154
LOGGER.warn("There was nothing to compile...");
155155
}

0 commit comments

Comments
 (0)