From 13f0039d74101ac051d57c93022412bcf955db2b Mon Sep 17 00:00:00 2001 From: Sashir Estela Date: Sun, 7 Apr 2024 19:52:24 +0000 Subject: [PATCH] Fixing race conditions on unit tests --- .../sashirestela/cleverclient/http/HttpProcessorTest.java | 2 ++ .../cleverclient/support/CleverClientSSETest.java | 5 ++++- src/test/resources/junit-platform.properties | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/junit-platform.properties diff --git a/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java b/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java index eec3823..acc9907 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java @@ -4,6 +4,7 @@ import io.github.sashirestela.cleverclient.support.Configurator; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; @@ -30,6 +31,7 @@ import static org.mockito.Mockito.when; @SuppressWarnings("unchecked") +@Order(2) class HttpProcessorTest { HttpProcessor httpProcessor; diff --git a/src/test/java/io/github/sashirestela/cleverclient/support/CleverClientSSETest.java b/src/test/java/io/github/sashirestela/cleverclient/support/CleverClientSSETest.java index 1e3ee90..c260d0d 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/support/CleverClientSSETest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/support/CleverClientSSETest.java @@ -2,12 +2,14 @@ import io.github.sashirestela.cleverclient.support.CleverClientSSE.LineRecord; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; +@Order(1) class CleverClientSSETest { Set events = Set.of("process", "process2"); @@ -36,7 +38,8 @@ void shouldReturnExpectedValueWhenRawDataMeetsConditions() { var event = (CleverClientSSE) data[0]; var actualCondition = event.isActualData(); var expectedCondition = (boolean) data[1]; - assertEquals(expectedCondition, actualCondition); + assertEquals(expectedCondition, actualCondition, "For data '" + event.getActualData() + + "' was expecting " + expectedCondition + " but was " + actualCondition); } } diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties new file mode 100644 index 0000000..f61913b --- /dev/null +++ b/src/test/resources/junit-platform.properties @@ -0,0 +1,2 @@ +# ClassOrderer$OrderAnnotation sorts classes based on their @Order annotation +junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$OrderAnnotation \ No newline at end of file