From 4a5bca195d368222b3b1d6fa3e2c03ac5a627f88 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Mon, 6 Nov 2023 05:37:35 +0000 Subject: [PATCH] fix: sonar issues --- .../learning/awspring/domain/FileInfo.java | 27 ++++++++++--------- .../repository/FileInfoRepositoryTest.java | 6 ++--- .../SchemaValidationIntegrationTest.java | 4 +-- .../awspring/web/listener/SQSListener.java | 2 +- .../services/InboundLogServiceTest.java | 7 +++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/aws-s3-project/src/main/java/com/learning/awspring/domain/FileInfo.java b/aws-s3-project/src/main/java/com/learning/awspring/domain/FileInfo.java index 7028a917..e05094db 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/domain/FileInfo.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/domain/FileInfo.java @@ -36,28 +36,31 @@ public FileInfo(String fileName, String fileUrl, boolean isUploadSuccessFull) { @Override public final boolean equals(Object o) { - if (this == o) return true; - if (o == null) return false; + if (this == o) { + return true; + } + if (o == null) { + return false; + } Class oEffectiveClass = - o instanceof HibernateProxy - ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() + o instanceof HibernateProxy hibernateProxy + ? hibernateProxy.getHibernateLazyInitializer().getPersistentClass() : o.getClass(); Class thisEffectiveClass = - this instanceof HibernateProxy - ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() + this instanceof HibernateProxy hibernateProxy + ? hibernateProxy.getHibernateLazyInitializer().getPersistentClass() : this.getClass(); - if (thisEffectiveClass != oEffectiveClass) return false; + if (thisEffectiveClass != oEffectiveClass) { + return false; + } FileInfo fileInfo = (FileInfo) o; return getId() != null && Objects.equals(getId(), fileInfo.getId()); } @Override public final int hashCode() { - return this instanceof HibernateProxy - ? ((HibernateProxy) this) - .getHibernateLazyInitializer() - .getPersistentClass() - .hashCode() + return this instanceof HibernateProxy hibernateProxy + ? hibernateProxy.getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode(); } } diff --git a/aws-s3-project/src/test/java/com/learning/awspring/repository/FileInfoRepositoryTest.java b/aws-s3-project/src/test/java/com/learning/awspring/repository/FileInfoRepositoryTest.java index c1427455..6f983516 100644 --- a/aws-s3-project/src/test/java/com/learning/awspring/repository/FileInfoRepositoryTest.java +++ b/aws-s3-project/src/test/java/com/learning/awspring/repository/FileInfoRepositoryTest.java @@ -11,14 +11,14 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; @DataJpaTest -public class FileInfoRepositoryTest { +class FileInfoRepositoryTest { @Autowired private TestEntityManager entityManager; @Autowired private FileInfoRepository fileInfoRepository; @Test - public void testFindByFileName() { + void testFindByFileName() { FileInfo fileInfo = new FileInfo(); fileInfo.setFileName("test"); fileInfo.setFileUrl("testUrl"); @@ -29,7 +29,7 @@ public void testFindByFileName() { } @Test - public void testExistsByFileName() { + void testExistsByFileName() { FileInfo fileInfo = new FileInfo(); fileInfo.setFileName("test"); fileInfo.setFileUrl("testUrl"); diff --git a/aws-secretmanager-project/src/test/java/com/example/awsspring/repositories/SchemaValidationIntegrationTest.java b/aws-secretmanager-project/src/test/java/com/example/awsspring/repositories/SchemaValidationIntegrationTest.java index 0f8b7acd..072197a4 100644 --- a/aws-secretmanager-project/src/test/java/com/example/awsspring/repositories/SchemaValidationIntegrationTest.java +++ b/aws-secretmanager-project/src/test/java/com/example/awsspring/repositories/SchemaValidationIntegrationTest.java @@ -14,12 +14,12 @@ @DataJpaTest(properties = "spring.jpa.hibernate.ddl-auto=validate") @AutoConfigureTestDatabase(replace = Replace.NONE) @ImportTestcontainers(DBTestContainer.class) -public class SchemaValidationIntegrationTest { +class SchemaValidationIntegrationTest { @Autowired private DataSource dataSource; @Test - public void testSchemaValidity() { + void testSchemaValidity() { Assertions.assertThat(dataSource).isInstanceOf(HikariDataSource.class); } } diff --git a/aws-sqs-project/src/main/java/com/learning/awspring/web/listener/SQSListener.java b/aws-sqs-project/src/main/java/com/learning/awspring/web/listener/SQSListener.java index 7bcbcd29..108a84fe 100644 --- a/aws-sqs-project/src/main/java/com/learning/awspring/web/listener/SQSListener.java +++ b/aws-sqs-project/src/main/java/com/learning/awspring/web/listener/SQSListener.java @@ -52,7 +52,7 @@ public void readMessageFromSqs(List> payloadMessageLi snsMessage.getPayload())); return inboundLog; }) - .collect(Collectors.toList()); + .toList(); inboundLogService.saveAllMessagesToDatabase(inBoundLogList); } } diff --git a/aws-sqs-project/src/test/java/com/learning/awspring/services/InboundLogServiceTest.java b/aws-sqs-project/src/test/java/com/learning/awspring/services/InboundLogServiceTest.java index 886ab63c..8d00ad94 100644 --- a/aws-sqs-project/src/test/java/com/learning/awspring/services/InboundLogServiceTest.java +++ b/aws-sqs-project/src/test/java/com/learning/awspring/services/InboundLogServiceTest.java @@ -63,8 +63,7 @@ void findInboundLogById() { assertThat(optionalInboundLog).isPresent(); InboundLog inboundLog = optionalInboundLog.get(); assertThat(inboundLog.getId()).isEqualTo(1L); - assertThat(inboundLog.getMessageId().toString()) - .isEqualTo("4594f2c9-5f88-4472-9229-1b31d867ae71"); + assertThat(inboundLog.getMessageId()).hasToString("4594f2c9-5f88-4472-9229-1b31d867ae71"); } @Test @@ -76,8 +75,8 @@ void saveInboundLog() { // then assertThat(persistedInboundLog).isNotNull(); assertThat(persistedInboundLog.getId()).isEqualTo(1L); - assertThat(persistedInboundLog.getMessageId().toString()) - .isEqualTo("4594f2c9-5f88-4472-9229-1b31d867ae71"); + assertThat(persistedInboundLog.getMessageId()) + .hasToString("4594f2c9-5f88-4472-9229-1b31d867ae71"); } @Test