Skip to content

Commit 16f91cc

Browse files
committed
feat: allow checksum-calculation for string
1 parent d754183 commit 16f91cc

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

app/src/main/java/com/diffplug/spotless/cli/core/ChecksumCalculator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737

3838
public class ChecksumCalculator {
3939

40+
public String calculateChecksum(String text) {
41+
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
42+
return toHashedHexBytes(bytes);
43+
}
44+
4045
public String calculateChecksum(SpotlessCLIFormatterStep step) {
4146
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
4247
writeObjectDataTo(step, out);

app/src/test/java/com/diffplug/spotless/cli/core/ChecksumCalculatorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jetbrains.annotations.NotNull;
2626
import org.junit.jupiter.api.Test;
2727

28+
import com.diffplug.selfie.Selfie;
2829
import com.diffplug.spotless.FormatterStep;
2930
import com.diffplug.spotless.cli.SpotlessAction;
3031
import com.diffplug.spotless.cli.SpotlessActionContextProvider;
@@ -190,6 +191,16 @@ void itCalculatesDifferentChecksumDueToDifferentSetterOption() {
190191
assertThat(checksum1).isNotEqualTo(checksum2);
191192
}
192193

194+
@Test
195+
void itCalculatesChecksumForFilePath() {
196+
Path testPath = Path.of("var", "tmp", "test.txt");
197+
198+
String checksum =
199+
checksumCalculator.calculateChecksum(testPath.toAbsolutePath().toString());
200+
201+
Selfie.expectSelfie(checksum).toBe("ef184d3abbb8db0a9867f9abaae87397");
202+
}
203+
193204
private static Step step(
194205
Path test1, String test2, StepArgGroup argGroup, StepArgGroup argGroup2, List<Path> parameters) {
195206
return step(test1, test2, test1 + test2, argGroup, argGroup2, parameters);

0 commit comments

Comments
 (0)