DATAGEODE-44 - Use Geode's DEFAULT Pool when a Pool cannot be resolved from the Spring context.

This commit is contained in:
John Blum
2017-09-22 13:40:20 -07:00
parent 8abbfda619
commit a3b41ad986
17 changed files with 362 additions and 270 deletions

View File

@@ -24,7 +24,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.data.gemfire.util.ArrayUtils.asArray;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newRuntimeException;
import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.Test;
@@ -205,19 +208,72 @@ public class SpringUtilsUnitTests {
}
@Test
public void safeGetValueReturnsSupplierValue() {
assertThat(SpringUtils.safeGetValue(() -> "test", null)).isEqualTo("test");
}
@Test
public void safeGetValueReturnsDefaultValue() {
assertThat(SpringUtils.safeGetValue(() -> { throw new RuntimeException("error"); }, "test"))
.isEqualTo("test");
public void safeGetValueReturnsSuppliedValue() {
assertThat(SpringUtils.safeGetValue(() -> "test")).isEqualTo("test");
}
@Test
public void safeGetValueReturnsNull() {
assertThat(SpringUtils.<Object>safeGetValue(() -> { throw new RuntimeException("error"); }, "test"))
assertThat(SpringUtils.<Object>safeGetValue(() -> { throw newRuntimeException("error"); })).isNull();
}
@Test
public void safeGetValueReturnsDefaultValue() {
assertThat(SpringUtils.safeGetValue(() -> { throw newRuntimeException("error"); }, "test"))
.isEqualTo("test");
}
@Test
public void safeGetValueReturnsSuppliedDefaultValue() {
Supplier<String> exceptionThrowingSupplier = () -> { throw newRuntimeException("error"); };
Supplier<String> defaultValueSupplier = () -> "test";
assertThat(SpringUtils.safeGetValue(exceptionThrowingSupplier, defaultValueSupplier)).isEqualTo("test");
}
@Test
public void safeGetValueHandlesExceptionReturnsValue() {
Supplier<String> exceptionThrowingSupplier = () -> { throw newRuntimeException("error"); };
Function<Throwable, String> exceptionHandler = exception -> {
assertThat(exception).isInstanceOf(RuntimeException.class);
assertThat(exception).hasMessage("error");
assertThat(exception).hasNoCause();
return "test";
};
assertThat(SpringUtils.safeGetValue(exceptionThrowingSupplier, exceptionHandler)).isEqualTo("test");
}
@Test(expected = IllegalStateException.class)
public void safeGetValueHandlesExceptionAndCanThrowException() {
Supplier<String> exceptionThrowingSupplier = () -> { throw newRuntimeException("error"); };
Function<Throwable, String> exceptionHandler = exception -> {
assertThat(exception).isInstanceOf(RuntimeException.class);
assertThat(exception).hasMessage("error");
assertThat(exception).hasNoCause();
throw newIllegalStateException(exception, "test");
};
try {
SpringUtils.safeGetValue(exceptionThrowingSupplier, exceptionHandler);
}
catch (IllegalStateException expected) {
assertThat(expected).hasMessage("test");
assertThat(expected).hasCauseInstanceOf(RuntimeException.class);
assertThat(expected.getCause()).hasMessage("error");
assertThat(expected.getCause()).hasNoCause();
throw expected;
}
}
}