UTs on Windows when project path contains space & some exception review

This commit is contained in:
Alix Lourme
2016-11-22 23:33:40 +01:00
parent 2ad08d2367
commit 6ecf55be91
8 changed files with 27 additions and 27 deletions

View File

@@ -102,7 +102,7 @@ public final class Downloader {
org.apache.commons.io.FileUtils.copyFile(file, outputPath);
} catch (IOException ex) {
final String msg = format("Download failed, unable to copy '%s' to '%s'", url.toString(), outputPath.getAbsolutePath());
throw new DownloadFailedException(msg);
throw new DownloadFailedException(msg, ex);
}
} else {
final String msg = format("Download failed, file ('%s') does not exist", url.toString());
@@ -186,7 +186,7 @@ public final class Downloader {
final String msg = format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
throw new DownloadFailedException(msg, ex);
} catch (Throwable ex) {
} catch (Exception ex) {
final String msg = format("Unexpected exception saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
throw new DownloadFailedException(msg, ex);
@@ -249,7 +249,7 @@ public final class Downloader {
lastModifiedFile = new File(url.toURI());
} catch (URISyntaxException ex) {
final String msg = format("Unable to locate '%s'", url.toString());
throw new DownloadFailedException(msg);
throw new DownloadFailedException(msg, ex);
}
timestamp = lastModifiedFile.lastModified();
} else {
@@ -281,7 +281,7 @@ public final class Downloader {
return getLastModified(url, true);
}
} catch (InvalidSettingException ex1) {
LOGGER.debug("invalid setting?", ex);
LOGGER.debug("invalid setting?", ex1);
}
throw new DownloadFailedException(format("Error making HTTP %s request.", httpMethod), ex);
} finally {
@@ -351,6 +351,9 @@ public final class Downloader {
try {
quickQuery = Settings.getBoolean(Settings.KEYS.DOWNLOADER_QUICK_QUERY_TIMESTAMP, true);
} catch (InvalidSettingException e) {
if (LOGGER.isTraceEnabled()){
LOGGER.trace("Invalid settings : {}", e.getMessage(), e);
}
quickQuery = true;
}
return quickQuery;

View File

@@ -44,7 +44,7 @@ public class ChecksumTest {
@Test
public void testGetChecksum() throws Exception {
String algorithm = "MD5";
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
byte[] expResult = {-16, -111, 92, 95, 70, -72, -49, -94, -125, -27, -83, 103, -96, -101, 55, -109};
byte[] result = Checksum.getChecksum(algorithm, file);
boolean arraysAreEqual = true;
@@ -94,7 +94,7 @@ public class ChecksumTest {
*/
@Test
public void testGetMD5Checksum() throws Exception {
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
//String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
String expResult = "f0915c5f46b8cfa283e5ad67a09b3793";
String result = Checksum.getMD5Checksum(file);
@@ -108,7 +108,7 @@ public class ChecksumTest {
*/
@Test
public void testGetSHA1Checksum() throws Exception {
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
//String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
String expResult = "b8a9ff28b21bcb1d0b50e24a5243d8b51766851a";
String result = Checksum.getSHA1Checksum(file);

View File

@@ -18,7 +18,6 @@
package org.owasp.dependencycheck.utils;
import java.io.File;
import java.net.URL;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.owasp.dependencycheck.utils.Downloader;
@@ -31,9 +30,7 @@ public class DownloaderTest {
@Test
public void testGetLastModified_file() throws Exception {
File f = new File("target/test-classes/dependencycheck.properties");
URL url = new URL("file:///" + f.getCanonicalPath());
long timestamp = Downloader.getLastModified(url);
long timestamp = Downloader.getLastModified(new File("target/test-classes/dependencycheck.properties").toURI().toURL());
assertTrue("timestamp equal to zero?", timestamp > 0);
}
}