Polishing

This commit is contained in:
Juergen Hoeller
2014-09-02 22:15:53 +02:00
parent cfd01ab100
commit 98eb0f75bc
6 changed files with 56 additions and 54 deletions

View File

@@ -16,9 +16,6 @@
package org.springframework.cache.interceptor;
import static org.junit.Assert.*;
import static org.springframework.cache.CacheTestUtils.*;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@@ -26,6 +23,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
@@ -40,12 +38,16 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
import static org.springframework.cache.CacheTestUtils.*;
/**
* Provides various {@link CacheResolver} customisations scenario
*
* @author Stephane Nicoll
* @since 4.1
*/
public class CacheResolverCustomisationTests {
public class CacheResolverCustomizationTests {
private CacheManager cacheManager;
@@ -127,13 +129,13 @@ public class CacheResolverCustomisationTests {
@Test
public void noCacheResolved() {
Method m = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
try {
simpleService.noCacheResolved(new Object());
fail("Should have failed, no cache resolved");
} catch (IllegalStateException e) {
String msg = e.getMessage();
assertTrue("Reference to the method must be contained in the message", msg.contains(m.toString()));
}
catch (IllegalStateException ex) {
assertTrue("Reference to the method must be contained in the message", ex.getMessage().contains(method.toString()));
}
}
@@ -142,13 +144,13 @@ public class CacheResolverCustomisationTests {
try {
simpleService.unknownCacheResolver(new Object());
fail("Should have failed, no cache resolver with that name");
} catch (NoSuchBeanDefinitionException e) {
assertEquals("Wrong bean name in exception", "unknownCacheResolver", e.getBeanName());
}
catch (NoSuchBeanDefinitionException ex) {
assertEquals("Wrong bean name in exception", "unknownCacheResolver", ex.getBeanName());
}
}
@Configuration
@EnableCaching
static class Config extends CachingConfigurerSupport {
@@ -204,6 +206,7 @@ public class CacheResolverCustomisationTests {
}
}
@CacheConfig(cacheNames = "default")
static class SimpleService {
@@ -245,6 +248,7 @@ public class CacheResolverCustomisationTests {
}
}
/**
* Example of {@link CacheResolver} that resolve the caches at
* runtime (i.e. based on method invocation parameters).
@@ -263,6 +267,7 @@ public class CacheResolverCustomisationTests {
}
}
private static class NullCacheResolver extends AbstractCacheResolver {
private NullCacheResolver(CacheManager cacheManager) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -101,6 +101,7 @@ public class ConfigurationClassPostConstructAndAutowiringTests {
@Configuration
static class Config2 {
TestBean testBean;
@Autowired