目前我有以下-
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("$.message",
org.hamcrest.Matchers.equalTo("storeCode cannot be blank text; storeCode cannot be null")));
如何在上面添加
OR
条件,如下所示(当然,下面不起作用)
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("$.message",
org.hamcrest.Matchers.equalTo("storeCode cannot be blank text; storeCode cannot be null").OR.equalTo("storeCode cannot be null; storeCode cannot be blank text")));
either
、anyOf
或 oneOf
匹配器。
either
:
.andExpect(
MockMvcResultMatchers.jsonPath(
"$.message",
Matchers.either(Matchers.equalTo("storeCode cannot be blank text; storeCode cannot be null"))
.or(Matchers.equalTo("storeCode cannot be null; storeCode cannot be blank text"))));
anyOf
:
.andExpect(
MockMvcResultMatchers.jsonPath(
"$.message",
Matchers.anyOf(
Matchers.equalTo("storeCode cannot be blank text; storeCode cannot be null"),
Matchers.equalTo("storeCode cannot be null; storeCode cannot be blank text"))));
oneOf
:
.andExpect(
MockMvcResultMatchers.jsonPath(
"$.message",
Matchers.oneOf(
"storeCode cannot be blank text; storeCode cannot be null",
"storeCode cannot be null; storeCode cannot be blank text")));
matchesPattern
:
.andExpect(
MockMvcResultMatchers.jsonPath(
"$.message",
Matchers.matchesPattern(
"storeCode cannot be blank text; storeCode cannot be null|storeCode cannot be null; storeCode cannot be blank text"))));