import javax.annotation.CheckForNull;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
+import java.io.*;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
private class FileHashComputer extends CharHandler {
private MessageDigest globalMd5Digest = DigestUtils.getMd5Digest();
- private boolean emptyFile = true;;
@Override
void handleIgnoreEoL(char c) {
- emptyFile = false;
updateDigestUTF8Char(c, globalMd5Digest);
}
@Override
void newLine() {
- emptyFile = false;
updateDigestUTF8Char(LINE_FEED, globalMd5Digest);
}
@CheckForNull
public String getHash() {
- return emptyFile ? null : Hex.encodeHexString(globalMd5Digest.digest());
+ return Hex.encodeHexString(globalMd5Digest.digest());
}
}
String relativePathEmpty = "src/empty.java";
DefaultInputFile inputFileEmpty = new DefaultInputFile(PROJECT_KEY, relativePathEmpty)
.setLines(0)
- .setHash(null)
+ .setHash("abcd")
.setLineHashes(new byte[][] {});
when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileEmpty));
FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(1);
assertThat(metadata.nonBlankLines).isEqualTo(0);
- assertThat(metadata.hash).isNull();
+ assertThat(metadata.hash).isNotEmpty();
assertThat(metadata.originalLineOffsets).containsOnly(0);
assertThat(metadata.lineHashes[0]).isNull();
assertThat(metadata.empty).isTrue();