Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions rewrite-core/src/main/java/org/openrewrite/CsvDataTableStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,19 @@ void close() {
*/
public static String fileKey(DataTable<?> dataTable) {
String group = dataTable.getGroup();
String suffix = group != null ? group : dataTable.getInstanceName();
if (suffix.equals(dataTable.getName())) {
if (group != null) {
if (group.equals(dataTable.getName())) {
return dataTable.getName();
}
return dataTable.getName() + "--" + sanitize(group);
}
// Only add a suffix when the instance name was explicitly customized
// (i.e. differs from the default display name)
String instanceName = dataTable.getInstanceName();
if (instanceName.equals(dataTable.getDisplayName())) {
return dataTable.getName();
}
return dataTable.getName() + "--" + sanitize(suffix);
return dataTable.getName() + "--" + sanitize(instanceName);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions rewrite-core/src/test/java/org/openrewrite/DataTableStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,31 @@ void csvStoreReadDescriptor(@TempDir Path tempDir) throws Exception {
}
}

// =========================================================================
// CsvDataTableStore.fileKey
// =========================================================================

@Test
void fileKeyNoSuffixWhenInstanceNameNotCustomized() {
TestTable table = new TestTable(Recipe.noop());
assertThat(CsvDataTableStore.fileKey(table)).isEqualTo(TestTable.class.getName());
}

@Test
void fileKeySuffixWhenInstanceNameCustomized() {
TestTable table = new TestTable(Recipe.noop())
.withInstanceName(() -> "custom instance");
String key = CsvDataTableStore.fileKey(table);
assertThat(key).startsWith(TestTable.class.getName() + "--");
}

@Test
void fileKeySuffixFromGroup() {
TestTable table = new TestTable(Recipe.noop()).withGroup("my-group");
String key = CsvDataTableStore.fileKey(table);
assertThat(key).startsWith(TestTable.class.getName() + "--");
}

// =========================================================================
// CsvDataTableStore.sanitize
// =========================================================================
Expand Down