Skip to content

Commit

Permalink
Simplified code, passing only mock as parameter
Browse files Browse the repository at this point in the history
Also made the constructors package-protected, followed by IDEA hint. It's always a good idea to reduce the scope.
  • Loading branch information
mockitoguy committed Nov 25, 2018
1 parent 88a2d3d commit 38dc92d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/mockito/internal/stubbing/BaseStubbing.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
*/
package org.mockito.internal.stubbing;

import static org.mockito.internal.exceptions.Reporter.notAnException;
import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
import static org.objenesis.ObjenesisHelper.newInstance;

import org.mockito.internal.stubbing.answers.CallsRealMethods;
import org.mockito.internal.stubbing.answers.Returns;
import org.mockito.internal.stubbing.answers.ThrowsException;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.OngoingStubbing;

import static org.mockito.internal.exceptions.Reporter.notAnException;
import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
import static org.objenesis.ObjenesisHelper.newInstance;

public abstract class BaseStubbing<T> implements OngoingStubbing<T> {


// Keep strong ref to mock preventing premature garbage collection when using 'One-liner stubs'. See #1541.
private final Object strongMockRef;

public BaseStubbing(InvocationContainerImpl invocationContainer) {
this.strongMockRef = invocationContainer.invokedMock();
BaseStubbing(Object mock) {
this.strongMockRef = mock;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class ConsecutiveStubbing<T> extends BaseStubbing<T> {

private final InvocationContainerImpl invocationContainer;

public ConsecutiveStubbing(InvocationContainerImpl invocationContainer) {
super(invocationContainer);
ConsecutiveStubbing(InvocationContainerImpl invocationContainer) {
super(invocationContainer.invokedMock());
this.invocationContainer = invocationContainer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OngoingStubbingImpl<T> extends BaseStubbing<T> {
private Strictness strictness;

public OngoingStubbingImpl(InvocationContainerImpl invocationContainer) {
super(invocationContainer);
super(invocationContainer.invokedMock());
this.invocationContainer = invocationContainer;
}

Expand Down

0 comments on commit 38dc92d

Please sign in to comment.