spring-cloud / spring-cloud-contract

Support for Consumer Driven Contracts in Spring
https://cloud.spring.io/spring-cloud-contract
Apache License 2.0
718 stars 439 forks source link

Bug - hasSizeBetween matcher throws missing method exception under Spock test #1067

Closed springframeworkguru closed 5 years ago

springframeworkguru commented 5 years ago

The following matcher:

. . . 
                    matchers:
                        body:
                            -   path: $.links
                                type: by_type
                                minOccurrence: 1
                                maxOccurrence: 5

will generate the following assert:

            assertThat((java.lang.Iterable) parsedJson.read("\$.links", java.util.Collection.class)).as("\$.links").hasSizeBetween(1, 5)

This works fine under JUnit4.

However, when configuration is changed to generate Spock tests, the following exception is thrown:

assertThat((java.lang.Iterable) parsedJson.read("\$.links", java.util.Collection.class)).as("\$.links").hasSizeBetween(one, five)
|                               |          |                                             |              |              |    |
|                               |          |                                             |              |              1    5
|                               |          |                                             |              org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: org.assertj.core.api.ListAssert.hasSizeBetween() is applicable for argument types: (Integer, Integer) values: [1, 5]

The hasSizeBetween method accept's primitives:

    public CollectionAssert hasSizeBetween(int lowerBound, int higherBound) {
        isNotNull();
        int size = size(this.actual);
        if (!(size >= lowerBound && size <= higherBound)) {
            failWithMessage("The size <%s> is not between <%s> and <%s>", size,
                    lowerBound, higherBound);
        }
        return this;
    }

Guessing exception is related to Groovy's autoboxing.

marcingrzejszczak commented 5 years ago

Duplicate of https://github.com/spring-cloud/spring-cloud-contract/issues/1089