David-wallace's answer explains why you encounter OOM: a mock object remembers the details of each call.
But no less important question: what now to do? In addition to what David has already proposed, the latest versions of Mockito 1.10.19, as well as the upcoming 2.0.x versions now support the so-called stubOnly mocks (see javadoc ):
stubOnly: The stub layout does not record method calls, thereby saving memory but not allowing call verification.
Scala usage example:
import org.mockito.Mockito val list = Mockito.mock(classOf[Foo], Mockito.withSettings().stubOnly()) // The syntax is a bit more concise when using ScalaTest MockitoSugar val foo = mock[Foo](Mockito.withSettings().stubOnly())
Java usage example (untested):
import org.mockito.Mockito; Foo mock = Mockito.mock(Foo.class, Mockito.withSettings().stubOnly());
source share