Use @Test annotation to test for exceptions being thrown

Please note that this commit only uses the @Test annotation
where exceptions are thrown at the end of the test,
because otherwise the test would not be executed completely.

Examples for this are in DatabaseComponentImplTest where many exceptions
are thrown in close succession or in ConnectionRegistryImplTest where an
exception is thrown in the middle of the test.
This commit is contained in:
Torsten Grote
2016-01-12 15:16:34 -02:00
parent aa1b9328c4
commit b837e8b035
5 changed files with 48 additions and 140 deletions

View File

@@ -82,7 +82,7 @@ public class StreamDecrypterImplTest extends BriarTestCase {
assertEquals(-1, s.readFrame(buffer));
}
@Test
@Test(expected = IOException.class)
public void testTruncatedFrameThrowsException() throws Exception {
byte[] frameHeader = new byte[FRAME_HEADER_LENGTH];
int payloadLength = 123, paddingLength = 234;
@@ -105,15 +105,10 @@ public class StreamDecrypterImplTest extends BriarTestCase {
// Try to read the truncated frame
byte[] buffer = new byte[MAX_PAYLOAD_LENGTH];
try {
s.readFrame(buffer);
fail();
} catch (IOException expected) {
// Expected
}
s.readFrame(buffer);
}
@Test
@Test(expected = IOException.class)
public void testInvalidPayloadAndPaddingLengthThrowsException()
throws Exception {
byte[] frameHeader = new byte[FRAME_HEADER_LENGTH];
@@ -139,15 +134,10 @@ public class StreamDecrypterImplTest extends BriarTestCase {
// Try to read the invalid frame
byte[] buffer = new byte[MAX_PAYLOAD_LENGTH];
try {
s.readFrame(buffer);
fail();
} catch (IOException expected) {
// Expected
}
s.readFrame(buffer);
}
@Test
@Test(expected = IOException.class)
public void testNonZeroPaddingThrowsException() throws Exception {
byte[] frameHeader = new byte[FRAME_HEADER_LENGTH];
int payloadLength = 123, paddingLength = 234;
@@ -174,12 +164,7 @@ public class StreamDecrypterImplTest extends BriarTestCase {
// Try to read the invalid frame
byte[] buffer = new byte[MAX_PAYLOAD_LENGTH];
try {
s.readFrame(buffer);
fail();
} catch (IOException expected) {
// Expected
}
s.readFrame(buffer);
}
@Test