@Test
public void testErrorCatchingRightType() {

    FutureWithTrigger<Object> futureWithTrigger = new FutureWithTrigger<>();
    DummyExceptions.DummyException1 exception = new DummyExceptions.DummyException1();
    AtomicReference<DummyExceptions.DummyException1> exceptionReference1 = new AtomicReference<>();
    AtomicReference<DummyExceptions.DummyException2> exceptionReference2 = new AtomicReference<>();
    Object test = new Object();
    Triggerer.triggerValue(test, futureWithTrigger);
    try {
        futureWithTrigger.getFuture().consume(v -> {
            throw exception;
        }).trap(DummyExceptions.DummyException2.class, e -> {
            exceptionReference2.set(e);  //This should never be called
            throw e;
        }).trap(DummyExceptions.DummyException1.class, e -> {
            exceptionReference1.set(e); //This should be called because of the type
            throw e;
        }).await();
        fail("Exception should have been thrown");
    } catch (Exception catchedException) {
        assertEquals(exception, exceptionReference1.get());
        assertNull(exceptionReference2.get());
        assertEquals(exception, catchedException);
    }
}