{@code import ratpack.exec.ExecControl; import ratpack.exec.Promise; import ratpack.test.UnitTest; import ratpack.test.handling.HandlingResult;}public class Example public static class AsyncUpperCaseService { private final ExecControl control; public AsyncUpperCaseService(ExecControl control) { this.control = control; } public PromisetoUpper(final String lower) { return control.promise(f -> f.success(lower.toUpperCase())); } } public static void main(String[] args) throws Exception { HandlingResult result = UnitTest.requestFixture().handleChain(chain -> { ExecControl control = chain.getLaunchConfig().getExecController().getControl(); AsyncUpperCaseService service = new AsyncUpperCaseService(control); chain.get(ctx -> service.toUpper("foo").then(ctx::render)); }); assert result.rendered(String.class).equals("FOO"); } } }
Note: when using the Guice integration, the exec control is made available for injection.
|
|