Skip to content

Commit 9465f32

Browse files
fix: Sonar cloud issues fix (#16)
1 parent 465fb64 commit 9465f32

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

.github/workflows/code-review.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: SonarCloud Analysis
22

33
on:
4+
push:
5+
branches:
6+
- main
47
pull_request:
58
types:
69
- opened

src/main/java/it/gov/pagopa/message/core/dto/CitizenConsentDTO.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package it.gov.pagopa.message.core.dto;
22

33
import com.fasterxml.jackson.annotation.JsonAlias;
4-
import lombok.AllArgsConstructor;
54
import lombok.Data;
65
import lombok.NoArgsConstructor;
76
import lombok.experimental.SuperBuilder;
@@ -10,7 +9,6 @@
109

1110
@Data
1211
@SuperBuilder
13-
@AllArgsConstructor
1412
@NoArgsConstructor
1513
public class CitizenConsentDTO {
1614
@JsonAlias("fiscalCode")

src/test/java/it/gov/pagopa/common/utils/UtilsTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ class UtilsTest {
2121

2222

2323
@Test
24-
void createSHA256_Ko_NoSuchAlgorithm() throws NoSuchAlgorithmException {
24+
void createSHA256_Ko_NoSuchAlgorithm() {
2525
try (MockedStatic<MessageDigest> mockedStatic = Mockito.mockStatic(MessageDigest.class)) {
2626
mockedStatic.when(() -> MessageDigest.getInstance(any()))
27-
.thenThrow(NoSuchAlgorithmException.class);
27+
.thenThrow(new NoSuchAlgorithmException("SHA-256 not available"));
2828

2929
EmdEncryptionException exception = assertThrows(EmdEncryptionException.class, () -> Utils.createSHA256(""));
30+
31+
assertEquals("SHA-256 not available", exception.getCause().getMessage());
3032
}
3133
}
32-
3334
@Test
3435
void createSHA256_Ok(){
3536
String toHash = "RSSMRA98B18L049O";

src/test/java/it/gov/pagopa/common/web/exception/ValidationExceptionHandlerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static class ValidationDTO {
5959
private String data;
6060
}
6161

62-
private final ValidationDTO VALIDATION_DTO = new ValidationDTO("data");
62+
private final ValidationDTO validationDTO = new ValidationDTO("data");
6363

6464
@Test
6565
void handleMethodArgumentNotValidException() throws Exception {
@@ -79,7 +79,7 @@ void handleMissingRequestHeaderException() throws Exception {
7979

8080
mockMvc.perform(MockMvcRequestBuilders.put("/test")
8181
.contentType(MediaType.APPLICATION_JSON)
82-
.content(objectMapper.writeValueAsString(VALIDATION_DTO))
82+
.content(objectMapper.writeValueAsString(validationDTO))
8383
.accept(MediaType.APPLICATION_JSON))
8484
.andExpect(MockMvcResultMatchers.status().isBadRequest())
8585
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value("INVALID_REQUEST"))

src/test/java/it/gov/pagopa/message/core/event/producer/MessageErrorProducerTest.java

-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.junit.jupiter.api.Test;
88
import org.junit.jupiter.api.extension.ExtendWith;
99
import org.mockito.ArgumentCaptor;
10-
import org.mockito.Captor;
1110
import org.mockito.InjectMocks;
1211
import org.mockito.Mock;
1312
import org.mockito.junit.jupiter.MockitoExtension;
@@ -31,8 +30,6 @@ class MessageErrorProducerTest {
3130
private ScheduledExecutorService scheduler;
3231
@InjectMocks
3332
private MessageErrorProducer messageErrorProducer;
34-
@Captor
35-
private ArgumentCaptor<Runnable> runnableCaptor;
3633

3734
@Test
3835
void testStreamBridgeSendCalled() throws Exception {
@@ -51,14 +48,11 @@ void testStreamBridgeSendCalled() throws Exception {
5148
ArgumentCaptor<Callable<Object>> runnableCaptor = ArgumentCaptor.forClass(Callable.class);
5249
when(scheduler.schedule(runnableCaptor.capture(), eq(5L), eq(TimeUnit.SECONDS))).thenReturn(null);
5350

54-
// Act
5551
messageErrorProducer.sendToMessageErrorQueue(message);
5652

57-
// Run the captured Runnable immediately
5853
Callable<Object> capturedRunnable = runnableCaptor.getValue();
5954
capturedRunnable.call();
6055

61-
// Assert
6256
verify(scheduler).schedule(any(Callable.class), eq(5L), eq(TimeUnit.SECONDS));
6357
verify(streamBridge, times(1)).send(eq("messageSender-out-0"), any(), eq(message));
6458

src/test/java/it/gov/pagopa/message/core/service/CitizenServiceTest.java

+19-24
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void createCitizenConsent_Ko_EmdEncryptError(){
6363
mockedStatic.when(() -> Utils.createSHA256(any()))
6464
.thenThrow(EmdEncryptionException.class);
6565

66-
EmdEncryptionException exception = assertThrows(EmdEncryptionException.class, () -> citizenService.createCitizenConsent(citizenConsentDTO));
66+
assertThrows(EmdEncryptionException.class, () -> citizenService.createCitizenConsent(citizenConsentDTO));
67+
6768
}
6869
}
6970

@@ -83,26 +84,14 @@ void deleteCitizenConsent_Ok(){
8384
@Test
8485
void deleteCitizenConsent_Ko_UserNotOnboarded(){
8586
CitizenConsentDTO citizenConsentDTO = CitizenConsentDTOFaker.mockInstance(false);
86-
87+
String hashedFiscalCode = citizenConsentDTO.getHashedFiscalCode();
88+
String channelId = citizenConsentDTO.getChannelId();
8789
Mockito.when(citizenRepository
8890
.findByHashedFiscalCodeAndChannelId(Utils.createSHA256(citizenConsentDTO.getHashedFiscalCode()),citizenConsentDTO.getChannelId()))
8991
.thenReturn(null);
9092

9193
assertThrows(UserNotOnboardedException.class, () ->
92-
citizenService.deleteCitizenConsent(citizenConsentDTO.getHashedFiscalCode(),citizenConsentDTO.getChannelId()));
93-
}
94-
95-
@Test
96-
void deleteCitizenConsent_Ko_EmdEncryptError(){
97-
CitizenConsentDTO citizenConsentDTO = CitizenConsentDTOFaker.mockInstance(true);
98-
99-
try (MockedStatic<Utils> mockedStatic = Mockito.mockStatic(Utils.class)) {
100-
mockedStatic.when(() -> Utils.createSHA256(any()))
101-
.thenThrow(EmdEncryptionException.class);
102-
103-
assertThrows(EmdEncryptionException.class, () ->
104-
citizenService.deleteCitizenConsent(citizenConsentDTO.getHashedFiscalCode(),citizenConsentDTO.getChannelId()));
105-
}
94+
citizenService.deleteCitizenConsent(hashedFiscalCode,channelId));
10695
}
10796

10897
@Test
@@ -118,27 +107,33 @@ void updateCitizenConsent_Ok(){
118107
}
119108

120109
@Test
121-
void updateCitizenConsent_Ko_UserNotOnboarded(){
110+
void updateCitizenConsent_Ko_UserNotOnboarded() {
111+
122112
CitizenConsentDTO citizenConsentDTO = CitizenConsentDTOFaker.mockInstance(true);
123113

124-
Mockito.when(citizenRepository
125-
.findByHashedFiscalCodeAndChannelId(Utils.createSHA256(citizenConsentDTO.getHashedFiscalCode()),citizenConsentDTO.getChannelId()))
126-
.thenReturn(null);
114+
String hashedFiscalCode = citizenConsentDTO.getHashedFiscalCode();
115+
String channelId = citizenConsentDTO.getChannelId();
127116

128-
assertThrows(UserNotOnboardedException.class, () ->
129-
citizenService.updateCitizenConsent(citizenConsentDTO.getHashedFiscalCode(),citizenConsentDTO.getChannelId()));
117+
Mockito.when(citizenRepository.findByHashedFiscalCodeAndChannelId(hashedFiscalCode, channelId))
118+
.thenReturn(null);
119+
120+
assertThrows(UserNotOnboardedException.class, () -> {
121+
citizenService.updateCitizenConsent(hashedFiscalCode, channelId);
122+
});
130123
}
131124

132125
@Test
133-
void updateCitizenConsent_Ko_EmdEncryptError(){
126+
void citizenConsent_Ko_EmdEncryptError(){
134127
CitizenConsentDTO citizenConsentDTO = CitizenConsentDTOFaker.mockInstance(true);
128+
String hashedFiscalCode = citizenConsentDTO.getHashedFiscalCode();
129+
String channelId = citizenConsentDTO.getChannelId();
135130

136131
try (MockedStatic<Utils> mockedStatic = Mockito.mockStatic(Utils.class)) {
137132
mockedStatic.when(() -> Utils.createSHA256(any()))
138133
.thenThrow(EmdEncryptionException.class);
139134

140135
assertThrows(EmdEncryptionException.class, () ->
141-
citizenService.deleteCitizenConsent(citizenConsentDTO.getHashedFiscalCode(),citizenConsentDTO.getChannelId()));
136+
citizenService.deleteCitizenConsent(hashedFiscalCode, channelId));
142137
}
143138
}
144139
}

0 commit comments

Comments
 (0)