8000 Why does a stubOnly mock keeps reference of the last invocation? · Issue #348 · mockito/mockito · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Why does a stubOnly mock keeps reference of the last invocation? #348
Closed
@romainpiel

Description

@romainpiel

I was looking at a memory leak caused by a mock in our tests and I noticed that creating a mock this way

Foo foo = mock(Foo.class, withSettings().stubOnly());

will still keep the last invocation in memory:


I was wondering if that was on purpose? I thought the whole point of stubOnly() was to prevent allocating too much memory for nothing by preventing verify() on a mock. I think something like that would make more sense:

public class EmptyRegisteredInvocation implements RegisteredInvocations, Serializable {

    public void add(Invocation invocation) {
        // do nothing
    }

    public void removeLast() {
        // do nothing
    }

    public List<Invocation> getAll() {
        return Collections.emptyList();
    }

    public boolean isEmpty() {
        return true;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0