Browse Source

Merge branch '5.3.x'

pull/28674/head
Sam Brannen 4 years ago
parent
commit
6152e41249
  1. 37
      spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java

37
spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java vendored

@ -18,10 +18,12 @@ package org.springframework.cache.interceptor;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cache.support.NoOpCache; import org.springframework.cache.support.NoOpCache;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
@ -29,48 +31,49 @@ import static org.mockito.Mockito.verify;
* *
* @author Adam Ostrožlík * @author Adam Ostrožlík
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Vedran Pavic
*/ */
public class LoggingCacheErrorHandlerTests { @ExtendWith(MockitoExtension.class)
class LoggingCacheErrorHandlerTests {
@Mock
private Log logger;
@Test @Test
void handleGetCacheErrorLogsAppropriateMessage() { void handleGetCacheErrorLogsAppropriateMessage() {
Log logger = mock(Log.class); LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCacheGetError(new RuntimeException(), new NoOpCache("NOOP"), "key"); handler.handleCacheGetError(new RuntimeException(), new NoOpCache("NOOP"), "key");
verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'"); verify(this.logger).warn("Cache 'NOOP' failed to get entry with key 'key'");
} }
@Test @Test
void handlePutCacheErrorLogsAppropriateMessage() { void handlePutCacheErrorLogsAppropriateMessage() {
Log logger = mock(Log.class); LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCachePutError(new RuntimeException(), new NoOpCache("NOOP"), "key", new Object()); handler.handleCachePutError(new RuntimeException(), new NoOpCache("NOOP"), "key", new Object());
verify(logger).warn("Cache 'NOOP' failed to put entry with key 'key'"); verify(this.logger).warn("Cache 'NOOP' failed to put entry with key 'key'");
} }
@Test @Test
void handleEvictCacheErrorLogsAppropriateMessage() { void handleEvictCacheErrorLogsAppropriateMessage() {
Log logger = mock(Log.class); LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCacheEvictError(new RuntimeException(), new NoOpCache("NOOP"), "key"); handler.handleCacheEvictError(new RuntimeException(), new NoOpCache("NOOP"), "key");
verify(logger).warn("Cache 'NOOP' failed to evict entry with key 'key'"); verify(this.logger).warn("Cache 'NOOP' failed to evict entry with key 'key'");
} }
@Test @Test
void handleClearErrorLogsAppropriateMessage() { void handleClearErrorLogsAppropriateMessage() {
Log logger = mock(Log.class); LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, false);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCacheClearError(new RuntimeException(), new NoOpCache("NOOP")); handler.handleCacheClearError(new RuntimeException(), new NoOpCache("NOOP"));
verify(logger).warn("Cache 'NOOP' failed to clear entries"); verify(this.logger).warn("Cache 'NOOP' failed to clear entries");
} }
@Test @Test
void handleCacheErrorWithStacktrace() { void handleCacheErrorWithStacktrace() {
Log logger = mock(Log.class); LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(this.logger, true);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, true);
RuntimeException exception = new RuntimeException(); RuntimeException exception = new RuntimeException();
handler.handleCacheGetError(exception, new NoOpCache("NOOP"), "key"); handler.handleCacheGetError(exception, new NoOpCache("NOOP"), "key");
verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'", exception); verify(this.logger).warn("Cache 'NOOP' failed to get entry with key 'key'", exception);
} }
} }

Loading…
Cancel
Save