From 88006a4304662ac8dbd510f2791c0b1703d8b9e4 Mon Sep 17 00:00:00 2001 From: Yuxin Deng Date: Sun, 23 Nov 2025 21:28:11 -0500 Subject: [PATCH] fixed sonarqube returned error --- docker-compose.yml | 10 ++++++++++ .../samples/petclinic/MySqlIntegrationTests.java | 7 +++++-- .../samples/petclinic/PetClinicIntegrationTests.java | 7 +++++-- .../samples/petclinic/PostgresIntegrationTests.java | 7 +++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 25bb0a3b7..faabb5e7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,16 @@ services: - devops-net depends_on: - sonarqube + postgres: + image: postgres:16 + environment: + POSTGRES_DB: petclinic + POSTGRES_USER: petclinic + POSTGRES_PASSWORD: petclinic + ports: + - "5432:5432" + networks: + - devops-net sonarqube: image: sonarqube:lts-community diff --git a/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java index 607593aad..82a4cfa0f 100644 --- a/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java +++ b/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java @@ -60,8 +60,11 @@ class MySqlIntegrationTests { @Test void testFindAll() { - vets.findAll(); - vets.findAll(); // served from cache + var firstCall = vets.findAll(); + assertThat(firstCall).isNotEmpty(); + + var secondCall = vets.findAll(); // served from cache + assertThat(secondCall).hasSameSizeAs(firstCall); } @Test diff --git a/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java index 8c0451dfd..fe40651df 100644 --- a/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java +++ b/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java @@ -45,8 +45,11 @@ public class PetClinicIntegrationTests { @Test void testFindAll() { - vets.findAll(); - vets.findAll(); // served from cache + var firstCall = vets.findAll(); + assertThat(firstCall).isNotEmpty(); + + var secondCall = vets.findAll(); // served from cache + assertThat(secondCall).hasSameSizeAs(firstCall); } @Test diff --git a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java index f3c5181e7..65869f620 100644 --- a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java +++ b/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java @@ -80,8 +80,11 @@ public class PostgresIntegrationTests { @Test void testFindAll() throws Exception { - vets.findAll(); - vets.findAll(); // served from cache + var firstCall = vets.findAll(); + assertThat(firstCall).isNotEmpty(); + + var secondCall = vets.findAll(); // served from cache + assertThat(secondCall).hasSameSizeAs(firstCall); } @Test