mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 01:51:49 +01:00
Merge pull request #161 from hansjoachim/exceptionTests
Uses ExpectedException to test for exceptions Former-commit-id: 38f9b007311032db7edec0e1c345130409518855
This commit is contained in:
@@ -20,12 +20,11 @@ package org.owasp.dependencycheck.utils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Rule;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.owasp.dependencycheck.utils.Checksum;
|
import org.owasp.dependencycheck.utils.Checksum;
|
||||||
import org.owasp.dependencycheck.utils.Checksum;
|
import org.owasp.dependencycheck.utils.Checksum;
|
||||||
|
|
||||||
@@ -35,21 +34,8 @@ import org.owasp.dependencycheck.utils.Checksum;
|
|||||||
*/
|
*/
|
||||||
public class ChecksumTest {
|
public class ChecksumTest {
|
||||||
|
|
||||||
@BeforeClass
|
@Rule
|
||||||
public static void setUpClass() throws Exception {
|
public ExpectedException expectedException = ExpectedException.none();
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownClass() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getChecksum method, of class Checksum.
|
* Test of getChecksum method, of class Checksum.
|
||||||
@@ -83,13 +69,9 @@ public class ChecksumTest {
|
|||||||
public void testGetChecksum_FileNotFound() throws Exception {
|
public void testGetChecksum_FileNotFound() throws Exception {
|
||||||
String algorithm = "MD5";
|
String algorithm = "MD5";
|
||||||
File file = new File("not a valid file");
|
File file = new File("not a valid file");
|
||||||
boolean exceptionThrown = false;
|
|
||||||
try {
|
expectedException.expect(IOException.class);
|
||||||
byte[] result = Checksum.getChecksum(algorithm, file);
|
Checksum.getChecksum(algorithm, file);
|
||||||
} catch (IOException ex) {
|
|
||||||
exceptionThrown = true;
|
|
||||||
}
|
|
||||||
Assert.assertTrue(exceptionThrown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,13 +84,9 @@ public class ChecksumTest {
|
|||||||
public void testGetChecksum_NoSuchAlgorithm() throws Exception {
|
public void testGetChecksum_NoSuchAlgorithm() throws Exception {
|
||||||
String algorithm = "some unknown algorithm";
|
String algorithm = "some unknown algorithm";
|
||||||
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
||||||
boolean exceptionThrown = false;
|
|
||||||
try {
|
expectedException.expect(NoSuchAlgorithmException.class);
|
||||||
byte[] result = Checksum.getChecksum(algorithm, file);
|
Checksum.getChecksum(algorithm, file);
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
exceptionThrown = true;
|
|
||||||
}
|
|
||||||
Assert.assertTrue(exceptionThrown);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user