Skip to content

Commit

Permalink
yegor256#377: Some improvements of TkProxy class.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdragan committed Oct 31, 2015
1 parent 1faf827 commit ee9ff32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/takes/tk/TkProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @since 0.25
*/
@ToString
@EqualsAndHashCode
@EqualsAndHashCode(of = { "origin", "rqtransformer", "rstransformer" })
public final class TkProxy implements Take {

/**
Expand Down Expand Up @@ -111,9 +111,11 @@ public Request transform(final Request request) {

@Override
public Response act(final Request req) throws IOException {
final Request transformed = this.rqtransformer.transform(req);
final Response response = this.origin.act(transformed);
return this.rstransformer.transform(response);
return this.rstransformer.transform(
this.origin.act(
this.rqtransformer.transform(req)
)
);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/takes/tk/TkProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.takes.Response;
import org.takes.Take;
import org.takes.rq.RqFake;
import org.takes.rs.RsText;
import org.takes.tk.TkProxy.RqTransformer;
import org.takes.tk.TkProxy.RsTransformer;

Expand All @@ -50,8 +51,8 @@ public final class TkProxyTest {
@Test
public void proxiesRequest() throws IOException {
final Take take = Mockito.mock(Take.class);
final Request transformed = Mockito.mock(Request.class);
final Response response = Mockito.mock(Response.class);
final Request transformed = new RqFake("transformed request");
final Response response = new RsText("response");
Mockito.when(take.act(transformed)).thenReturn(response);
final TkProxy tkProxy = new TkProxy(
take,
Expand All @@ -76,8 +77,8 @@ public Request transform(final Request request) {
@Test
public void proxiesResponse() throws IOException {
final Take take = Mockito.mock(Take.class);
final Request request = Mockito.mock(Request.class);
final Response transformed = Mockito.mock(Response.class);
final Request request = new RqFake("request");
final Response transformed = new RsText("transformed response");
final TkProxy tkProxy = new TkProxy(
take,
new RsTransformer() {
Expand Down

0 comments on commit ee9ff32

Please sign in to comment.