下面的测试方法显示在spring-guide tutorial中。
是否有较不复杂的语法来编写此测试,或者如何将其拆分为较小的块?
verify(orderService).createOrder(
org.mockito.Matchers.<CreateOrderEvent>argThat(
allOf( org.hamcrest.Matchers.<CreateOrderEvent>
hasProperty("details",
hasProperty("dateTimeOfSubmission", notNullValue())),
org.hamcrest.Matchers.<CreateOrderEvent>hasProperty("details",
hasProperty("name", equalTo(CUSTOMER_NAME))),
org.hamcrest.Matchers.<CreateOrderEvent>hasProperty("details",
hasProperty("address1", equalTo(ADDRESS1))),
org.hamcrest.Matchers.<CreateOrderEvent>hasProperty("details",
hasProperty("postcode", equalTo(POST_CODE)))
)));
最佳答案
您可以切换hasProperty和allOf匹配器。
verify(orderService).createOrder(
org.mockito.Matchers.<CreateOrderEvent>argThat(
org.hamcrest.Matchers.<CreateOrderEvent>hasProperty("details",
allOf(
hasProperty("dateTimeOfSubmission", notNullValue()),
hasProperty("name", equalTo(CUSTOMER_NAME)),
hasProperty("address1", equalTo(ADDRESS1)),
hasProperty("postcode", equalTo(POST_CODE)))
)));