From c90ca15addf048ce1ea17b1149052d97a7655ea7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 25 Nov 2015 17:49:44 +0100 Subject: [PATCH] Fix caching tests Update assertion to validate the proper exception type is thrown. --- .../cache/config/AbstractAnnotationTests.java | 7 ++++--- .../cache/config/AnnotatedClassCacheableService.java | 5 +++-- .../cache/config/CustomInterceptorTests.java | 3 ++- .../cache/config/DefaultCacheableService.java | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java b/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java index bcc58fa51ad..e130596ec26 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java @@ -16,6 +16,7 @@ package org.springframework.cache.config; +import java.io.IOException; import java.util.Collection; import java.util.UUID; @@ -290,6 +291,7 @@ public abstract class AbstractAnnotationTests { service.throwChecked(arg); fail("Excepted exception"); } catch (Exception ex) { + assertEquals("Wrong exception type", IOException.class, ex.getClass()); assertEquals(arg, ex.getMessage()); } } @@ -299,9 +301,8 @@ public abstract class AbstractAnnotationTests { service.throwUnchecked(Long.valueOf(1)); fail("Excepted exception"); } catch (RuntimeException ex) { - assertTrue("Excepted different exception type and got " + ex.getClass(), - ex instanceof UnsupportedOperationException); - // expected + assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass()); + assertEquals("1", ex.getMessage()); } } diff --git a/spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java b/spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java index c65d15beca0..450a01fb024 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java +++ b/spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java @@ -16,6 +16,7 @@ package org.springframework.cache.config; +import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; import org.springframework.cache.annotation.CacheEvict; @@ -162,12 +163,12 @@ public class AnnotatedClassCacheableService implements CacheableService @Override public Long throwChecked(Object arg1) throws Exception { - throw new UnsupportedOperationException(arg1.toString()); + throw new IOException(arg1.toString()); } @Override public Long throwUnchecked(Object arg1) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(arg1.toString()); } // multi annotations diff --git a/spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java b/spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java index e1f07b9dfae..2aa49ba77b8 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java @@ -16,6 +16,7 @@ package org.springframework.cache.config; +import java.io.IOException; import java.util.Map; import org.junit.After; @@ -78,7 +79,7 @@ public class CustomInterceptorTests { } catch (RuntimeException e) { assertNotNull("missing original exception", e.getCause()); - assertEquals(Exception.class, e.getCause().getClass()); + assertEquals(IOException.class, e.getCause().getClass()); } catch (Exception e) { fail("Wrong exception type " + e); diff --git a/spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java b/spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java index f2b843375cc..f5564df56d6 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java +++ b/spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java @@ -16,6 +16,7 @@ package org.springframework.cache.config; +import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; import org.springframework.cache.annotation.CacheEvict; @@ -167,7 +168,7 @@ public class DefaultCacheableService implements CacheableService { @Override @Cacheable("testCache") public Long throwChecked(Object arg1) throws Exception { - throw new Exception(arg1.toString()); + throw new IOException(arg1.toString()); } @Override