From d81949074b4537f7e576c431b428e6e14e3d7dc2 Mon Sep 17 00:00:00 2001 From: John Blum Date: Sat, 26 May 2018 17:03:51 -0700 Subject: [PATCH] Rename doSafeOperation(..) methods to doOperationSafely(..). Annotate the ExceptionThrowingOperation interface with @FunctionalInterface. Catch and handle Throwable in rethrowAsRuntimeException(:ExceptionThrowingOpeation). --- .../gemfire/tests/mock/GemFireMockObjectsSupport.java | 10 +++++----- .../data/gemfire/tests/util/ObjectUtils.java | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupport.java b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupport.java index f270c30..6b85057 100644 --- a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupport.java +++ b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/mock/GemFireMockObjectsSupport.java @@ -30,7 +30,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.tests.util.IOUtils.doSafeIo; -import static org.springframework.data.gemfire.tests.util.ObjectUtils.doSafeOperation; import static org.springframework.data.gemfire.tests.util.ObjectUtils.rethrowAsRuntimeException; import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; import static org.springframework.data.gemfire.util.CollectionUtils.asSet; @@ -135,6 +134,7 @@ import org.springframework.data.gemfire.IndexType; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; import org.springframework.data.gemfire.tests.mock.support.MockObjectInvocationException; import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.tests.util.ObjectUtils; import org.springframework.util.Assert; /** @@ -1928,16 +1928,16 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport { when(mockLuceneQuery.getLimit()).thenReturn(limit); when(mockLuceneQuery.getPageSize()).thenReturn(pageSize); - doSafeOperation(() -> when(mockLuceneQuery.findKeys()) + ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findKeys()) .thenReturn(Collections.emptySet()), Collections.emptySet()); rethrowAsRuntimeException(() -> when(mockLuceneQuery.findPages()) .thenThrow(newUnsupportedOperationException("Operation Not Supported!"))); - doSafeOperation(() -> when(mockLuceneQuery.findResults()) + ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findResults()) .thenReturn(Collections.emptyList()), Collections.emptyList()); - doSafeOperation(() -> when(mockLuceneQuery.findValues()) + ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findValues()) .thenReturn(Collections.emptyList()), Collections.emptyList()); return mockLuceneQuery; @@ -1990,7 +1990,7 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport { return luceneIndexes.get(LuceneIndexKey.of(indexName, regionPath)); }); - doSafeOperation(() -> + ObjectUtils.doOperationSafely(() -> when(mockLuceneService.waitUntilFlushed(anyString(), anyString(), anyLong(), any(TimeUnit.class))) .thenReturn(true)); diff --git a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/util/ObjectUtils.java b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/util/ObjectUtils.java index 67cba36..7c1d48a 100644 --- a/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/util/ObjectUtils.java +++ b/spring-test-data-geode/src/main/java/org/springframework/data/gemfire/tests/util/ObjectUtils.java @@ -17,7 +17,7 @@ package org.springframework.data.gemfire.tests.util; /** - * {@link ObjectUtils} is a utility class for working with {@link Object objects}. + * {@link ObjectUtils} is a utility class for performing different opeations on {@link Object objects}. * * @author John Blum * @see java.lang.Object @@ -26,11 +26,11 @@ package org.springframework.data.gemfire.tests.util; @SuppressWarnings("all") public abstract class ObjectUtils { - public static T doSafeOperation(ExceptionThrowingOperation operation) { - return doSafeOperation(operation, null); + public static T doOperationSafely(ExceptionThrowingOperation operation) { + return doOperationSafely(operation, null); } - public static T doSafeOperation(ExceptionThrowingOperation operation, T defaultValue) { + public static T doOperationSafely(ExceptionThrowingOperation operation, T defaultValue) { try { return operation.doExceptionThrowingOperation(); @@ -48,11 +48,12 @@ public abstract class ObjectUtils { catch (RuntimeException cause) { throw cause; } - catch (Exception cause) { + catch (Throwable cause) { throw new RuntimeException(cause); } } + @FunctionalInterface public interface ExceptionThrowingOperation { T doExceptionThrowingOperation() throws Exception; }