From 58a122ee28f893d2809a5dd116509b534561fdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= Date: Mon, 7 Feb 2022 15:07:47 +0100 Subject: [PATCH] Add test that checks exception handling on background threads --- .../bramble/test/ThreadExceptionTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bramble-api/src/test/java/org/briarproject/bramble/test/ThreadExceptionTest.java diff --git a/bramble-api/src/test/java/org/briarproject/bramble/test/ThreadExceptionTest.java b/bramble-api/src/test/java/org/briarproject/bramble/test/ThreadExceptionTest.java new file mode 100644 index 000000000..6491df41a --- /dev/null +++ b/bramble-api/src/test/java/org/briarproject/bramble/test/ThreadExceptionTest.java @@ -0,0 +1,32 @@ +package org.briarproject.bramble.test; + +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class ThreadExceptionTest extends BrambleTestCase { + + @Test(expected = AssertionError.class) + public void testAssertionErrorMakesTestCaseFail() { + // This is what BrambleTestCase does, too: + fail(); + } + + @Test(expected = AssertionError.class) + public void testExceptionInThreadMakesTestCaseFail() { + Thread t = new Thread(() -> { + System.out.println("thread before exception"); + throw new RuntimeException("boom"); + }); + + t.start(); + try { + t.join(); + System.out.println("joined thread"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + +}