mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
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:
@@ -31,7 +31,7 @@ public class ConsumersTest extends BriarTestCase {
|
||||
assertArrayEquals(dig, dig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testCountingConsumer() throws Exception {
|
||||
byte[] data = new byte[1234];
|
||||
CountingConsumer cc = new CountingConsumer(data.length);
|
||||
@@ -39,12 +39,7 @@ public class ConsumersTest extends BriarTestCase {
|
||||
cc.write(data, 1, data.length - 2);
|
||||
cc.write(data[data.length - 1]);
|
||||
assertEquals(data.length, cc.getCount());
|
||||
try {
|
||||
cc.write((byte) 0);
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
cc.write((byte) 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,18 +39,13 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
bdfWriterFactory = i.getInstance(BdfWriterFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testFormatExceptionIfAckIsTooLarge() throws Exception {
|
||||
byte[] b = createAck(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readAck();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,32 +57,22 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testEmptyAck() throws Exception {
|
||||
byte[] b = createEmptyAck();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readAck();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
|
||||
byte[] b = createOffer(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readOffer();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,32 +86,22 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testEmptyOffer() throws Exception {
|
||||
byte[] b = createEmptyOffer();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readOffer();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||
byte[] b = createRequest(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readRequest();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,18 +113,13 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = FormatException.class)
|
||||
public void testEmptyRequest() throws Exception {
|
||||
byte[] b = createEmptyRequest();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readRequest();
|
||||
fail();
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
private byte[] createAck(boolean tooBig) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user