Skip to content

Commit

Permalink
Fix code example after API change.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaley committed Sep 21, 2014
1 parent 1630616 commit ddfde19
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 51 deletions.
51 changes: 9 additions & 42 deletions ratpack-core/src/main/java/ratpack/exec/ExecControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@
/**
* Provides methods for controlling execution(i.e. blocking, forking and calling async API), independent of the current execution.
*
* <pre class="java">
* <pre class="java">{@code
* import ratpack.exec.ExecControl;
* import ratpack.exec.Promise;
* import ratpack.exec.Fulfillment;
* import ratpack.handling.Handler;
* import ratpack.handling.Context;
* import ratpack.handling.ChainAction;
* import ratpack.func.Action;
* import ratpack.func.Actions;
*
* import ratpack.test.UnitTest;
* import ratpack.test.handling.HandlingResult;
Expand All @@ -47,49 +41,22 @@
* this.control = control;
* }
*
* public Promise&lt;String&gt; toUpper(final String lower) {
* return control.promise(new Fulfillment&lt;String&gt;() {
* protected void execute() {
* success(lower.toUpperCase());
* }
* });
* }
* }
*
* public static class ServiceUsingHandler implements Handler {
* private final AsyncUpperCaseService service;
*
* public ServiceUsingHandler(AsyncUpperCaseService service) {
* this.service = service;
* }
*
* public void handle(final Context context) {
* service.toUpper("foo").then(new Action&lt;String&gt;() {
* public void execute(String string) {
* context.render(string);
* }
* });
* public Promise<String> toUpper(final String lower) {
* return control.promise(f -> f.success(lower.toUpperCase()));
* }
* }
*
* public static void main(String[] args) throws Exception {
* HandlingResult result = UnitTest.handle(
* new ChainAction() {
* protected void execute() {
* ExecControl control = getLaunchConfig().getExecController().getControl();
* AsyncUpperCaseService service = new AsyncUpperCaseService(control);
* Handler handler = new ServiceUsingHandler(service);
*
* get(handler);
* }
* },
* Actions.noop()
* );
* 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");
* }
* }
* </pre>
* }</pre>
* <p>
* <b>Note:</b> when using the Guice integration, the exec control is made available for injection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public HandlingResult handle(Handler handler) {
}

@Override
public HandlingResult handle(Action<? super Chain> chainAction) throws Exception {
return delegate.handle(chainAction);
public HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception {
return delegate.handleChain(chainAction);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion ratpack-test/src/main/java/ratpack/test/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static HandlingResult handle(Handler handler, Action<? super RequestFixtu
public static HandlingResult handle(Action<? super Chain> chainAction, Action<? super RequestFixture> requestFixtureAction) throws Exception {
RequestFixture requestFixture = requestFixture();
requestFixtureAction.execute(requestFixture);
return requestFixture.handle(chainAction);
return requestFixture.handleChain(chainAction);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public interface RequestFixture {
* @return the effective result of the handling
* @throws HandlerTimeoutException if the handler does not produce a result in the time limit defined by this fixture
*/
@SuppressWarnings("overloads")
HandlingResult handle(Handler handler) throws HandlerTimeoutException;

/**
Expand All @@ -110,8 +109,7 @@ public interface RequestFixture {
* @throws HandlerTimeoutException if the handler does not produce a result in the time limit defined by this fixture
* @throws Exception any thrown by {@code chainAction}
*/
@SuppressWarnings("overloads")
HandlingResult handle(Action<? super Chain> chainAction) throws Exception;
HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception;

/**
* Set a request header value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public HandlingResult handle(Handler handler) throws HandlerTimeoutException {
* {@inheritDoc}
*/
@Override
public HandlingResult handle(Action<? super Chain> chainAction) throws Exception {
return getRequestFixture().handle(chainAction);
public HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception {
return getRequestFixture().handleChain(chainAction);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public HandlingResult handle(Handler handler) throws HandlerTimeoutException {
}

@Override
public HandlingResult handle(Action<? super Chain> chainAction) throws Exception {
public HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception {
LaunchConfig launchConfig = launchConfigBuilder.build();
Registry registry = registryBuilder.build();
Handler handler = Handlers.chain(launchConfig, registry, chainAction);
Expand Down

0 comments on commit ddfde19

Please sign in to comment.