Skip to content

Commit f2cedae

Browse files
ChrisEdwardsclaude
andcommitted
Fix string concatenation in AssessServiceIntegrationTest logging (AIML-231)
Replace all string concatenation in log statements with SLF4J placeholders for better performance. String concatenation in logs is inefficient because the concatenation happens before checking if the log level is enabled. Changes: - Replace log.info("text " + var) with log.info("text {}", var) - Apply to all test methods: testEnvironmentsAndTagsArePopulated, testSessionMetadataIsPopulated, testVulnTagsWithSpacesHandledBySDK, testListVulnsByAppIdWithSessionMetadata, and testListVulnsByAppIdForLatestSession 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0267541 commit f2cedae

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

src/test/java/com/contrast/labs/ai/mcp/contrast/AssessServiceIntegrationTest.java

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void testEnvironmentsAndTagsArePopulated() throws IOException {
6868
assertThat(response).as("Response should not be null").isNotNull();
6969
assertThat(response.items()).as("Should have at least one vulnerability").isNotEmpty();
7070

71-
log.info("Retrieved " + response.items().size() + " vulnerabilities");
71+
log.info("Retrieved {} vulnerabilities", response.items().size());
7272

7373
// Analyze first few vulnerabilities
7474
int withEnvironments = 0;
@@ -79,26 +79,25 @@ void testEnvironmentsAndTagsArePopulated() throws IOException {
7979
assertThat(vuln.tags()).as("Tags should never be null").isNotNull();
8080

8181
// Debug: Show all environment and tag data
82-
log.info("Vuln " + vuln.vulnID() + ":");
83-
log.info(
84-
" environments: " + vuln.environments() + " (size: " + vuln.environments().size() + ")");
85-
log.info(" tags: " + vuln.tags() + " (size: " + vuln.tags().size() + ")");
82+
log.info("Vuln {}:", vuln.vulnID());
83+
log.info(" environments: {} (size: {})", vuln.environments(), vuln.environments().size());
84+
log.info(" tags: {} (size: {})", vuln.tags(), vuln.tags().size());
8685

8786
if (!vuln.environments().isEmpty()) {
8887
withEnvironments++;
89-
log.info(" ✓ Has environments: " + vuln.environments());
88+
log.info(" ✓ Has environments: {}", vuln.environments());
9089
}
9190

9291
if (!vuln.tags().isEmpty()) {
9392
withTags++;
94-
log.info(" ✓ Has tags: " + vuln.tags());
93+
log.info(" ✓ Has tags: {}", vuln.tags());
9594
}
9695
}
9796

9897
log.info("\nResults:");
9998
log.info(
100-
" Vulnerabilities with environments: " + withEnvironments + "/" + response.items().size());
101-
log.info(" Vulnerabilities with tags: " + withTags + "/" + response.items().size());
99+
" Vulnerabilities with environments: {}/{}", withEnvironments, response.items().size());
100+
log.info(" Vulnerabilities with tags: {}/{}", withTags, response.items().size());
102101

