Rename doSafeOperation(..) methods to doOperationSafely(..).
Annotate the ExceptionThrowingOperation interface with @FunctionalInterface. Catch and handle Throwable in rethrowAsRuntimeException(:ExceptionThrowingOpeation).
This commit is contained in:
@@ -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));
|
||||
|
||||
|
||||
@@ -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> T doSafeOperation(ExceptionThrowingOperation<T> operation) {
|
||||
return doSafeOperation(operation, null);
|
||||
public static <T> T doOperationSafely(ExceptionThrowingOperation<T> operation) {
|
||||
return doOperationSafely(operation, null);
|
||||
}
|
||||
|
||||
public static <T> T doSafeOperation(ExceptionThrowingOperation<T> operation, T defaultValue) {
|
||||
public static <T> T doOperationSafely(ExceptionThrowingOperation<T> 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> {
|
||||
T doExceptionThrowingOperation() throws Exception;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user