I'm getting the same error. The real code is.
Limit cachedLimit = mock(Limit.class);
String cacheKey = "limexCode:2010-07-22:false";
Element cacheElement = new Element(cacheKey, cachedLimit);
Cache cache = mock(Cache.class);
doReturn(cacheElement).when(cache).get(Matchers.<Serializable>anyObject())
I used null in my previous example to show prove that the error wasn't
caused by the cacheElement.
The issue is that the real get method code is being called.
Thanks,
Peter
On Jul 8, 2:30 pm, Max <
maxon...@gmail.com> wrote:
> Use doReturn(null).when(cache).get(anyObject());
>
> Also since you're mocking Cache it should return null by default. You don't
> have to stub it.
>
> On Thu, Jul 8, 2010 at 2:09 PM, Peter <
proggerp...@gmail.com> wrote:
> > I'm getting null pointers when trying to create a mock object. I'm a
> > little confused as I thought the whole point was that the actual code
> > of the mocked class would not be executed.
>
> > However I'm trying to mock a net.sf.ehcacheCache object
>
> > Cache cache = mock(Cache.class);
> > when(cache.get(anyObject())).thenReturn(null);
>
> > I get a null pointer exception when cache.get tries to access the
> > private variable 'status' which is null.
>
> > This seems so basic that I must be doing something foolish.
>
> > Thanks,
> > Peter
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mockito" group.
> > To post to this group, send email to
moc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> >
mockito+u...@googlegroups.com<
mockito%2Bunsu...@googlegroups.com>
> > .