diff --git a/src/test/java/com/google/jenkins/plugins/credentials/oauth/JsonServiceAccountConfigTestUtil.java b/src/test/java/com/google/jenkins/plugins/credentials/oauth/JsonServiceAccountConfigTestUtil.java index b732e2a..23d3910 100644 --- a/src/test/java/com/google/jenkins/plugins/credentials/oauth/JsonServiceAccountConfigTestUtil.java +++ b/src/test/java/com/google/jenkins/plugins/credentials/oauth/JsonServiceAccountConfigTestUtil.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.StringWriter; import java.nio.charset.Charset; +import java.nio.file.Files; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; @@ -64,13 +65,7 @@ public static String createTempJsonKeyFile(String clientEmail, PrivateKey privat private static File getTempFolder() throws IOException { if (tempFolder == null) { - tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime())); - if (!tempFolder.delete()) { - throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath()); - } - if (!tempFolder.mkdir()) { - throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath()); - } + tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile(); tempFolder.deleteOnExit(); } return tempFolder; diff --git a/src/test/java/com/google/jenkins/plugins/credentials/oauth/LegacyJsonServiceAccountConfigUtil.java b/src/test/java/com/google/jenkins/plugins/credentials/oauth/LegacyJsonServiceAccountConfigUtil.java index 6e9b8e5..ad0132c 100644 --- a/src/test/java/com/google/jenkins/plugins/credentials/oauth/LegacyJsonServiceAccountConfigUtil.java +++ b/src/test/java/com/google/jenkins/plugins/credentials/oauth/LegacyJsonServiceAccountConfigUtil.java @@ -21,6 +21,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Files; /** * Util class for {@link com.google.jenkins.plugins.credentials.oauth @@ -86,13 +87,7 @@ public static String createTempInvalidLegacyJsonKeyFile() throws IOException { private static File getTempFolder() throws IOException { if (tempFolder == null) { - tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime())); - if (!tempFolder.delete()) { - throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath()); - } - if (!tempFolder.mkdir()) { - throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath()); - } + tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile(); tempFolder.deleteOnExit(); } return tempFolder; diff --git a/src/test/java/com/google/jenkins/plugins/credentials/oauth/P12ServiceAccountConfigTestUtil.java b/src/test/java/com/google/jenkins/plugins/credentials/oauth/P12ServiceAccountConfigTestUtil.java index a0c907a..127cf77 100644 --- a/src/test/java/com/google/jenkins/plugins/credentials/oauth/P12ServiceAccountConfigTestUtil.java +++ b/src/test/java/com/google/jenkins/plugins/credentials/oauth/P12ServiceAccountConfigTestUtil.java @@ -19,6 +19,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.math.BigInteger; +import java.nio.file.Files; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.KeyStore; @@ -64,13 +65,7 @@ public static String createTempP12KeyFile(KeyPair keyPair) private static File getTempFolder() throws IOException { if (tempFolder == null) { - tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime())); - if (!tempFolder.delete()) { - throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath()); - } - if (!tempFolder.mkdir()) { - throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath()); - } + tempFolder = Files.createTempDirectory("temp" + Long.toString(System.nanoTime())).toFile(); tempFolder.deleteOnExit(); } return tempFolder;