Skip to content

Commit dc7dce8

Browse files
SLLS-546 Don't use system clocks in tests (#708)
1 parent 351844e commit dc7dce8

6 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/test/java/org/sonarsource/sonarlint/ls/CommandManagerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ void showHotspotFlowsCommandSuccess() {
614614
"rule",
615615
"ruleName",
616616
Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)),
617-
Instant.now(),
617+
Instant.EPOCH,
618618
true,
619619
false,
620620
null,

src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,23 +737,23 @@ void shouldForwardOpenIssueRequestWithRuleDescriptionWhenBindingDoesExist() {
737737

738738
@Test
739739
void shouldLogMessagesWithLogLevel() {
740-
underTest.log(new LogParams(LogLevel.ERROR, null, null, null, Instant.now()));
740+
underTest.log(new LogParams(LogLevel.ERROR, null, null, null, Instant.EPOCH));
741741
assertThat(logTester.logs())
742742
.anyMatch(log -> log.contains("null"));
743743

744-
underTest.log(new LogParams(LogLevel.ERROR, "Log message", null, null, Instant.now()));
744+
underTest.log(new LogParams(LogLevel.ERROR, "Log message", null, null, Instant.EPOCH));
745745
assertThat(logTester.logs(MessageType.Log))
746746
.anyMatch(log -> log.contains("null"));
747-
underTest.log(new LogParams(LogLevel.WARN, "Log message", null, null, Instant.now()));
747+
underTest.log(new LogParams(LogLevel.WARN, "Log message", null, null, Instant.EPOCH));
748748
assertThat(logTester.logs(MessageType.Log))
749749
.anyMatch(log -> log.contains("null"));
750-
underTest.log(new LogParams(LogLevel.INFO, "Log message", null, null, Instant.now()));
750+
underTest.log(new LogParams(LogLevel.INFO, "Log message", null, null, Instant.EPOCH));
751751
assertThat(logTester.logs(MessageType.Log))
752752
.anyMatch(log -> log.contains("null"));
753-
underTest.log(new LogParams(LogLevel.DEBUG, "Log message", null, null, Instant.now()));
753+
underTest.log(new LogParams(LogLevel.DEBUG, "Log message", null, null, Instant.EPOCH));
754754
assertThat(logTester.logs(MessageType.Log))
755755
.anyMatch(log -> log.contains("null"));
756-
underTest.log(new LogParams(LogLevel.TRACE, "Log message", null, null, Instant.now()));
756+
underTest.log(new LogParams(LogLevel.TRACE, "Log message", null, null, Instant.EPOCH));
757757
assertThat(logTester.logs(MessageType.Log))
758758
.anyMatch(log -> log.contains("null"));
759759
}
@@ -1222,15 +1222,15 @@ void shouldForwardDidChangePluginStatusesToClient() {
12221222

12231223
private TaintVulnerabilityDto getTaintDto(UUID uuid) {
12241224
return new TaintVulnerabilityDto(uuid, "serverKey", false, null, "ruleKey", "message",
1225-
Path.of("filePath"), Instant.now(), org.sonarsource.sonarlint.core.rpc.protocol.common.Either
1225+
Path.of("filePath"), Instant.EPOCH, org.sonarsource.sonarlint.core.rpc.protocol.common.Either
12261226
.forLeft(new StandardModeDetails(IssueSeverity.MAJOR, RuleType.BUG)),
12271227
List.of(),
12281228
new TextRangeWithHashDto(5, 5, 5, 5, ""), "", true, false);
12291229
}
12301230

12311231
private TaintIssue getTaintIssue(UUID uuid) {
12321232
return new TaintIssue(new TaintVulnerabilityDto(uuid, "serverKey", false, null, "ruleKey", "message",
1233-
Path.of("filePath"), Instant.now(), org.sonarsource.sonarlint.core.rpc.protocol.common.Either
1233+
Path.of("filePath"), Instant.EPOCH, org.sonarsource.sonarlint.core.rpc.protocol.common.Either
12341234
.forLeft(new StandardModeDetails(IssueSeverity.MAJOR, RuleType.BUG)),
12351235
List.of(),
12361236
new TextRangeWithHashDto(5, 5, 5, 5, ""), "", true, false), "folderUri", true);

src/test/java/org/sonarsource/sonarlint/ls/domain/TaintIssueTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void shouldInitializeWithCorrectSeverityDetails() {
6363
"ruleKey",
6464
"message",
6565
Path.of("ideFilePath"),
66-
Instant.now(),
66+
Instant.EPOCH,
6767
Either.forLeft(new StandardModeDetails(IssueSeverity.MAJOR, RuleType.BUG)),
6868
List.of(),
6969
null,
@@ -87,7 +87,7 @@ void shouldInitializeWithCorrectSeverityDetailsMQR() {
8787
"ruleKey",
8888
"message",
8989
Path.of("ideFilePath"),
90-
Instant.now(),
90+
Instant.EPOCH,
9191
Either.forRight(new MQRModeDetails(CleanCodeAttribute.TRUSTWORTHY, List.of(new ImpactDto(SoftwareQuality.SECURITY, ImpactSeverity.HIGH)))),
9292
List.of(),
9393
null,

src/test/java/org/sonarsource/sonarlint/ls/mediumtests/ConnectedModeMediumTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ConnectedModeMediumTests extends AbstractLanguageServerMediumTests {
106106
private static final String PROJECT_NAME1 = "Project One";
107107
private static final String PROJECT_KEY2 = "project:key2";
108108
private static final String PROJECT_NAME2 = "Project Two";
109-
private static final long CURRENT_TIME = System.currentTimeMillis();
109+
private static final long CURRENT_TIME = Instant.parse("2026-01-01T00:00:00Z").toEpochMilli();
110110
private static Path bindingSuggestionBaseDir;
111111

112112
private Path folder1BaseDir;
@@ -376,7 +376,7 @@ void analysisConnected_find_tracked_hotspot_before_sq_10_1() {
376376
.setKey(hotspotKey)
377377
.setMessage("Make sure using this hardcoded IP address \"12.34.56.78\" is safe here.")
378378
.setComponent("someComponentKey")
379-
.setCreationDate(DateUtils.formatDateTime(System.currentTimeMillis()))
379+
.setCreationDate(DateUtils.formatDateTime(CURRENT_TIME))
380380
.setStatus("TO_REVIEW")
381381
.setVulnerabilityProbability("LOW")
382382
.setTextRange(Common.TextRange.newBuilder()
@@ -440,7 +440,7 @@ void analysisConnected_find_tracked_hotspot_after_sq_10_1() {
440440
Hotspots.HotspotLite.newBuilder()
441441
.setKey(hotspotKey)
442442
.setFilePath(analyzedFileName)
443-
.setCreationDate(System.currentTimeMillis())
443+
.setCreationDate(CURRENT_TIME)
444444
.setStatus("TO_REVIEW")
445445
.setVulnerabilityProbability("LOW")
446446
.setMessage("Make sure using this hardcoded IP address \"12.34.56.78\" is safe here.")
@@ -944,7 +944,7 @@ void change_hotspot_status_to_resolved() {
944944
Hotspots.HotspotLite.newBuilder()
945945
.setKey(hotspotKey)
946946
.setFilePath(analyzedFileName)
947-
.setCreationDate(System.currentTimeMillis())
947+
.setCreationDate(CURRENT_TIME)
948948
.setStatus("TO_REVIEW")
949949
.setVulnerabilityProbability("LOW")
950950
.setMessage("Make sure using this hardcoded IP address \"12.34.56.78\" is safe here.")
@@ -1001,7 +1001,7 @@ void should_not_change_hotspot_status_to_resolved() {
10011001
Hotspots.HotspotLite.newBuilder()
10021002
.setKey(hotspotKey)
10031003
.setFilePath(analyzedFileName)
1004-
.setCreationDate(System.currentTimeMillis())
1004+
.setCreationDate(CURRENT_TIME)
10051005
.setStatus("TO_REVIEW")
10061006
.setVulnerabilityProbability("LOW")
10071007
.setMessage("Make sure using this hardcoded IP address \"12.34.56.78\" is safe here.")
@@ -1076,7 +1076,7 @@ void change_hotspot_status_permission_check() throws ExecutionException, Interru
10761076
Hotspots.HotspotLite.newBuilder()
10771077
.setKey(hotspotKey)
10781078
.setFilePath(analyzedFileName)
1079-
.setCreationDate(System.currentTimeMillis())
1079+
.setCreationDate(CURRENT_TIME)
10801080
.setStatus("TO_REVIEW")
10811081
.setVulnerabilityProbability("LOW")
10821082
.setMessage("Make sure using this hardcoded IP address \"12.34.56.78\" is safe here.")
@@ -1411,7 +1411,7 @@ void shouldReportTaintIssues() {
14111411
.setEndLine(1)
14121412
.setEndLineOffset(2)
14131413
.setHash("hash")))
1414-
.setCreationDate(Instant.now().toEpochMilli())
1414+
.setCreationDate(CURRENT_TIME)
14151415
.build());
14161416

14171417
addConfigScope(folder1BaseDir.toUri().toString());

src/test/java/org/sonarsource/sonarlint/ls/notebooks/DelegatingCellIssueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void shouldGetIssue() {
4242
"ruleKey",
4343
"message",
4444
Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)),
45-
Instant.now(),
45+
Instant.EPOCH,
4646
true,
4747
false,
4848
null,

src/test/java/org/sonarsource/sonarlint/ls/notebooks/VersionedOpenNotebookTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ private void manuallyReindexCellLines(VersionedOpenNotebook underTest) {
518518
"ruleKey",
519519
"message",
520520
Either.forLeft(new StandardModeDetails(IssueSeverity.BLOCKER, RuleType.BUG)),
521-
Instant.now(),
521+
Instant.EPOCH,
522522
true,
523523
false,
524524
new TextRangeDto(1, 0, 1, 0),

0 commit comments

Comments
 (0)