Skip to content

Commit 099b607

Browse files
committed
chore: Sonarqube improvements
1 parent 4fd0530 commit 099b607

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

src/main/java/com/endava/cats/command/ExplainCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void displayErrorReason() {
6767
Arrays.stream(CatsResultFactory.Reason.values()).filter(reason -> reason.name()
6868
.toLowerCase(Locale.ROOT).contains(info.toLowerCase(Locale.ROOT)))
6969
.sorted()
70-
.forEach(reason -> logger.noFormat("* Reason {} - {}", reason.reason(), reason.description()));
70+
.forEach(reason -> logger.noFormat("* Reason {} - {}", reason.value(), reason.description()));
7171
}
7272

7373
private void displayFuzzerInfo() {

src/main/java/com/endava/cats/fuzzer/fields/base/TwoXXorFourXXReplaceStringsFuzzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void fuzz(FuzzingData data) {
4545
ResponseCodeFamily expectedResponseCodes = new ResponseCodeFamilyDynamic(List.of("2XX", "4XX"));
4646
fieldsIteratorExecutor.execute(
4747
FieldsIteratorExecutorContext.builder()
48-
.scenario("Replace fields with characters %s".formatted(this.typesOfDataSentToTheService()))
48+
.scenario("Replace fields with %s.".formatted(this.typesOfDataSentToTheService()))
4949
.fuzzingData(data).fuzzingStrategy(FuzzingStrategy.replace())
5050
.expectedResponseCode(expectedResponseCodes)
5151
.fuzzValueProducer(this.fuzzValueProducer())

src/main/java/com/endava/cats/model/CatsResultFactory.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface CatsResultFactory {
1515
*/
1616
static CatsResult createExpectedResponse(String receivedResponseCode) {
1717
String message = "Response matches expected result. Response code [%s] is documented and response body matches the corresponding schema.".formatted(receivedResponseCode);
18-
String reason = Reason.ALL_GOOD.description();
18+
String reason = Reason.ALL_GOOD.value();
1919

2020
return new CatsResult(message, reason);
2121
}
@@ -28,7 +28,7 @@ static CatsResult createExpectedResponse(String receivedResponseCode) {
2828
*/
2929
static CatsResult createNotMatchingResponseSchema(String receivedResponseCode) {
3030
String message = "Response does NOT match expected result. Response code [%s] is documented, but response body does NOT match the corresponding schema.".formatted(receivedResponseCode);
31-
String reason = Reason.NOT_MATCHING_RESPONSE_SCHEMA.description();
31+
String reason = Reason.NOT_MATCHING_RESPONSE_SCHEMA.value();
3232

3333
return new CatsResult(message, reason);
3434
}
@@ -42,7 +42,7 @@ static CatsResult createNotMatchingResponseSchema(String receivedResponseCode) {
4242
*/
4343
static CatsResult createNotMatchingContentType(List<String> expected, String actual) {
4444
String message = "Response content type not matching the contract: expected %s, actual [%s]".formatted(expected, actual);
45-
String reason = Reason.RESPONSE_CONTENT_TYPE_NOT_MATCHING.description();
45+
String reason = Reason.RESPONSE_CONTENT_TYPE_NOT_MATCHING.value();
4646
return new CatsResult(message, reason);
4747
}
4848

@@ -61,7 +61,7 @@ static CatsResult createNotImplemented() {
6161
* @return a CatsResult to use in reports
6262
*/
6363
static CatsResult createNotFound() {
64-
return new CatsResult("Response HTTP code 404: you might need to provide business context using --refData or --urlParams", Reason.NOT_FOUND.description());
64+
return new CatsResult("Response HTTP code 404: you might need to provide business context using --refData or --urlParams", Reason.NOT_FOUND.value());
6565
}
6666

6767
/**
@@ -73,7 +73,7 @@ static CatsResult createNotFound() {
7373
*/
7474
static CatsResult createResponseTimeExceedsMax(long receivedResponseTime, long maxResponseTime) {
7575
String message = "Test case executed successfully, but response time exceeds --maxResponseTimeInMs: actual %d, max %d".formatted(receivedResponseTime, maxResponseTime);
76-
String reason = Reason.RESPONSE_TIME_EXCEEDS_MAX.description();
76+
String reason = Reason.RESPONSE_TIME_EXCEEDS_MAX.value();
7777

7878
return new CatsResult(message, reason);
7979
}
@@ -87,7 +87,7 @@ static CatsResult createResponseTimeExceedsMax(long receivedResponseTime, long m
8787
*/
8888
static CatsResult createUnexpectedException(String fuzzer, String errorMessage) {
8989
String message = "Fuzzer [%s] failed due to [%s]".formatted(fuzzer, errorMessage);
90-
String reason = Reason.UNEXPECTED_EXCEPTION.description();
90+
String reason = Reason.UNEXPECTED_EXCEPTION.value();
9191

9292
return new CatsResult(message, reason);
9393
}
@@ -100,7 +100,7 @@ static CatsResult createUnexpectedException(String fuzzer, String errorMessage)
100100
*/
101101
static CatsResult createErrorLeaksDetectedInResponse(List<String> keywords) {
102102
String message = "The following keywords were detected in the response which might suggest an error details leak: %s".formatted(keywords);
103-
String reason = Reason.ERROR_LEAKS_DETECTED.description();
103+
String reason = Reason.ERROR_LEAKS_DETECTED.value();
104104

105105
return new CatsResult(message, reason);
106106
}
@@ -115,7 +115,7 @@ static CatsResult createErrorLeaksDetectedInResponse(List<String> keywords) {
115115
*/
116116
static CatsResult createUnexpectedBehaviour(String receivedResponseCode, String expectedResponseCode) {
117117
String message = "Unexpected behaviour: expected %s, actual [%s]".formatted(expectedResponseCode, receivedResponseCode);
118-
String reason = Reason.UNEXPECTED_BEHAVIOUR.description() + " %s".formatted(receivedResponseCode);
118+
String reason = Reason.UNEXPECTED_BEHAVIOUR.value() + " %s".formatted(receivedResponseCode);
119119

120120
return new CatsResult(message, reason);
121121
}
@@ -129,7 +129,7 @@ static CatsResult createUnexpectedBehaviour(String receivedResponseCode, String
129129
*/
130130
static CatsResult createUnexpectedResponseCode(String receivedResponseCode, String expectedResponseCode) {
131131
String message = "Response does NOT match expected result. Response code is NOT from a list of expected codes for this FUZZER: expected %s, actual [%s]".formatted(expectedResponseCode, receivedResponseCode);
132-
String reason = Reason.UNEXPECTED_RESPONSE_CODE.description() + ": %s".formatted(receivedResponseCode);
132+
String reason = Reason.UNEXPECTED_RESPONSE_CODE.value() + ": %s".formatted(receivedResponseCode);
133133

134134
return new CatsResult(message, reason);
135135
}
@@ -144,7 +144,7 @@ static CatsResult createUnexpectedResponseCode(String receivedResponseCode, Stri
144144
*/
145145
static CatsResult createUndocumentedResponseCode(String receivedResponseCode, String expectedResponseCode, String documentedResponseCodes) {
146146
String message = "Response does NOT match expected result. Response code is from a list of expected codes for this FUZZER, but it is undocumented: expected %s, actual [%s], documented response codes: %s".formatted(expectedResponseCode, receivedResponseCode, documentedResponseCodes);
147-
String reason = Reason.UNDOCUMENTED_RESPONSE_CODE.description() + ": %s".formatted(receivedResponseCode);
147+
String reason = Reason.UNDOCUMENTED_RESPONSE_CODE.value() + ": %s".formatted(receivedResponseCode);
148148

149149
return new CatsResult(message, reason);
150150
}
@@ -172,20 +172,20 @@ enum Reason {
172172
RESPONSE_CONTENT_TYPE_NOT_MATCHING("Response content type not matching the contract", "The response content type does not match the one defined in the OpenAPI contract"),
173173
UNEXPECTED_BEHAVIOUR("Unexpected behaviour", "CATS run the test case successfully, but the response code was not expected, nor documented, nor known to typically be documented");
174174

175-
private final String reason;
175+
private final String value;
176176
private final String description;
177177

178-
Reason(String reason, String description) {
179-
this.reason = reason;
178+
Reason(String value, String description) {
179+
this.value = value;
180180
this.description = description;
181181
}
182182

183183
public String description() {
184184
return description;
185185
}
186186

187-
public String reason() {
188-
return reason;
187+
public String value() {
188+
return value;
189189
}
190190
}
191191
}

src/test/java/com/endava/cats/command/GenerateCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GenerateCommandTest {
3333
ProcessingArguments processingArguments;
3434

3535
@BeforeEach
36-
public void init() {
36+
void init() {
3737
generateCommand = new GenerateCommand(fuzzingDataFactory, catsGlobalContext, processingArguments);
3838
}
3939

src/test/java/com/endava/cats/command/ReplayCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ReplayCommandTest {
2929
private TestCaseListener testCaseListener;
3030

3131
@BeforeEach
32-
public void setup() {
32+
void setup() {
3333
replayCommand = new ReplayCommand(serviceCaller, testCaseListener);
3434
replayCommand.authArgs = Mockito.mock(AuthArguments.class);
3535
ReflectionTestUtils.setField(testCaseListener, "testCaseExporter", Mockito.mock(TestCaseExporter.class));

src/test/java/com/endava/cats/fuzzer/fields/base/ExactValuesInFieldsFuzzerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExactValuesInFieldsFuzzerTest {
2626
private FilesArguments filesArguments;
2727

2828
@BeforeEach
29-
public void setup() {
29+
void setup() {
3030
filesArguments = Mockito.mock(FilesArguments.class);
3131
myBaseBoundaryFuzzer = new MyExactValueFuzzer(null, null, filesArguments);
3232
}

src/test/java/com/endava/cats/io/ServiceCallerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ServiceCallerTest {
5353
private ServiceCaller serviceCaller;
5454

5555
@BeforeAll
56-
public static void setup() {
56+
static void setup() {
5757
wireMockServer = new WireMockServer(new WireMockConfiguration().dynamicPort());
5858
wireMockServer.start();
5959
wireMockServer.stubFor(WireMock.get("/not-json").willReturn(WireMock.ok("<html>test</html>")));
@@ -74,12 +74,12 @@ public static void setup() {
7474
}
7575

7676
@AfterAll
77-
public static void clean() {
77+
static void clean() {
7878
wireMockServer.stop();
7979
}
8080

8181
@BeforeEach
82-
public void setupEach() throws Exception {
82+
void setupEach() throws Exception {
8383
filesArguments = new FilesArguments();
8484
TestCaseListener testCaseListener = Mockito.mock(TestCaseListener.class);
8585
serviceCaller = new ServiceCaller(catsGlobalContext, testCaseListener, filesArguments, authArguments, apiArguments, processingArguments);

src/test/java/com/endava/cats/util/VersionCheckerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ class VersionCheckerTest {
1717
private static VersionChecker versionChecker;
1818

1919
@BeforeAll
20-
public static void setup() {
20+
static void setup() {
2121
wireMockServer = new WireMockServer(new WireMockConfiguration().dynamicPort());
2222
wireMockServer.start();
2323
VersionChecker.baseUrl = "http://localhost:" + wireMockServer.port() + "/latest";
2424
}
2525

2626
@BeforeEach
27-
public void setupEach() {
27+
void setupEach() {
2828
versionChecker = new VersionChecker();
2929
}
3030

3131
@AfterAll
32-
public static void clean() {
32+
static void clean() {
3333
wireMockServer.stop();
3434
}
3535

0 commit comments

Comments
 (0)