103102
// At least verify the fields are being returned (even if empty)
104103
// This ensures the API is returning the fields and they're being deserialized
@@ -134,7 +133,7 @@ void testSessionMetadataIsPopulated() throws IOException {
134133
assertThat(response).as("Response should not be null").isNotNull();
135134
assertThat(response.items()).as("Should have at least one vulnerability").isNotEmpty();
136135

137-
log.info("Retrieved " + response.items().size() + " vulnerabilities");
136+
log.info("Retrieved {} vulnerabilities", response.items().size());
138137

139138
// Analyze session metadata in vulnerabilities
140139
int withSessionMetadata = 0;
@@ -144,8 +143,8 @@ void testSessionMetadataIsPopulated() throws IOException {
144143
assertThat(vuln.sessionMetadata()).as("Session metadata should never be null").isNotNull();
145144

146145
// Debug: Show session metadata
147-
log.info("Vuln " + vuln.vulnID() + ":");
148-
log.info(" sessionMetadata: " + vuln.sessionMetadata().size() + " session(s)");
146+
log.info("Vuln {}:", vuln.vulnID());
147+
log.info(" sessionMetadata: {} session(s)", vuln.sessionMetadata().size());
149148

150149
if (!vuln.sessionMetadata().isEmpty()) {
151150
withSessionMetadata++;
@@ -154,23 +153,22 @@ void testSessionMetadataIsPopulated() throws IOException {
154153
// Show details of first session
155154
var firstSession = vuln.sessionMetadata().get(0);
156155
log.info(" ✓ Has session metadata:");
157-
log.info(" - Session ID: " + firstSession.getSessionId());
156+
log.info(" - Session ID: {}", firstSession.getSessionId());
158157
if (firstSession.getMetadata() != null && !firstSession.getMetadata().isEmpty()) {
159-
log.info(" - Metadata items: " + firstSession.getMetadata().size());
158+
log.info(" - Metadata items: {}", firstSession.getMetadata().size());
160159
// Show first metadata item
161160
var firstItem = firstSession.getMetadata().get(0);
162-
log.info(" * " + firstItem.getDisplayLabel() + ": " + firstItem.getValue());
161+
log.info(" * {}: {}", firstItem.getDisplayLabel(), firstItem.getValue());
163162
}
164163
}
165164
}
166165

167166
log.info("\nResults:");
168167
log.info(
169-
" Vulnerabilities with session metadata: "
170-
+ withSessionMetadata
171-
+ "/"
172-
+ response.items().size());
173-
log.info(" Total sessions found: " + totalSessions);
168+
" Vulnerabilities with session metadata: {}/{}",
169+
withSessionMetadata,
170+
response.items().size());
171+
log.info(" Total sessions found: {}", totalSessions);
174172

175173
// Verify the session metadata field exists (even if empty) - this confirms SDK expansion works
176174
for (VulnLight vuln : response.items()) {
@@ -248,16 +246,15 @@ void testVulnTagsWithSpacesHandledBySDK() throws IOException {
248246
);
249247

250248
assertThat(response).as("Response should not be null").isNotNull();
251-
log.info(
252-
"Query completed successfully (returned " + response.items().size() + " vulnerabilities)");
249+
log.info("Query completed successfully (returned {} vulnerabilities)", response.items().size());
253250

254251
// The query should complete without error - whether we get results depends on the org's data
255252
// The important thing is that the SDK properly encoded the tag with spaces
256253
if (response.items().size() > 0) {
257254
log.info("✓ Found vulnerabilities with 'SmartFix Remediated' tag:");
258255
for (VulnLight vuln : response.items()) {
259-
log.info(" - " + vuln.vulnID() + ": " + vuln.title());
260-
log.info(" Tags: " + vuln.tags());
256+
log.info(" - {}: {}", vuln.vulnID(), vuln.title());
257+
log.info(" Tags: {}", vuln.tags());
261258
}
262259
} else {
263260
log.info("ℹ No vulnerabilities found with 'SmartFix Remediated' tag (this is OK)");
@@ -271,7 +268,7 @@ void testVulnTagsWithSpacesHandledBySDK() throws IOException {
271268

272269
assertThat(response).as("Response should not be null").isNotNull();
273270
log.info("✓ Query with multiple tags completed successfully");
274-
log.info(" (returned " + response.items().size() + " vulnerabilities)");
271+
log.info(" (returned {} vulnerabilities)", response.items().size());
275272

276273
log.info("\n✓ Integration test passed: SDK properly handles vulnTags with spaces");
277274
}
@@ -288,7 +285,7 @@ void testListVulnsByAppIdWithSessionMetadata() throws IOException {
288285
assertThat(allVulns).as("Response should not be null").isNotNull();
289286
assertThat(allVulns.items()).as("Should have at least one vulnerability").isNotEmpty();
290287

291-
log.info(" ✓ Found " + allVulns.items().size() + " vulnerability(ies)");
288+
log.info(" ✓ Found {} vulnerability(ies)", allVulns.items().size());
292289

293290
// Step 2: Get applications list (single API call)
294291
log.info("Step 2: Getting first application with vulnerabilities...");
@@ -299,14 +296,14 @@ void testListVulnsByAppIdWithSessionMetadata() throws IOException {
299296
// Just use the first application - no iteration needed
300297
var testAppId = applications.get(0).appID();
301298
var testAppName = applications.get(0).name();
302-
log.info(" ✓ Using application: " + testAppName + " (ID: " + testAppId + ")");
299+
log.info(" ✓ Using application: {} (ID: {})", testAppName, testAppId);
303300

304301
// Step 3: Call listVulnsByAppId() with the discovered appId
305-
log.info("Step 3: Calling listVulnsByAppId() for app: " + testAppName);
302+
log.info("Step 3: Calling listVulnsByAppId() for app: {}", testAppName);
306303
var vulnerabilities = assessService.listVulnsByAppId(testAppId);
307304

308305
assertThat(vulnerabilities).as("Vulnerabilities list should not be null").isNotNull();
309-
log.info(" ✓ Retrieved " + vulnerabilities.size() + " vulnerability(ies)");
306+
log.info(" ✓ Retrieved {} vulnerability(ies)", vulnerabilities.size());
310307

311308
if (vulnerabilities.isEmpty()) {
312309
log.info(" ℹ No vulnerabilities for this app (this is OK for the test)");
@@ -355,15 +352,14 @@ void testListVulnsInAppByNameForLatestSessionWithDynamicSessionId() throws IOExc
355352
// Just use the first application - no iteration needed
356353
var testAppID = applications.get(0).appID();
357354
var testAppName = applications.get(0).name();
358-
log.info(" ✓ Using application: " + testAppName + " (ID: " + testAppID + ")");
355+
log.info(" ✓ Using application: {} (ID: {})", testAppName, testAppID);
359356

360357
// Step 2: Call listVulnsByAppIdForLatestSession() with the discovered app ID
361-
log.info("Step 2: Calling listVulnsByAppIdForLatestSession() for appID: " + testAppID);
358+
log.info("Step 2: Calling listVulnsByAppIdForLatestSession() for appID: {}", testAppID);
362359
var latestSessionVulns = assessService.listVulnsByAppIdForLatestSession(testAppID);
363360

364361
assertThat(latestSessionVulns).as("Vulnerabilities list should not be null").isNotNull();
365-
log.info(
366-
" ✓ Retrieved " + latestSessionVulns.size() + " vulnerability(ies) for latest session");
362+
log.info(" ✓ Retrieved {} vulnerability(ies) for latest session", latestSessionVulns.size());
367363

368364
if (latestSessionVulns.isEmpty()) {
369365
log.info(
@@ -382,17 +378,16 @@ void testListVulnsInAppByNameForLatestSessionWithDynamicSessionId() throws IOExc
382378
if (!vuln.sessionMetadata().isEmpty()) {
383379
withSessionMetadata++;
384380
String sessionId = vuln.sessionMetadata().get(0).getSessionId();
385-
log.info(" ✓ Vuln " + vuln.vulnID() + " has session ID: " + sessionId);
381+
log.info(" ✓ Vuln {} has session ID: {}", vuln.vulnID(), sessionId);
386382
}
387383
}
388384

389385
log.info("\nResults:");
390-
log.info(" Vulnerabilities returned: " + latestSessionVulns.size());
386+
log.info(" Vulnerabilities returned: {}", latestSessionVulns.size());
391387
log.info(
392-
" Vulnerabilities with session metadata: "
393-
+ withSessionMetadata
394-
+ "/"
395-
+ latestSessionVulns.size());
388+
" Vulnerabilities with session metadata: {}/{}",
389+
withSessionMetadata,
390+
latestSessionVulns.size());
396391
log.info(
397392
"✓ Integration test passed: listVulnsByAppIdForLatestSession() returns vulnerabilities with"
398393
+ " session metadata");

0 commit comments

Comments
 (0)