compilation error at thenReturn method. - please advise.

5,805 views
Skip to first unread message

Raaz Sekhar

unread,
Jun 18, 2014, 4:12:39 PM6/18/14
to moc...@googlegroups.com
Getting compilation error as - "The method thenReturn(Boolean) in the type OngoingStubbing<Boolean> is not applicable for the arguments (String)"

Code:

public  AvailabilityCheckerImpl(String postCode){
this.postCode=postCode;
}
public String isPostCodeIn3DTVServiceArea(String postCode)
throws TechnicalFailureException {
// TODO Auto-generated method stub
AvailabilityCheckerImpl mockedList = mock(AvailabilityCheckerImpl.class);
when(mockedList.postCode.startsWith("TW3")).thenReturn("SERVICE_AVAILABLE");  // compilation error at the bold text

}

}

Please advise

Thanks

Marcin Grzejszczak

unread,
Jun 19, 2014, 4:58:58 AM6/19/14
to moc...@googlegroups.com
Hi!

You're doing a set of method invocations:

mockedList.postCode.startsWith("TW3")

startsWith returns a boolean so that's why thenReturn should also return a boolean. I guess you wanted to write

when(mockedList.postCode).thenReturn("SERVICE_AVAILABLE");

Btw why do you want to mock that AvailabilityCheckerImpl ? Why not pass a real instance like this new AvailabilityCheckerImpl("TW3") or sth. I don't know the real context though.


--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/d/optout.

Marcin Grzejszczak

unread,
Jun 19, 2014, 6:04:48 AM6/19/14
to moc...@googlegroups.com

Now I see that postCode is a field. I'm working with Groovy and I thought that you're using a getter :) anyway you can't mock a string and you shouldn't do that. Can you write what you want to achieve?

Reply all
Reply to author
Forward
0 new messages