How do I simplify mockito/hamcrest argument matchers in test method?

Pete_ch

The test method below appear in a spring-guide tutorial. Is there a less convoluted syntax to write this test or how can I break it apart into smaller chunks?

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)))
    )));
Stefan Birkner

You could switch the hasProperty and the allOf matchers.

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)))
    )));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do Mockito matchers work?

From Dev

How do I test a very simple void method in jUnit?

From Dev

How do I test a .sample method in rspec?

From Dev

How do I simplify this jQuery?

From Dev

How do I test out my program in the main method?

From Dev

How do I simplify this div loop

From Dev

How do I unit test a method to add an item to a database?

From Dev

How do I debug a failing test method in NCrunch

From Dev

How do I test the order of method calls in rspec?

From Dev

How do I test the rescue block of a method with rspec mocks 3.3

From Dev

How do I simplify the following code?

From Dev

How do I test a method that requires a file's presence?

From Dev

How do I test a method in Django which closes the database connection?

From Dev

How can I mock this argument matchers?

From Dev

How do I test a method that requires a file's presence?

From Dev

How do I simplify this expression?

From Dev

How do I test this particular method?

From Dev

How do I create a method with a Class as an argument?

From Dev

How do I simplify minterms of a truth table?

From Dev

How do I call a method with a generic type T[] as an argument?

From Dev

How do I use a method as an argument for another method?

From Dev

How do i pass a class as an argument and then use a shared method of that class?

From Dev

How can I simplify this method

From Dev

How do I test a postconstruct method

From Dev

How do I debug a failing test method in NCrunch

From Dev

How do I test the order of method calls in rspec?

From Dev

How do I simplify a conditional with multiple or statements?

From Dev

How do I simplify the following code?

From Dev

How do I simplify my code?

Related Related

HotTag

Archive