diff --git a/pom.xml b/pom.xml
index 76209763..51c810ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,6 +182,12 @@
3.26.3
test
+
+ org.awaitility
+ awaitility
+ 4.2.1
+ test
+
org.apache.maven.plugin-testing
maven-plugin-testing-harness
diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java
index 4ec7d797..5ae30929 100644
--- a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java
+++ b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java
@@ -2,21 +2,20 @@
import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.simple.SimpleLogger;
import ch.ivyteam.ivy.maven.engine.Slf4jSimpleEngineProperties;
-public class TestSlf4jWarningConfiguration {
+class TestSlf4jWarningConfiguration {
/*
* XIVY-3123 Streamline the log output to be maven-like, instead of logging
* [WARN] we want [WARNING]. This allows us to use the maven log parser on our
* jenkins pipelines to avoid introducing new warnings.
*/
@Test
- public void mavenLikeWarning() {
+ void mavenLikeWarning() {
Slf4jSimpleEngineProperties.install();
-
assertThat(System.getProperty(SimpleLogger.WARN_LEVEL_STRING_KEY))
.as("SLF4J warning string is not maven-like [WARNING]")
.isEqualTo("WARNING");
diff --git a/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java b/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java
index b030adba..3d91dcc8 100644
--- a/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java
+++ b/src/test/java/ch/ivyteam/ivy/maven/engine/deploy/dir/TestFileLogForwarder.java
@@ -17,42 +17,47 @@
package ch.ivyteam.ivy.maven.engine.deploy.dir;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
-import java.io.File;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import ch.ivyteam.ivy.maven.log.LogCollector;
import ch.ivyteam.ivy.maven.log.LogCollector.LogEntry;
-public class TestFileLogForwarder {
+class TestFileLogForwarder {
+
+ @TempDir
+ Path tempDir;
@Test
- public void fileToMavenLog() throws Exception {
- File fakeEngineLog = Files.createTempFile("myProject.iar", ".deploymentLog").toFile();
- LogCollector mavenLog = new LogCollector();
- FileLogForwarder logForwarder = new FileLogForwarder(fakeEngineLog, mavenLog,
- new EngineLogLineHandler(mavenLog));
+ void fileToMavenLog() throws Exception {
+ var fakeEngineLog = tempDir.resolve("myProject.iar.deploymentLog");
+ Files.createFile(fakeEngineLog);
+ var mavenLog = new LogCollector();
+ var logForwarder = new FileLogForwarder(fakeEngineLog.toFile(), mavenLog, new EngineLogLineHandler(mavenLog));
+ var log = new FakeLogger(fakeEngineLog);
try {
logForwarder.activate();
- logAndWait(fakeEngineLog, "WARNING: starting");
- assertThat(mavenLog.getWarnings()).hasSize(1);
+ log.write("WARNING: starting");
+ await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(1));
LogEntry firstEntry = mavenLog.getWarnings().get(mavenLog.getWarnings().size() - 1);
assertThat(firstEntry.toString()).isEqualTo(" ENGINE: starting");
- logAndWait(fakeEngineLog, "WARNING: finished");
- assertThat(mavenLog.getWarnings()).hasSize(2);
+ log.write("WARNING: finished");
+ await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(2));
LogEntry lastEntry = mavenLog.getWarnings().get(mavenLog.getWarnings().size() - 1);
assertThat(lastEntry.toString()).isEqualTo(" ENGINE: finished");
- logAndWait(fakeEngineLog, "INFO: hi");
- assertThat(mavenLog.getDebug()).hasSize(1);
+ log.write("INFO: hi");
+ await().untilAsserted(() -> assertThat(mavenLog.getDebug()).hasSize(1));
LogEntry debugEntry = mavenLog.getDebug().get(mavenLog.getDebug().size() - 1);
assertThat(debugEntry.toString()).isEqualTo(" ENGINE: hi");
@@ -60,14 +65,24 @@ public void fileToMavenLog() throws Exception {
logForwarder.deactivate();
}
- logAndWait(fakeEngineLog, "WARNING: illegal");
- assertThat(mavenLog.getWarnings()).hasSize(2);
+ log.write("WARNING: illegal");
+ await().untilAsserted(() -> assertThat(mavenLog.getWarnings()).hasSize(2));
}
- private static void logAndWait(File fakeEngineLog, String log) throws IOException, InterruptedException {
- boolean append = true;
- FileUtils.write(fakeEngineLog, log, StandardCharsets.UTF_8, append);
- Thread.sleep(1000);
- }
+ private static final class FakeLogger {
+ private final Path file;
+
+ private FakeLogger(Path file) {
+ this.file = file;
+ }
+
+ private void write(String log) {
+ try {
+ Files.writeString(file, log, StandardOpenOption.APPEND);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
}
diff --git a/src/test/java/ch/ivyteam/ivy/maven/engine/download/TestLatestMinorVersionRange.java b/src/test/java/ch/ivyteam/ivy/maven/engine/download/TestLatestMinorVersionRange.java
index 0993911c..c5e53e7b 100644
--- a/src/test/java/ch/ivyteam/ivy/maven/engine/download/TestLatestMinorVersionRange.java
+++ b/src/test/java/ch/ivyteam/ivy/maven/engine/download/TestLatestMinorVersionRange.java
@@ -3,12 +3,12 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestLatestMinorVersionRange {
+class TestLatestMinorVersionRange {
@Test
- public void get() {
+ void get() {
assertThat(new LatestMinorVersionRange("8.0.0").get().toString()).isEqualTo("[8.0.0,8.1.0)");
assertThat(new LatestMinorVersionRange("8.0.1").get().toString()).isEqualTo("[8.0.1,8.1.0)");
assertThat(new LatestMinorVersionRange("8.1.0").get().toString()).isEqualTo("[8.1.0,8.2.0)");