From b84ad89b8f324f654a3f75fd88e5ab10c02981bc Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Thu, 12 Sep 2024 10:35:30 +0200 Subject: [PATCH] Migrated assertions to assertj --- .../ruleunit/examples/multiunit/RuntimeTest.java | 6 +++--- .../pom.xml | 4 ++++ .../quarkus/test/hotreload/HotReloadIT.java | 16 ++++++---------- .../org/drools/quarkus/test/RuntimeTest.java | 13 +++++-------- .../quarkus/ruleunit/test/RuntimeTest.java | 5 ++--- .../KmoduleKieBaseModelsBuiltItem.java | 2 -- 6 files changed, 20 insertions(+), 26 deletions(-) diff --git a/drools-quarkus-extension/drools-quarkus-examples/drools-quarkus-examples-multiunit/src/test/java/org/drools/quarkus/ruleunit/examples/multiunit/RuntimeTest.java b/drools-quarkus-extension/drools-quarkus-examples/drools-quarkus-examples-multiunit/src/test/java/org/drools/quarkus/ruleunit/examples/multiunit/RuntimeTest.java index 4122df9325f..322207cea27 100644 --- a/drools-quarkus-extension/drools-quarkus-examples/drools-quarkus-examples-multiunit/src/test/java/org/drools/quarkus/ruleunit/examples/multiunit/RuntimeTest.java +++ b/drools-quarkus-extension/drools-quarkus-examples/drools-quarkus-examples-multiunit/src/test/java/org/drools/quarkus/ruleunit/examples/multiunit/RuntimeTest.java @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test; import org.kie.api.runtime.rule.FactHandle; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @QuarkusTest public class RuntimeTest { @@ -69,7 +69,7 @@ public void delete(DataHandle handle) { instance.fire(); - assertEquals("Hi 1", output.get().getText()); + assertThat(output.get().getText()).isEqualTo("Hi 1"); } @Test @@ -101,6 +101,6 @@ public void delete(DataHandle handle) { instance.fire(); - assertEquals("Hi 2", output.get().getText()); + assertThat(output.get().getText()).isEqualTo("Hi 2"); } } diff --git a/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/pom.xml b/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/pom.xml index e06d5791feb..7b406c931dc 100644 --- a/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/pom.xml +++ b/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/pom.xml @@ -54,6 +54,10 @@ io.quarkus quarkus-resteasy-jackson + + org.assertj + assertj-core + io.quarkus diff --git a/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/src/test/java/org/drools/quarkus/test/hotreload/HotReloadIT.java b/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/src/test/java/org/drools/quarkus/test/hotreload/HotReloadIT.java index 5e5de51d846..1d5bb063a0a 100644 --- a/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/src/test/java/org/drools/quarkus/test/hotreload/HotReloadIT.java +++ b/drools-quarkus-extension/drools-quarkus-integration-test-hotreload/src/test/java/org/drools/quarkus/test/hotreload/HotReloadIT.java @@ -28,8 +28,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class HotReloadIT { @@ -50,7 +49,7 @@ public class HotReloadIT { public void testServletChange() throws InterruptedException { String personsPayload = "[{\"name\":\"Mario\",\"age\":45,\"adult\":false},{\"name\":\"Sofia\",\"age\":17,\"adult\":false}]"; - List names = given() + List names = given() .baseUri("http://localhost:" + HTTP_TEST_PORT) .contentType(ContentType.JSON) .accept(ContentType.JSON) @@ -60,10 +59,9 @@ public void testServletChange() throws InterruptedException { .then() .statusCode(200) .extract() - .as(List.class); + .>as(List.class); - assertEquals(1, names.size()); - assertEquals("Mario", names.get(0)); + assertThat(names).hasSize(1).containsExactly("Mario"); test.modifyResourceFile(RESOURCE_FILE, s -> s.replaceAll("18", "16")); @@ -75,10 +73,8 @@ public void testServletChange() throws InterruptedException { .post("/find-adult") .then() .statusCode(200) - .extract().as(List.class); + .extract().>as(List.class); - assertEquals(2, names.size()); - assertTrue(names.contains("Mario")); - assertTrue(names.contains("Sofia")); + assertThat(names).hasSize(2).containsExactlyInAnyOrder("Mario", "Sofia"); } } diff --git a/drools-quarkus-extension/drools-quarkus-integration-test/src/test/java/org/drools/quarkus/test/RuntimeTest.java b/drools-quarkus-extension/drools-quarkus-integration-test/src/test/java/org/drools/quarkus/test/RuntimeTest.java index 96c380dd554..a6905fbdcef 100644 --- a/drools-quarkus-extension/drools-quarkus-integration-test/src/test/java/org/drools/quarkus/test/RuntimeTest.java +++ b/drools-quarkus-extension/drools-quarkus-integration-test/src/test/java/org/drools/quarkus/test/RuntimeTest.java @@ -30,8 +30,7 @@ import org.kie.api.runtime.KieRuntimeBuilder; import org.kie.api.runtime.KieSession; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.kie.api.prototype.PrototypeBuilder.prototype; @QuarkusTest @@ -58,16 +57,15 @@ public void testYamlEvaluation() { private void testSimpleDrl(KieSession ksession, String assetPackage) { List pkgNames = ksession.getKieBase().getKiePackages().stream().map(KiePackage::getName).collect(Collectors.toList()); - assertEquals(2, pkgNames.size()); - assertTrue(pkgNames.contains("org.drools.quarkus.test")); - assertTrue(pkgNames.contains(assetPackage)); + + assertThat(pkgNames).hasSize(2).containsExactlyInAnyOrder("org.drools.quarkus.test", assetPackage); Result result = new Result(); ksession.insert(result); ksession.insert(new Person("Mark", 17)); ksession.fireAllRules(); - assertEquals("Mark can NOT drink", result.toString()); + assertThat(result.toString()).isEqualTo("Mark can NOT drink"); } @Test @@ -85,7 +83,6 @@ public void testPrototypeEvaluation() { ksession.insert(result); ksession.fireAllRules(); - - assertEquals("Mark can NOT drink", result.get("value")); + assertThat(result.get("value")).isEqualTo("Mark can NOT drink"); } } diff --git a/drools-quarkus-extension/drools-quarkus-ruleunit-integration-test/src/test/java/org/drools/quarkus/ruleunit/test/RuntimeTest.java b/drools-quarkus-extension/drools-quarkus-ruleunit-integration-test/src/test/java/org/drools/quarkus/ruleunit/test/RuntimeTest.java index 873e112e293..1ac86e8100d 100644 --- a/drools-quarkus-extension/drools-quarkus-ruleunit-integration-test/src/test/java/org/drools/quarkus/ruleunit/test/RuntimeTest.java +++ b/drools-quarkus-extension/drools-quarkus-ruleunit-integration-test/src/test/java/org/drools/quarkus/ruleunit/test/RuntimeTest.java @@ -25,7 +25,7 @@ import jakarta.inject.Inject; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @QuarkusTest public class RuntimeTest { @@ -42,7 +42,6 @@ public void testRuleUnit() { instance.fire(); } - assertEquals(1, unit.getResults().size()); - assertEquals("Hello Mario", unit.getResults().get(0)); + assertThat(unit.getResults()).hasSize(1).containsExactly("Hello Mario"); } } diff --git a/drools-quarkus-extension/drools-quarkus-util-deployment/src/main/java/org/drools/quarkus/util/deployment/KmoduleKieBaseModelsBuiltItem.java b/drools-quarkus-extension/drools-quarkus-util-deployment/src/main/java/org/drools/quarkus/util/deployment/KmoduleKieBaseModelsBuiltItem.java index d437bc3dc8a..797b46ab81d 100644 --- a/drools-quarkus-extension/drools-quarkus-util-deployment/src/main/java/org/drools/quarkus/util/deployment/KmoduleKieBaseModelsBuiltItem.java +++ b/drools-quarkus-extension/drools-quarkus-util-deployment/src/main/java/org/drools/quarkus/util/deployment/KmoduleKieBaseModelsBuiltItem.java @@ -19,8 +19,6 @@ package org.drools.quarkus.util.deployment; import java.util.Collection; -import java.util.Map; -import java.util.Set; import org.kie.api.builder.model.KieBaseModel;