Skip to content

Commit

Permalink
Enable project to use JUnit5 in mix with JUnit4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsuter committed Jul 19, 2024
1 parent 76abf48 commit b0fa07d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<maven.version>3.6.3</maven.version>
<!-- version should match ivy Engine sfl4j version! And version in EngineClassLoaderFactory.SLF4J_VERSION -->
<slf4j.version>2.0.13</slf4j.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<site.path>snapshot</site.path>
<other.site.path>release</other.site.path>
<other.site.name>Stable</other.site.name>
Expand Down Expand Up @@ -164,9 +165,15 @@

<!-- TEST scoped -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
48 changes: 26 additions & 22 deletions src/test/java/ch/ivyteam/ivy/maven/engine/TestClasspathJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,42 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.nio.file.Path;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import ch.ivyteam.ivy.maven.util.ClasspathJar;

public class TestClasspathJar {
class TestClasspathJar {

@TempDir
Path tempDir;

@Test
public void readWriteClasspath() throws IOException {
File jarFile = Files.createTempFile("my", ".jar").toFile();
ClasspathJar jar = new ClasspathJar(jarFile);
File content = Files.createTempFile("content", ".jar").toFile();
jar.createFileEntries(Arrays.asList(content));

assertThat(jar.getClasspathFiles()).contains(content.getName());

ZipInputStream jarStream = new ZipInputStream(new FileInputStream(jarFile));
ZipEntry first = jarStream.getNextEntry();
assertThat(first.getName()).isEqualTo("META-INF/MANIFEST.MF");
String manifest = IOUtils.toString(jarStream, StandardCharsets.UTF_8);
assertThat(manifest)
.as("Manifest should not start with a whitespace or it will not be interpreted by the JVM")
.startsWith("Manifest-Version:");
void readWriteClasspath() throws IOException {
var jarFile = tempDir.resolve("my.jar");
Files.createFile(jarFile);
ClasspathJar jar = new ClasspathJar(jarFile.toFile());
var content = tempDir.resolve("content.jar");
Files.createFile(content);
jar.createFileEntries(List.of(content.toFile()));

assertThat(jar.getClasspathFiles()).contains(content.getFileName().toString());

try (var in = new ZipInputStream(Files.newInputStream(jarFile))) {
ZipEntry first = in.getNextEntry();
assertThat(first.getName()).isEqualTo("META-INF/MANIFEST.MF");
String manifest = new String(in.readAllBytes(), StandardCharsets.UTF_8);
assertThat(manifest)
.as("Manifest should not start with a whitespace or it will not be interpreted by the JVM")
.startsWith("Manifest-Version:");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,29 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.UUID;
import java.nio.file.Path;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import ch.ivyteam.ivy.maven.engine.EngineClassLoaderFactory.OsgiDir;

public class TestEngineVersionEvaluator {
class TestEngineVersionEvaluator {

@Test
public void isOSGiEngine_invalid() {
File tempDir = createTempDir();
assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir)).isFalse();
}
@TempDir
Path tempDir;

@Test
public void isOSGiEngine_valid() {
File tempDir = createTempDir();
File systemDir = new File(tempDir, OsgiDir.INSTALL_AREA);
systemDir.mkdir();
systemDir.deleteOnExit();
assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir)).isTrue();
void isOSGiEngine_invalid() {
assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir.toFile())).isFalse();
}

private static File createTempDir() {
try {
File tmpDir = Files.createTempDirectory(UUID.randomUUID().toString()).toFile();
tmpDir.deleteOnExit();
return tmpDir;
} catch (Exception e) {
throw new RuntimeException(e);
}
@Test
void isOSGiEngine_valid() throws IOException {
var systemDir = tempDir.resolve(OsgiDir.INSTALL_AREA);
Files.createDirectories(systemDir);
assertThat(EngineVersionEvaluator.isOSGiEngine(tempDir.toFile())).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import ch.ivyteam.ivy.maven.deploy.DeployToEngineMojo;
import ch.ivyteam.ivy.maven.deploy.DeployToEngineMojo.DefaultDeployOptions;

public class TestYamlOptionsFactory {
class TestYamlOptionsFactory {

@Test
public void yamlWithAllNonDefaultOptions() throws Exception {
void yamlWithAllNonDefaultOptions() throws Exception {
DeployToEngineMojo config = new DeployToEngineMojo();
config.deployTestUsers = "true";
config.deployTargetVersion = "RELEASED";
Expand All @@ -26,13 +25,13 @@ public void yamlWithAllNonDefaultOptions() throws Exception {
}

private String getFileContent(String file) throws IOException {
try (InputStream is = getClass().getResourceAsStream(file)) {
return IOUtils.toString(is, StandardCharsets.UTF_8);
try (var in = getClass().getResourceAsStream(file)) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
}

@Test
public void yamlWithAllDefaultOptions() throws Exception {
void yamlWithAllDefaultOptions() throws Exception {
DeployToEngineMojo config = new DeployToEngineMojo();
config.deployTestUsers = DefaultDeployOptions.DEPLOY_TEST_USERS;
config.deployTargetVersion = DefaultDeployOptions.VERSION_AUTO;
Expand Down

0 comments on commit b0fa07d

Please sign in to comment.