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 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
@ -290,6 +291,7 @@ public abstract class AbstractAnnotationTests {
service.throwChecked(arg); service.throwChecked(arg);
fail("Excepted exception"); fail("Excepted exception");
} catch (Exception ex) { } catch (Exception ex) {
assertEquals("Wrong exception type", IOException.class, ex.getClass());
assertEquals(arg, ex.getMessage()); assertEquals(arg, ex.getMessage());
} }
} }
@ -299,9 +301,8 @@ public abstract class AbstractAnnotationTests {
service.throwUnchecked(Long.valueOf(1)); service.throwUnchecked(Long.valueOf(1));
fail("Excepted exception"); fail("Excepted exception");
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
assertTrue("Excepted different exception type and got " + ex.getClass(), assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass());
ex instanceof UnsupportedOperationException); assertEquals("1", ex.getMessage());
// expected
} }
} }

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

@ -16,6 +16,7 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
@ -162,12 +163,12 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override @Override
public Long throwChecked(Object arg1) throws Exception { public Long throwChecked(Object arg1) throws Exception {
throw new UnsupportedOperationException(arg1.toString()); throw new IOException(arg1.toString());
} }
@Override @Override
public Long throwUnchecked(Object arg1) { public Long throwUnchecked(Object arg1) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException(arg1.toString());
} }
// multi annotations // multi annotations

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

@ -16,6 +16,7 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.junit.After; import org.junit.After;
@ -78,7 +79,7 @@ public class CustomInterceptorTests {
} }
catch (RuntimeException e) { catch (RuntimeException e) {
assertNotNull("missing original exception", e.getCause()); assertNotNull("missing original exception", e.getCause());
assertEquals(Exception.class, e.getCause().getClass()); assertEquals(IOException.class, e.getCause().getClass());
} }
catch (Exception e) { catch (Exception e) {
fail("Wrong exception type " + e); fail("Wrong exception type " + e);

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

@ -16,6 +16,7 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
@ -167,7 +168,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override @Override
@Cacheable("testCache") @Cacheable("testCache")
public Long throwChecked(Object arg1) throws Exception { public Long throwChecked(Object arg1) throws Exception {
throw new Exception(arg1.toString()); throw new IOException(arg1.toString());
} }
@Override @Override

Loading…
Cancel
Save