jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-4729

Object.toString() called instead of coerced Map toString closure

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7.9
  • Fix Version/s: 1.9-beta-4, 1.8.4, 1.7.11
  • Component/s: mocks and stubs
  • Labels:
    None
  • Environment:
    Ubuntu linux 10.10 x86_64

    java version "1.6.0_21"
    Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

    Groovy Version: 1.7.9 JVM: 1.6.0_21

Description

Sorry to open a new issue, this is very similar to http://jira.codehaus.org/browse/GROOVY-2801

In this instance, I'm mocking the toString method on an Abstract class SocketAddress.

channel = [
getRemoteAddress: { [toString: remoteAddress] as SocketAddress },
getLocalAddress: { [toString: localAddress] as SocketAddress }
] as Channel

and during the test, I receive a failure:

org.junit.ComparisonFailure: expected:<[10.10.2.20]> but was:<[SocketAddress_groovyProxy@5a425eb9]>
at org.junit.Assert.assertEquals(Assert.java:123)
at org.junit.Assert.assertEquals(Assert.java:145)
at org.junit.Assert$assertEquals.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:165)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:177)

GROOVY-2801 was closed some time ago so I'm opening this new issue.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Travis Hume added a comment - 16/Mar/11 4:26 PM

Worked around by creating another class

channel = [
getRemoteAddress: { new MockSocketAddress(address: remoteAddress) },
getLocalAddress: { new MockSocketAddress(address: localAddress) }
] as Channel

...

class MockSocketAddress extends SocketAddress {
def address

public String toString() { address }
}

Show
Travis Hume added a comment - 16/Mar/11 4:26 PM Worked around by creating another class channel = [ getRemoteAddress: { new MockSocketAddress(address: remoteAddress) }, getLocalAddress: { new MockSocketAddress(address: localAddress) } ] as Channel ... class MockSocketAddress extends SocketAddress { def address public String toString() { address } }
Hide
Permalink
Travis Hume added a comment - 17/Mar/11 9:46 AM - edited

A minimal test case demonstrating the problem

package test

import static org.junit.Assert.*
import org.junit.Test;

class Groovy4729Test {

    @Test
    public void toStringTest() {
        def mock = [toString: { "foo" }]
        assertEquals("foo", mock.toString())
    }
}

Fails with:
org.junit.ComparisonFailure: expected:<[foo]> but was:<[[toString:test.GROOVY4729Test$_toStringTest_closure1@7c5b0668]]>

Show
Travis Hume added a comment - 17/Mar/11 9:46 AM - edited A minimal test case demonstrating the problem
package test

import static org.junit.Assert.*
import org.junit.Test;

class Groovy4729Test {

    @Test
    public void toStringTest() {
        def mock = [toString: { "foo" }]
        assertEquals("foo", mock.toString())
    }
}
Fails with: org.junit.ComparisonFailure: expected:<[foo]> but was:<[[toString:test.GROOVY4729Test$_toStringTest_closure1@7c5b0668]]>
Hide
Permalink
Travis Hume added a comment - 18/Mar/11 9:45 AM - edited

Bug persists in groovy-1.8.0-rc-3

Groovy Shell (1.8.0-rc-3, JVM: 1.6.0_21)
Type 'help' or '\h' for help.
-----------------------------------------------------------------------------------------------------
groovy:000> m = [toString: {'foo'}] as String
===> [toString:groovysh_evaluate$_run_closure1@695cd9c0]
groovy:000> assert 'foo' == m.toString()
ERROR org.codehaus.groovy.runtime.powerassert.PowerAssertionError:
assert 'foo' == m.toString()
             |  | |
             |  | [toString:groovysh_evaluate$_run_closure1@695cd9c0]
             |  [toString:groovysh_evaluate$_run_closure1@695cd9c0]
             false
        at groovysh_evaluate.run (groovysh_evaluate:2)
        ...
Show
Travis Hume added a comment - 18/Mar/11 9:45 AM - edited Bug persists in groovy-1.8.0-rc-3
Groovy Shell (1.8.0-rc-3, JVM: 1.6.0_21)
Type 'help' or '\h' for help.
-----------------------------------------------------------------------------------------------------
groovy:000> m = [toString: {'foo'}] as String
===> [toString:groovysh_evaluate$_run_closure1@695cd9c0]
groovy:000> assert 'foo' == m.toString()
ERROR org.codehaus.groovy.runtime.powerassert.PowerAssertionError:
assert 'foo' == m.toString()
             |  | |
             |  | [toString:groovysh_evaluate$_run_closure1@695cd9c0]
             |  [toString:groovysh_evaluate$_run_closure1@695cd9c0]
             false
        at groovysh_evaluate.run (groovysh_evaluate:2)
        ...

People

  • Assignee:
    Cedric Champeau
    Reporter:
    Travis Hume
Vote (0)
Watch (0)

Dates

  • Created:
    16/Mar/11 4:05 PM
    Updated:
    14/Oct/11 12:28 AM
    Resolved:
    10/Oct/11 6:53 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.