assertj / assertj

AssertJ is a library providing easy to use rich typed assertions
https://assertj.github.io/doc/
Apache License 2.0
2.63k stars 700 forks source link

Upgrading to version 3.21.0 introduces `groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method org.assertj.core.api.ObjectAssert#satisfies.` #2361

Open svametcalf opened 3 years ago

svametcalf commented 3 years ago

Summary

Greetings! Thanks for a great library!

When upgrading to the newest version of assertj-core (3.21.0), I am getting a number of the following exceptions when using assertj in Groovy.

Cannot resolve which method to invoke for [class <test_class>_closure2] due to overlapping prototypes between:
    [interface java.util.function.Consumer]
    [interface org.assertj.core.api.ThrowingConsumer]

I use a number of assertions with Groovy Closures that now need an explicit cast. For example:

def result = [1, 2, 3, 4]
assertThat(result).satisfies({assertThat(it.size()).isEqualTo(4)} as Consumer) // works, but less than ideal
assertThat(result).satisfies({assertThat(it.size()).isEqualTo(4)}) //throws in 3.21.0, but worked previously 

I believe this is caused by the Groovy interpreter attempting to implicitly cast the Closure to a java.util.function.Consumer but is unable to pick between the satisfies methods to call, because ThrowingConsumer extends Consumer.

joel-costigliola commented 3 years ago

There is a similar issue for Kotlin https://github.com/assertj/assertj-core/issues/2357 which is going to be fixed in the language (https://youtrack.jetbrains.com/issue/KT-17765).

AssertJ is meant for Java mainly, when we can we try to make things easy for other JVM languages but we don't want to reduce the java functionalities because a JVM language does not support them well.

Have you had a look if there is an improvement raised for this specific case in the Groovy project?

BeokBeok commented 3 years ago

^ Sorry to mentioned issue here. Please ignore it.

unix-junkie commented 3 years ago

Kotlin clients which rely on this API are affected by the same problem (OVERLOAD_RESOLUTION_AMBIGUITY, #2357), due to the bug in the Kotlin compiler: KT-17765.

scordio commented 2 years ago

As mentioned in https://github.com/assertj/assertj-core/issues/2357#issuecomment-1181387367, we will analyze how to better support these use cases in version 4 as they will most likely require breaking changes.