Need Help interpreting assertion message

55 views
Skip to first unread message

eyoung

unread,
Nov 9, 2010, 5:29:36 AM11/9/10
to gmock-user
Just started trying out GMock in a grails app.

It seems to me the message I'm getting is ambiguous: It says the call
was unexpected, but then it says it expected 1 but got 0.


junit.framework.AssertionFailedError: Unexpected method call
'linkOrCreateProperty(apex01.dac9-ejy, "IP Address", " Text")' on
'Mock for PropertyService (1)' 'linkOrCreateProperty(is an instance of
com.comcast.neto.chimps.domain.component.Component, is an instance of
java.lang.String, is an instance of java.lang.String)' on 'Mock for
PropertyService (2)': expected 1, actual 0

Here's the relevant code:

def prop = new Property(name: "testProp")
PropertyService mockPropService = mock(PropertyService)

mockPropService.linkOrCreateProperty(is(Component),is(String),is(String)).returns(prop)
//mockPropService.setPropertyValue(is(Property),is(String),
is(String))
play {
println "play"
csvDataImportService.importCsvData(fileService)
}



Running grails 1.3.4
GMock 0.8.1
Hamcrest matchers 1.1

Johnny Jian

unread,
Nov 9, 2010, 5:35:53 AM11/9/10
to gmock...@googlegroups.com
That means linkOrCreateProperty(apex01.dac9-ejy, "IP Address", " Text") doesn't match linkOrCreateProperty(is(Component),is(String),is(String)).

Johnny


--
You received this message because you are subscribed to the Google Groups "gmock-user" group.
To post to this group, send email to gmock...@googlegroups.com.
To unsubscribe from this group, send email to gmock-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gmock-user?hl=en.


Ed Young

unread,
Nov 9, 2010, 12:04:25 PM11/9/10
to gmock...@googlegroups.com
Having a hard time zeroing in on the problem, I'm simplifying everything to narrow things down.

It says it got an unexpected method call, but then says "expected 1, actual 1"



junit.framework.AssertionFailedError: Unexpected method call 'linkOrCreateProperty(apex01.dac9-ejy, "OS", " Text")' 'linkOrCreateProperty(is an instance of com.comcast.neto.chimps.domain.component.Component, is an instance of java.lang.String, is an instance of java.lang.String)': expected 1, actual 1

I believe I have the GMock constructed correctly, yes?

Here's the test code:

def csvDataImportService = new CsvDataImportService()
def        propertyService = mock(PropertyService)

csvDataImportService.propertyService.linkOrCreateProperty(is(Component),is(String),is(String)).returns(is(Property))
       
        play {
            println "play"
            csvDataImportService.importCsvData(fileService)
        }

Here's the code that's being mocked:
def prop = propertyService.linkOrCreateProperty( comp, param.key," Text" )
--
- Ed

Johnny Jian

unread,
Nov 9, 2010, 8:26:53 PM11/9/10
to gmock...@googlegroups.com
"expected 1, actual 1" means linkOrCreateProperty() is really called once, and the unexpected linkOrCreateProperty() is the second time being called.

In summary, linkOrCreateProperty() is called twice. The first time it matches the matcher, so gmock says "actual 1"; but the second time it doesn't match the matcher, so gmock says "unexpected", otherwise it will say "actual 1 (+1)".

However, it may be a bug of gmock. Uploading a reproduceable test case will be helpful.

PS: ".returns(is(Property))" is not correct. It should return an actual value instead of a matcher.

Johnny
Reply all
Reply to author
Forward
0 new messages