private ValueResolver<Object> createIterativeResolver(Object value) { return resolver.cloneReplacingValueAndType(value, Object.class) .recursive(false); }
<S> ValueResolver<S> cloneReplacingValueAndType(Object newValue, Class<S> superType) { // superType expected to be either type or Object.class if (!superType.isAssignableFrom(type)) { throw new IllegalStateException("superType must be assignable from " + type); } ValueResolver<S> result = new ValueResolver<S>(newValue, superType) .context(exec).description(description) .embedResolutionInTask(embedResolutionInTask) .deep(forceDeep) .timeout(timeout) .immediately(immediately) .recursive(recursive); if (returnDefaultOnGet) { if (!superType.isInstance(defaultValue)) { throw new IllegalStateException("Existing default value " + defaultValue + " not compatible with new type " + superType); } @SuppressWarnings("unchecked") S typedDefaultValue = (S)defaultValue; result.defaultValue(typedDefaultValue); } if (swallowExceptions) result.swallowExceptions(); return result; }
public void testNonRecursiveBlocking() throws Exception { Object result = Tasks.resolving(new WrappingImmediateAndDeferredSupplier(new FailingImmediateAndDeferredSupplier())) .as(Object.class) .context(app) .immediately(false) .recursive(false) .get(); assertEquals(result.getClass(), FailingImmediateAndDeferredSupplier.class); }
public void testNonRecursiveImmediately() throws Exception { Object result = Tasks.resolving(new WrappingImmediateAndDeferredSupplier(new FailingImmediateAndDeferredSupplier())) .as(Object.class) .context(app) .immediately(true) .recursive(false) .get(); assertEquals(result.getClass(), FailingImmediateAndDeferredSupplier.class); }
public void testNonRecursiveImmediateFailsOnNonObjectType() throws Exception { try { Tasks.resolving(new WrappingImmediateAndDeferredSupplier(new FailingImmediateAndDeferredSupplier())) .as(FailingImmediateAndDeferredSupplier.class) .context(app) .immediately(true) .recursive(false) .get(); Asserts.shouldHaveFailedPreviously("recursive(true) accepts only as(Object.class)"); } catch (IllegalStateException e) { Asserts.expectedFailureContains(e, "must be Object"); } }
public void testNonRecursiveBlockingFailsOnNonObjectType() throws Exception { try { Tasks.resolving(new WrappingImmediateAndDeferredSupplier(new FailingImmediateAndDeferredSupplier())) .as(FailingImmediateAndDeferredSupplier.class) .context(app) .immediately(false) .recursive(false) .get(); Asserts.shouldHaveFailedPreviously("recursive(true) accepts only as(Object.class)"); } catch (IllegalStateException e) { Asserts.expectedFailureContains(e, "must be Object"); } }