Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overloaded assertEquals methods do not work from Groovy #2854

Closed
2 of 7 tasks
ispringer opened this issue Dec 14, 2022 · 9 comments · Fixed by #2858
Closed
2 of 7 tasks

overloaded assertEquals methods do not work from Groovy #2854

ispringer opened this issue Dec 14, 2022 · 9 comments · Fixed by #2858

Comments

@ispringer
Copy link
Contributor

ispringer commented Dec 14, 2022

After upgrading to TestNG 7.7.0, we started seeing a bunch of "Ambiguous method overloading for method org.testng.Assert#assertEquals." GroovyRuntimeExceptions when running our Groovy-based tests. We did not see these exceptions with TestNG 7.4.x.

Note, JUnit 5 had a similar issue, that they have fixed (see junit-team/junit5#1710).

TestNG Version

7.7.0

Expected behavior

The overloaded Assert#assertEquals methods should work.

Actual behavior

We get exceptions like the following when running our tests:

23:16:31  groovy.lang.GroovyRuntimeException: 
23:16:31  Ambiguous method overloading for method org.testng.Assert#assertEquals.
23:16:31  Cannot resolve which method to invoke for [class java.lang.Integer, class java.lang.Integer] due to overlapping prototypes between:
23:16:31  	[int, class java.lang.Integer]
23:16:31  	[class java.lang.Integer, int]
23:16:31  	at groovy.lang.MetaClassImpl.doChooseMostSpecificParams(MetaClassImpl.java:3354)
23:16:31  	at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3330)
23:16:31  	at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3320)
23:16:31  	at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3264)
23:16:31  	at groovy.lang.MetaClassImpl.pickStaticMethod(MetaClassImpl.java:1594)
23:16:31  	at groovy.lang.MetaClassImpl.retrieveStaticMethod(MetaClassImpl.java:1491)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.Selector$MethodSelector.chooseMeta(Selector.java:597)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.Selector$MethodSelector.setCallSiteTarget(Selector.java:1010)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.fallback(IndyInterface.java:351)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.access$000(IndyInterface.java:49)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface$FallbackSupplier.get(IndyInterface.java:281)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.lambda$fromCache$1(IndyInterface.java:301)
23:16:31  	at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.lambda$compute$0(ConcurrentLinkedHashMap.java:788)
23:16:31  	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
23:16:31  	at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.compute(ConcurrentLinkedHashMap.java:800)
23:16:31  	at org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.computeIfAbsent(ConcurrentLinkedHashMap.java:777)
23:16:31  	at org.codehaus.groovy.runtime.memoize.LRUCache.getAndPut(LRUCache.java:63)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.CacheableCallSite.getAndPut(CacheableCallSite.java:48)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.lambda$fromCache$2(IndyInterface.java:298)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.doWithCallSite(IndyInterface.java:367)
23:16:31  	at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:295)

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

All of these tests fail with TestNG 7.7.0:

import org.testng.annotations.Test

import static org.testng.Assert.assertEquals

class AssertEqualsBugTest {

    @Test
    void testAssertEqualsWorksWithBooleans() {
        assertEquals(true, true)
    }

    @Test
    void testAssertEqualsWorksWithBytes() {
        assertEquals(Byte.valueOf((byte) 10), Byte.valueOf((byte) 10))
    }

    @Test
    void testAssertEqualsWorksWithChars() {
        assertEquals(Character.valueOf((char) 10), Character.valueOf((char) 10))
    }

    @Test
    void testAssertEqualsWorksWithShorts() {
        assertEquals(Short.valueOf((short) 10), Short.valueOf((short) 10))
    }

    @Test
    void testAssertEqualsWorksWithInts() {
        assertEquals(10, 10)
    }

    @Test
    void testAssertEqualsWorksWithLongs() {
        assertEquals(Long.valueOf((long) 10), Long.valueOf((long) 10))
    }

    @Test
    void testAssertEqualsWorksWithFloats() {
        assertEquals(Float.valueOf((float) 10), Float.valueOf((float) 10))
    }

    @Test
    void testAssertEqualsWorksWithDoubles() {
        assertEquals(Double.valueOf((double) 10), Double.valueOf((double) 10))
    }

}

Contribution guidelines

In case you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

@krmahadevan
Copy link
Member

@ispringer - I will take a look at this over the weekend.

@ispringer
Copy link
Contributor Author

@krmahadevan - Wow, amazing turnaround time! Thanks!

@ispringer
Copy link
Contributor Author

@krmahadevan, any chance you can release a 7.7.1 with this fix? It would allow my team to avoid refactoring a couple hundred assertEquals calls in order to upgrade to 7.x.

@krmahadevan
Copy link
Member

@ispringer - Yes we can do a bug fix release. Lets wait till this weekend to see if there are any more discrepancies that need to be addressed. If there's nothing, then first thing Monday morning (Dec 26) you should see a bug fix release ?

@juherr - What do you think ?

@juherr
Copy link
Member

juherr commented Dec 21, 2022

@krmahadevan Great for me. But not need to ask : make a release when you think it is needed.

@krmahadevan
Copy link
Member

@ispringer - I have created a 7.7.1 release and staged it.
You can consume it as below.

If you are using Maven, then please add the below repository and bump the dependency version to 7.7.1

<repository>
    <id>maven-central-staging</id>
    <url>https://oss.sonatype.org/content/repositories/orgtestng-1085</url>
</repository>

If you are using Gradle, then please add the below repository and bump the dependency version to 7.7.1

repositories {
    mavenCentral()

    maven {
        url 'https://oss.sonatype.org/content/repositories/orgtestng-1085' }
}

Once I get a confirmation from you, I will go ahead and publish 7.7.1 into Maven Central and wrap the release.

@ispringer
Copy link
Contributor Author

@krmahadevan, I just tried it out. All my project's tests run successfully without any assertEquals exceptions. Thanks again!

@krmahadevan krmahadevan modified the milestones: 7.8.0, 7.7.1 Dec 29, 2022
@krmahadevan
Copy link
Member

@ispringer - Thank you for the confirmation. 7.7.1 is now released. Happy new year in advance :)

https://repo1.maven.org/maven2/org/testng/testng/7.7.1/

@alrobertson
Copy link

Thanks very much. Just had the same issue and this resolved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants