Skip to content

Commit

Permalink
Remove static of timestamp formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 12, 2024
1 parent 25ee9d6 commit b2a3696
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void createDirectory(
}

@VisibleForTesting
static String formatTimestamp(final Optional<UInt64> arrivalTimestamp) {
String formatTimestamp(final Optional<UInt64> arrivalTimestamp) {
if (arrivalTimestamp.isEmpty()) {
return "unknown";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void saveGossipMessageDecodingError_shouldSaveToFile(@TempDir Path tempDir) {
final String topic = "test_topic";
manager.saveGossipMessageDecodingError("test_topic", arrivalTimestamp, messageBytes);

final String fileName =
String.format("%s.ssz", DebugDataDumper.formatTimestamp(arrivalTimestamp));
final String fileName = String.format("%s.ssz", manager.formatTimestamp(arrivalTimestamp));
final Path expectedFile =
tempDir
.resolve("gossip_messages")
Expand All @@ -66,8 +65,7 @@ void saveGossipMessageDecodingError_shouldNotSaveToFileWhenDisabled(@TempDir Pat
manager.saveGossipMessageDecodingError("test_topic", arrivalTimestamp, messageBytes);
assertThat(manager.isEnabled()).isFalse();

final String fileName =
String.format("%s.ssz", DebugDataDumper.formatTimestamp(arrivalTimestamp));
final String fileName = String.format("%s.ssz", manager.formatTimestamp(arrivalTimestamp));
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("decoding_error").resolve(fileName);
checkFileNotExist(expectedFile);
Expand All @@ -81,8 +79,7 @@ void saveGossipRejectedMessageToFile_shouldSaveToFile(@TempDir Path tempDir) {
final String topic = "test_topic";
manager.saveGossipRejectedMessageToFile("test_topic", arrivalTimestamp, messageBytes);

final String fileName =
String.format("%s.ssz", DebugDataDumper.formatTimestamp(arrivalTimestamp));
final String fileName = String.format("%s.ssz", manager.formatTimestamp(arrivalTimestamp));
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("rejected").resolve(topic).resolve(fileName);
checkBytesSavedToFile(expectedFile, messageBytes);
Expand Down Expand Up @@ -157,14 +154,16 @@ void constructionOfDirectories_shouldDisableWhenFailedToCreate(@TempDir Path tem

@Test
void formatTimestamp_shouldFormatDate() {
final DebugDataDumper manager = new DebugDataDumper(Path.of("."), true);
final String formattedTimestamp =
DebugDataDumper.formatTimestamp(Optional.of(timeProvider.getTimeInMillis()));
manager.formatTimestamp(Optional.of(timeProvider.getTimeInMillis()));
assertThat(formattedTimestamp).isEqualTo("1970-01-01T12:46:40.00");
}

@Test
void formatTimestamp_shouldReturnConsistentUnknown() {
final String formattedTimestamp = DebugDataDumper.formatTimestamp(Optional.empty());
final DebugDataDumper manager = new DebugDataDumper(Path.of("."), true);
final String formattedTimestamp = manager.formatTimestamp(Optional.empty());
assertThat(formattedTimestamp).isEqualTo("unknown");
}

Expand Down

0 comments on commit b2a3696

Please sign in to comment.