Skip to content

Commit

Permalink
update JUnit to 4.13.2; use java.nio.file.Files for temp dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
inthewaves committed May 4, 2021
1 parent 95c58a7 commit 75b5d42
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 37 deletions.
2 changes: 1 addition & 1 deletion applier/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'java'
dependencies {
compile project(':shared')

testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.13.2'
testCompile project(':sharedtest')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Applies V1 patches.
Expand Down Expand Up @@ -67,7 +70,7 @@ public void applyDelta(File oldBlob, InputStream deltaIn, OutputStream newBlobOu
// will fail when it tries to create the file in a few more lines anyways.
tempDir.mkdirs();
}
File tempFile = File.createTempFile("gfbfv1", "old", tempDir);
File tempFile = Files.createTempFile(tempDir.toPath(), "gfbfv1", "old").toFile();
try {
applyDeltaInternal(oldBlob, tempFile, deltaIn, newBlobOut);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicBoolean;

/**
Expand Down Expand Up @@ -114,10 +115,10 @@ public void setUp() throws IOException {
// 2. The new file, in memory only (for comparing results at the end).
// 3. The patch, in memory.

File tempFile = File.createTempFile("foo", "bar");
File tempFile = Files.createTempFile("foo", "bar").toFile();
tempDir = tempFile.getParentFile();
tempFile.delete();
oldFile = File.createTempFile("fbfv1dat", "old");
oldFile = Files.createTempFile("fbfv1dat", "old").toFile();
oldFile.deleteOnExit();

// Write the old file to disk:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.file.Files;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void setUp() throws IOException {
buffer1 = new byte[6];
buffer2 = new byte[6];
try {
oldFile = File.createTempFile("archive_patcher", "old");
oldFile = Files.createTempFile("archive_patcher", "old").toFile();
oldFile.deleteOnExit();
} catch (IOException e) {
if (oldFile != null) {
Expand Down Expand Up @@ -688,7 +690,7 @@ private byte[] readTestData(String testDataFileName) throws IOException {
* @throws IOException if unable to complete the copy
*/
private void copyToOldFile(String testDataFileName) throws IOException {
oldFile = File.createTempFile("archive_patcher", "temp");
oldFile = Files.createTempFile("archive_patcher", "temp").toFile();
Assert.assertNotNull("cant create file!", oldFile);
byte[] buffer = readTestData(testDataFileName);
FileOutputStream out = new FileOutputStream(oldFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.util.Random;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void testExample() throws IOException {
0 }; // EOF

// Create "input file".
File inputFile = File.createTempFile("testExample", null);
File inputFile = Files.createTempFile("testExample", null).toFile();
FileOutputStream writeInputFile = new FileOutputStream(inputFile);
writeInputFile.write(oldBytes);
writeInputFile.close();
Expand Down Expand Up @@ -101,7 +102,7 @@ public void testOpcodes() throws IOException {
0 }; // EOF

// Create "input file".
File inputFile = File.createTempFile("testExample", null);
File inputFile = Files.createTempFile("testExample", null).toFile();;
FileOutputStream writeInputFile = new FileOutputStream(inputFile);
writeInputFile.write(oldBytes);
writeInputFile.close();
Expand All @@ -124,7 +125,7 @@ public void testOpcodes() throws IOException {
@Test
public void testInlineDataCommands() throws IOException {
// We never read "input" so create an single, empty one.
File inputFile = File.createTempFile("testExample", null);
File inputFile = Files.createTempFile("testExample", null).toFile();;
FileOutputStream writeInputFile = new FileOutputStream(inputFile);
writeInputFile.close();
RandomAccessFile readInputFile = new RandomAccessFile(inputFile, "r");
Expand Down Expand Up @@ -309,7 +310,7 @@ private void checkExpectedIOException(byte[] inputBytes, int inputLimit,
inputLimit = inputBytes.length;
}
// Create "input file".
File inputFile = File.createTempFile("testExample", null);
File inputFile = Files.createTempFile("testExample", null).toFile();;
FileOutputStream writeInputFile = new FileOutputStream(inputFile);
writeInputFile.write(inputBytes, 0, inputLimit);
writeInputFile.close();
Expand Down
2 changes: 1 addition & 1 deletion explainer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
compile project(':generator')
compile project(':shared')

testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.13.2'
testCompile project(':sharedtest')
}
// EOF
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;
import org.junit.After;
Expand Down Expand Up @@ -135,8 +136,8 @@ private final void assertFileEquals(File file, byte[] expected) throws IOExcepti

@Before
public void setup() throws IOException {
oldFile = File.createTempFile("patchexplainertest", "old");
newFile = File.createTempFile("patchexplainertest", "new");
oldFile = Files.createTempFile("patchexplainertest", "old").toFile();
newFile = Files.createTempFile("patchexplainertest", "new").toFile();;
}

@After
Expand Down
2 changes: 1 addition & 1 deletion generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'java'
dependencies {
compile project(':shared')

testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.13.2'
testCompile project(':sharedtest')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
* A closeable container for a temp file that deletes itself on {@link #close()}. This is convenient
Expand All @@ -35,7 +36,7 @@ public class TempFileHolder implements Closeable {
* @throws IOException if unable to create the file
*/
public TempFileHolder() throws IOException {
file = File.createTempFile("archive_patcher", "tmp");
file = Files.createTempFile("archive_patcher", "tmp").toFile();
file.deleteOnExit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;

// TODO(andrewhayden): clean up the implementations, we only really need two and they can be in
// separate files.
Expand Down Expand Up @@ -389,7 +390,7 @@ public RandomAccessMmapObject(final String tempFileName, final String mode, long
"RandomAccessMmapObject only supports file sizes up to " + "Integer.MAX_VALUE.");
}

mFile = File.createTempFile(tempFileName, "temp");
mFile = Files.createTempFile(tempFileName, "temp").toFile();
mFile.deleteOnExit();
mShouldDeleteFileOnRelease = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;

/**
* A factory for creating instances of {@link RandomAccessObject}. BsDiff needs to store some
Expand Down Expand Up @@ -60,7 +61,7 @@ public RandomAccessFileObjectFactory(String mode) {
@Override
public RandomAccessObject create(int size) throws IOException {
return new RandomAccessObject.RandomAccessFileObject(
File.createTempFile(FILE_NAME_PREFIX, "temp"), mMode, true);
Files.createTempFile(FILE_NAME_PREFIX, "temp").toFile(), mMode, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void testDivineDeflateParameters_AllValidSettings() throws IOException {

@Test
public void testDivineDeflateParameters_File() throws IOException {
File tempFile = File.createTempFile("ddcdt", "tmp");
File tempFile = Files.createTempFile("ddcdt", "tmp").toFile();
tempFile.deleteOnExit();
try {
UnitTestZipArchive.saveTestZip(tempFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -189,7 +190,7 @@ private static final List<QualifiedRecommendation> suppressed(
@Before
public void setup() throws IOException {
// Make an empty file to test the recommender's limitation logic
tempFile = File.createTempFile("DeltaFriendlyOldBlobSizeLimiterTest", "test");
tempFile = Files.createTempFile("DeltaFriendlyOldBlobSizeLimiterTest", "test").toFile();
tempFile.deleteOnExit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.zip.CRC32;

Expand All @@ -42,7 +43,7 @@ public class MinimalZipArchiveTest {
@Before
public void setup() throws Exception {
unitTestZipArchive = UnitTestZipArchive.makeTestZip();
tempFile = File.createTempFile("MinimalZipArchiveTest", "zip");
tempFile = Files.createTempFile("MinimalZipArchiveTest", "zip").toFile();
tempFile.deleteOnExit();
try {
FileOutputStream out = new FileOutputStream(tempFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.CRC32;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testLocateStartOfEocd_WithFile() throws IOException {
// Create a temp file with some zeroes, the EOCD header, and more zeroes.
int bytesBefore = 53754;
int bytesAfter = 107;
File tempFile = File.createTempFile("MinimalZipParserTest", "zip");
File tempFile = Files.createTempFile("MinimalZipParserTest", "zip").toFile();
tempFile.deleteOnExit();
try {
FileOutputStream out = new FileOutputStream(tempFile);
Expand Down Expand Up @@ -97,7 +98,7 @@ public void testLocateStartOfEocd_WithFile() throws IOException {
@Test
public void testLocateStartOfEocd_WithFile_NoEocd() throws IOException {
// Create a temp file with some zeroes and no EOCD header at all
File tempFile = File.createTempFile("MinimalZipParserTest", "zip");
File tempFile = Files.createTempFile("MinimalZipParserTest", "zip").toFile();
tempFile.deleteOnExit();
try {
FileOutputStream out = new FileOutputStream(tempFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -83,7 +84,7 @@ public class PatchWriterTest {
@Before
public void setup() throws IOException {
buffer = new ByteArrayOutputStream();
deltaFile = File.createTempFile("patchwritertest", "delta");
deltaFile = Files.createTempFile("patchwritertest", "delta").toFile();
deltaFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(deltaFile)) {
out.write(DELTA_CONTENT.getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -85,7 +86,7 @@ private File store(byte[] data) throws IOException {
* @throws IOException if anything goes wrong
*/
private File newTempFile() throws IOException {
File file = File.createTempFile("pdet", "bin");
File file = Files.createTempFile("pdet", "bin").toFile();
tempFilesCreated.add(file);
file.deleteOnExit();
return file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void tearDown() {
* @throws IOException if it fails
*/
private File storeAndMapArchive(byte[] data) throws IOException {
File file = File.createTempFile("pdpt", "zip");
File file = Files.createTempFile("pdpt", "zip").toFile();
tempFilesCreated.add(file);
file.deleteOnExit();
FileOutputStream out = new FileOutputStream(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.RandomAccessFile;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.nio.file.Files;

@RunWith(JUnit4.class)
public class RandomAccessObjectTest {
Expand Down Expand Up @@ -173,7 +174,7 @@ public void fileWriteByteTest() throws IOException {

@Test
public void fileWriteByteToEmptyFileTest() throws IOException {
File tmpFile = File.createTempFile("RandomAccessObjectTest", "temp");
File tmpFile = Files.createTempFile("RandomAccessObjectTest", "temp").toFile();

try (RandomAccessObject obj = new RandomAccessObject.RandomAccessFileObject(tmpFile, "rw")) {
for (int x = 0; x < BLOB.length; x++) {
Expand Down Expand Up @@ -256,7 +257,7 @@ public void mmapWriteByteTest() throws IOException {

@Test
public void mmapWriteByteToEmptyFileTest() throws IOException {
File tmpFile = File.createTempFile("RandomAccessObjectTest", "temp");
File tmpFile = Files.createTempFile("RandomAccessObjectTest", "temp").toFile();

try (RandomAccessObject obj =
new RandomAccessObject.RandomAccessMmapObject(new RandomAccessFile(tmpFile, "rw"), "rw")) {
Expand Down Expand Up @@ -604,7 +605,7 @@ private void seekToIntAlignedTest(final RandomAccessObject obj) throws IOExcepti
private File storeInTempFile(InputStream content) throws IOException {
File tmpFile = null;
try {
tmpFile = File.createTempFile("RandomAccessObjectTest", "temp");
tmpFile = Files.createTempFile("RandomAccessObjectTest", "temp").toFile();
tmpFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tmpFile);
byte[] buffer = new byte[32768];
Expand Down
2 changes: 1 addition & 1 deletion integrationtest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {
compile project(':applier')
compile project(':generator')

testCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.13.2'
testCompile project(':sharedtest')
}
// EOF
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -116,9 +117,9 @@ public class FileByFileV1IntegrationTest {

@Before
public void setUp() throws IOException {
oldFile = File.createTempFile("fbf_test", "old");
oldFile = Files.createTempFile("fbf_test", "old").toFile();
oldFile.deleteOnExit();
newFile = File.createTempFile("fbf_test", "new");
newFile = Files.createTempFile("fbf_test", "new").toFile();
newFile.deleteOnExit();
tempDir = oldFile.getParentFile();
}
Expand Down
Loading

0 comments on commit 75b5d42

Please sign in to comment.