Skip to content

Commit

Permalink
Hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Apr 25, 2024
1 parent aaf3310 commit 0ceeb45
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.assertj.core.api.Assertions;
import org.assertj.core.api.MapAssert;
import org.assertj.core.api.ObjectAssert;
import org.assertj.core.api.ThrowingConsumer;
import org.assertj.core.error.BasicErrorMessageFactory;
import org.assertj.core.internal.Failures;

Expand Down Expand Up @@ -55,6 +56,10 @@ public class MvcResultAssert extends AbstractMockHttpServletResponseAssert<MvcRe
super(jsonMessageConverter, mvcResult, MvcResultAssert.class);
}

public void and(ThrowingConsumer<MvcResultAssert> result) {
result.accept(this);
}

@Override
protected MockHttpServletResponse getResponse() {
checkHasNotFailedUnexpectedly();
Expand Down Expand Up @@ -89,6 +94,12 @@ public CookieMapAssert cookies() {
return new CookieMapAssert(this.actual.getResponse().getCookies());
}

public MvcResultAssert cookies(ThrowingConsumer<CookieMapAssert> cookies) {
cookies.accept(cookies());
return this.myself;
}


/**
* Return a new {@linkplain MediaTypeAssert assertion} object that uses the
* response's {@linkplain MediaType content type} as the object to test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ public class AssertableMockMvcIntegrationTests {
this.mockMvc = AssertableMockMvc.from(wac);
}

@Test
void hacking() {
assertThat(perform(get("/foo").accept(MediaType.APPLICATION_JSON)))
.satisfies((result) -> {
assertThat(result).hasStatusOk();
assertThat(result).cookies().containsCookie("foo");
assertThat(result).cookies().containsCookie("bar");
});

assertThat(perform(get("/foo").accept(MediaType.APPLICATION_JSON)))
.hasStatusOk()
.cookies((cookies) -> {
cookies.containsCookie("foo");
cookies.containsCookie("bar");
});

assertThat(perform(get("/foo").accept(MediaType.APPLICATION_JSON)))
.and(result -> {
result.hasStatusOk();
result.cookies().containsCookie("foo");
result.cookies().containsCookie("bar");
});
}

@Nested
class RequestTests {

Expand Down

0 comments on commit 0ceeb45

Please sign in to comment.