From 927e0b077ee55c41ca719a46b2f544047aabae33 Mon Sep 17 00:00:00 2001 From: Jens Wilke Date: Tue, 17 Oct 2017 12:18:18 +0200 Subject: [PATCH] Allow cache implementations to wrap the EntryProcessorException, closes #85 --- .../jsr107/tck/processor/CacheInvokeTest.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cache-tests/src/test/java/org/jsr107/tck/processor/CacheInvokeTest.java b/cache-tests/src/test/java/org/jsr107/tck/processor/CacheInvokeTest.java index 55d0db0..943c8ac 100644 --- a/cache-tests/src/test/java/org/jsr107/tck/processor/CacheInvokeTest.java +++ b/cache-tests/src/test/java/org/jsr107/tck/processor/CacheInvokeTest.java @@ -202,8 +202,9 @@ public void noValueException() { cache.invoke(key, new CombineEntryProcessor(processors)); fail(); } catch (CacheException e) { - assertTrue("expected IllegalAccessError; observed " + e.getCause(), - e.getCause() instanceof IllegalAccessError); + Throwable rootCause = getRootCause(e); + assertTrue("expected IllegalAccessError; observed " + rootCause, + rootCause instanceof IllegalAccessError); } assertFalse(cache.containsKey(key)); } @@ -230,6 +231,13 @@ public void existingReplace() { assertEquals(newValue, cache.get(key)); } + private static Throwable getRootCause(Throwable t) { + if (t.getCause() == null) { + return t; + } + return getRootCause(t.getCause()); + } + @Test public void existingException() { final Integer key = 123; @@ -246,8 +254,9 @@ public void existingException() { cache.invoke(key, new CombineEntryProcessor(processors)); fail(); } catch (CacheException e) { - assertTrue("expected IllegalAccessError; observed " + e.getCause(), - e.getCause() instanceof IllegalAccessError); + Throwable rootCause = getRootCause(e); + assertTrue("expected IllegalAccessError; observed " + rootCause, + rootCause instanceof IllegalAccessError); } assertEquals(oldValue, cache.get(key)); } @@ -287,8 +296,9 @@ public void removeException() { cache.invoke(key, new ThrowExceptionEntryProcessor(IllegalAccessError.class)); fail(); } catch (CacheException e) { - assertTrue("expected IllegalAccessError; observed " + e.getCause(), - e.getCause() instanceof IllegalAccessError); + Throwable t = getRootCause(e); + assertTrue("expected IllegalAccessError; observed " + t, + t instanceof IllegalAccessError); } assertEquals(oldValue, cache.get(key)); }