Browse Source

Fix caching tests

Update assertion to validate the proper exception type is thrown.
pull/929/head
Stephane Nicoll 10 years ago
parent
commit
c90ca15add
  1. 7
      spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java
  2. 5
      spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
  3. 3
      spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java
  4. 3
      spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java

7
spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java vendored

@ -16,6 +16,7 @@ @@ -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 { @@ -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 { @@ -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());
}
}

5
spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java vendored

@ -16,6 +16,7 @@ @@ -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<Object> @@ -162,12 +163,12 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@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

3
spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java vendored

@ -16,6 +16,7 @@ @@ -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 { @@ -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);

3
spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java vendored

@ -16,6 +16,7 @@ @@ -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<Long> { @@ -167,7 +168,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable("testCache")
public Long throwChecked(Object arg1) throws Exception {
throw new Exception(arg1.toString());
throw new IOException(arg1.toString());
}
@Override

Loading…
Cancel
Save