// act
final var response = given()
.cookie(Cookies.GA_UNIQUE_USER_IDENTIFIER, "GA1.1.1236122116.1674662056")
.get("/tools/live-viewers/live-settings.html")
.then()
.log()
.ifValidationFails();
// assert
response
.statusCode(Response.Status.OK.getStatusCode())
.body(not(containsString("\"msg\"")))
.body(containsString("www.twitch.tv/aliizzera23</textarea>"))
.log()
;
I realise this was asked a couple years ago, probably this feature wasn't around then. But now, it's easy to just do this:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
@Test
public void test_array_pass()
{
List<String> actual = Arrays.asList("fee", "fi", "foe");
List<String> expected = Arrays.asList("fee", "fi", "foe");
assertThat(actual, is(expected));
assertThat(actual, is(not(expected)));
}
If you have a recent version of Junit installed with hamcrest, just add these imports:
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
http://junit-team.github.io/junit/javadoc/latest/org/hamcrest/CoreMatchers.html
http://junit-team.github.io/junit/javadoc/latest/org/hamcrest/core/Is.html
validator.andExpect(status().isOk()).andExpect(model().attribute("reportItems", hasItem(
allOf(
hasProperty("id", is(1L))
)
)));
validator.andExpect(model().attribute("form", hasProperty(
"importDateInitial", is(new LocalDate().minusMonths(months).toDateTimeAtStartOfDay().toDate())
)
));
validator = mockMvc.perform(get("/conciliation/equals/return.jhtml"));
validator.andDo(print());
validator.andExpect(status().isOk())
.andExpect(model().attribute("reportItems", hasItems()));
Assert.assertThat(
Arrays.asList(),
Matchers.containsInAnyOrder(Arrays.asList())
);
Se precisar validar a propriedade então implemente o equals
List<MyObject> actual = Arrays.asList(new MyObject());
for(MyObject o: Arrays.asList(new MyObject()))
Assert.assertThat(
list,
CoreMatchers.hasItem(
Matchers.samePropertyValuesAs(actual.get(i))
)
);
assertThat(
jsonPath(config).getString("dockerHost"),
CoreMatchers.anyOf(CoreMatchers.containsString("unix:"), CoreMatchers.containsString("npipe"))
);