Skip to content

overloaded assertEquals methods do not work from Groovy #2854

@ispringer

Description

@ispringer

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/junit-framework#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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions