Skip to content

Commit

Permalink
Reuse FileUtils#contentEquals(File,File) in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 16, 2023
1 parent 5e137c6 commit cd0aa01
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions src/test/java/org/apache/commons/net/tftp/TFTPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,8 @@ private static File createFile(final File file, final int size) throws IOExcepti
return file;
}

private boolean filesIdentical(final File a, final File b) throws IOException {
if (!a.exists() || !b.exists()) {
return false;
}

if (a.length() != b.length()) {
return false;
}

try (final InputStream fisA = new BufferedInputStream(new FileInputStream(a));
final InputStream fisB = new BufferedInputStream(new FileInputStream(b))) {

int aBit = fisA.read();
int bBit = fisB.read();

while (aBit != -1) {
if (aBit != bBit) {
fisA.close();
fisB.close();
return false;
}
aBit = fisA.read();
bBit = fisB.read();
}

}
return true;
private boolean contentEquals(final File a, final File b) throws IOException {
return FileUtils.contentEquals(a, b);
}

@Override
Expand Down Expand Up @@ -155,7 +130,7 @@ private void testDownload(final int mode, final File file) throws IOException {
}

assertTrue("file not created", out.exists());
assertTrue("FILES not identical on file " + file, filesIdentical(out, file));
assertTrue("FILES not identical on file " + file, contentEquals(out, file));

// delete the downloaded file
out.delete();
Expand Down Expand Up @@ -208,7 +183,7 @@ private void testUpload(final int mode, final File file) throws Exception {
// close out its file buffers, etc.
Thread.sleep(100);
assertTrue("file not created", in.exists());
assertTrue("FILES not identical on file " + file, filesIdentical(file, in));
assertTrue("FILES not identical on file " + file, contentEquals(file, in));

in.delete();
}
Expand Down

0 comments on commit cd0aa01

Please sign in to comment.