Fix caching tests

Update assertion to validate the proper exception type is thrown.
This commit is contained in:
Stephane Nicoll
2015-11-25 17:49:44 +01:00
parent 17df02d01e
commit c90ca15add
4 changed files with 11 additions and 7 deletions

View File

@@ -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());
}
}

View File

@@ -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>
@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

View File

@@ -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);

View File

@@ -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> {
@Override
@Cacheable("testCache")
public Long throwChecked(Object arg1) throws Exception {
throw new Exception(arg1.toString());
throw new IOException(arg1.toString());
}
@Override