Skip to content

Commit c90ca15

Browse files
committed
Fix caching tests
Update assertion to validate the proper exception type is thrown.
1 parent 17df02d commit c90ca15

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.io.IOException;
1920
import java.util.Collection;
2021
import java.util.UUID;
2122

@@ -290,6 +291,7 @@ public void testCheckedThrowable(CacheableService<?> service) throws Exception {
290291
service.throwChecked(arg);
291292
fail("Excepted exception");
292293
} catch (Exception ex) {
294+
assertEquals("Wrong exception type", IOException.class, ex.getClass());
293295
assertEquals(arg, ex.getMessage());
294296
}
295297
}
@@ -299,9 +301,8 @@ public void testUncheckedThrowable(CacheableService<?> service) throws Exception
299301
service.throwUnchecked(Long.valueOf(1));
300302
fail("Excepted exception");
301303
} catch (RuntimeException ex) {
302-
assertTrue("Excepted different exception type and got " + ex.getClass(),
303-
ex instanceof UnsupportedOperationException);
304-
// expected
304+
assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass());
305+
assertEquals("1", ex.getMessage());
305306
}
306307
}
307308

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.io.IOException;
1920
import java.util.concurrent.atomic.AtomicLong;
2021

2122
import org.springframework.cache.annotation.CacheEvict;
@@ -162,12 +163,12 @@ public Number nullInvocations() {
162163

163164
@Override
164165
public Long throwChecked(Object arg1) throws Exception {
165-
throw new UnsupportedOperationException(arg1.toString());
166+
throw new IOException(arg1.toString());
166167
}
167168

168169
@Override
169170
public Long throwUnchecked(Object arg1) {
170-
throw new UnsupportedOperationException();
171+
throw new UnsupportedOperationException(arg1.toString());
171172
}
172173

173174
// multi annotations

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.io.IOException;
1920
import java.util.Map;
2021

2122
import org.junit.After;
@@ -78,7 +79,7 @@ public void customInterceptorAppliesWithCheckedException() {
7879
}
7980
catch (RuntimeException e) {
8081
assertNotNull("missing original exception", e.getCause());
81-
assertEquals(Exception.class, e.getCause().getClass());
82+
assertEquals(IOException.class, e.getCause().getClass());
8283
}
8384
catch (Exception e) {
8485
fail("Wrong exception type " + e);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.io.IOException;
1920
import java.util.concurrent.atomic.AtomicLong;
2021

2122
import org.springframework.cache.annotation.CacheEvict;
@@ -167,7 +168,7 @@ public Number nullInvocations() {
167168
@Override
168169
@Cacheable("testCache")
169170
public Long throwChecked(Object arg1) throws Exception {
170-
throw new Exception(arg1.toString());
171+
throw new IOException(arg1.toString());
171172
}
172173

173174
@Override

0 commit comments

Comments
 (0)