Skip to content

Commit

Permalink
Fixed #351 - JDK17+ Usage in Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khmarbaise committed Apr 14, 2023
1 parent 404e17c commit 0410566
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
import static com.soebes.itf.jupiter.extension.MavenProjectSources.ResourceUsage.NONE;
Expand All @@ -51,22 +49,22 @@
@MavenProjectSources(resourcesUsage = NONE)
class MavenProjectSourcesBasicIT {

private static final List<String> POM_STATIC = Arrays.asList(
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">",
"<modelVersion>4.0.0</modelVersion>",
" <groupId>project-sources-it</groupId>",
" <artifactId>project-sources-it-artifactid-001</artifactId>",
" <version>1.0.0</version>",
"</project>"
);
private static final String POM_STATIC = """
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project-sources-it</groupId>
<artifactId>project-sources-it-artifactid-001</artifactId>
<version>1.0.0</version>
</project>
""";

@BeforeEach
void beforeEach(TestInfo testInfo, MavenProjectResult result) throws IOException {
System.out.println("testInfo = " + testInfo);
System.out.println("method = " + testInfo.getTestMethod());
Path pomFile = result.getTargetProjectDirectory().resolve("pom.xml");
System.out.println("pomFile = " + pomFile);
Files.write(pomFile, POM_STATIC, StandardOpenOption.CREATE);
Files.writeString(pomFile, POM_STATIC, StandardOpenOption.CREATE);
}

@MavenTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;

Expand All @@ -47,22 +45,22 @@
@Programmatically
class MavenProjectSourcesMetaIT {

private static final List<String> POM_STATIC = Arrays.asList(
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">",
"<modelVersion>4.0.0</modelVersion>",
" <groupId>project-sources-it-meta-annotation</groupId>",
" <artifactId>project-sources-it-artifactid-001</artifactId>",
" <version>1.0.0</version>",
"</project>"
);
private static final String POM_STATIC = """
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project-sources-it-meta-annotation</groupId>
<artifactId>project-sources-it-artifactid-001</artifactId>
<version>1.0.0</version>
</project>
""";

@BeforeEach
void beforeEach(TestInfo testInfo, MavenProjectResult result) throws IOException {
System.out.println("testInfo = " + testInfo);
System.out.println("method = " + testInfo.getTestMethod());
Path pomFile = result.getTargetProjectDirectory().resolve("pom.xml");
System.out.println("pomFile = " + pomFile);
Files.write(pomFile, POM_STATIC, StandardOpenOption.CREATE);
Files.writeString(pomFile, POM_STATIC, StandardOpenOption.CREATE);
}

@MavenTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
import static com.soebes.itf.jupiter.extension.MavenProjectSources.ResourceUsage.NONE;
Expand All @@ -49,25 +47,25 @@
@MavenProjectSources(resourcesUsage = NONE)
class MavenProjectSourcesMoreComplexIT {

private List<String> generateProject(String info) {
return Arrays.asList(
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">",
"<modelVersion>4.0.0</modelVersion>",
" <groupId>project-sources-it</groupId>",
" <artifactId>" + String.format("%s", info) + "</artifactId>",
" <version>1.0.0</version>",
" <properties>",
" <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>",
" </properties>",
"</project>"
);
private String generateProject(String info) {
return """
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project-sources-it</groupId>
<artifactId>%s</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
""".formatted(info);
}
@BeforeEach
void beforeEach(TestInfo testInfo, MavenProjectResult result) throws IOException {
Class<?> testMethod = testInfo.getTestClass().orElseThrow(IllegalStateException::new);
String artifactId = testMethod.getName().replace('$', '_');
Path pomFile = result.getTargetProjectDirectory().resolve("pom.xml");
Files.write(pomFile, generateProject(artifactId), StandardOpenOption.CREATE);
Files.writeString(pomFile, generateProject(artifactId), StandardOpenOption.CREATE);
}

@MavenTest
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<maven.compiler.release>8</maven.compiler.release>
<maven.compiler.testRelease>17</maven.compiler.testRelease>
<smpp.component>maven-it-extension</smpp.component>
<!--
! Currently, javadoc fails based on module without test sources
Expand Down

0 comments on commit 0410566

Please sign in to comment.