Repository: mockito/mockito
Issue: Refactor instance based utility classes to static utility classes

The internal implementation of Mockito contains numerous helper classed that serve as a container for useful methods. By its nature these classes don't have a state. Currently some them are instance based in other word you need to create the utility class to call a helper method. This not only pollutes the heap but also the code cause instance methods can't be imported statically. 

Here is an example:

```java
Helper helper = new Helper();
if (helper.isInputValid(input)){
  [...] 
}
```

vs. static import of Helper.isInputValid

```java
if (isInputValid(input)){
  [...] 
}
```

The aim of this ticket is to identify canidates that can be refactored to static utility classes. If you like to refactoring and mockito feel free to send a PR and reference this issue.

Refactoring canidates:
- [ ] `AccessibilityChanger`
- [ ] `BeanPropertySetter`
- [ ] `ConditionalStackTraceFilter`
- [ ] `FieldCopier`
- [ ] `FieldReader`
- [ ] `GenericMaster` should be integrate into `GenericTypeResolver`
- [ ] `JUnitFailureHacker` can be removed when the deprecated `VerboseMockitoJUnitRunner` is removed
- [ ] `LenientCopyTool`
- [ ] `MatcherBinder`
- [ ] `MockitoCore` should better be a singleton
- [x] `MockCreationValidator`
- [ ] `RemoveFirstLine`
- [x] #591 `ArgumentMatchingTool`
- [x] #515 `AllInvocationsFinder`
- [x] #502 `ArgumentsComparator`
- [x] #540 `ArrayUtils`
- [x] #490 `AtLeastXNumberOfInvocationsChecker`
- [x] #490 `AtLeastXNumberOfInvocationsInOrderChecker`
- [ ] #912 `Constructors`
- [x] #427 `FieldSetter`
- [x] #908 `FriendlyExceptionMaker`
- [x] #431 `HandyReturnValues` 
- [x] #432 `InvocationMarker`
- [x] #462 `InvocationsFinder`
- [x] #908 `JUnitDetecter`
- [x] #490 `MissingInvocationChecker`
- [x] #490 `MissingInvocationInOrderChecker`
- [x] #514 `MockUtil`
- [x] #503 `NonGreedyNumberOfInvocationsInOrderChecker`
- [x] #907 `NumberOfInvocationsInOrderChecker`
- [x] #907 `NumberOfInvocationsChecker`
- [x] #547 `ObjectMethodsGuru`
- [x] #427 `Reporter`
- [x] #535 `SuperTypesLastSorter`
- [x] #501 `TestMethodFinder`
- [x] #515 `VerifiableInvocationsFinder`


Issue comments:
@raphw thanks for merging the PR that fast!  Would you mind reopening this ticket? There are more classes that can be refactored that way, I would like to extend the list.

Big :+1: for me btw, but please keep the pull requests managable and as small as possible. Preferably refactoring 1 method at a time. That way it is a lot easier to review.

I agree, there is nothing wrong with multiple PRs, the quick merge is a reaction to an easy overview (and being stuck at an Ukrainian airport without access to the Eurocup).

There are still two unit tests failing, could you have a look @ChristianSchwarz - I just had a quick look and there are two unit tests failing which seems related to the way you refactored the previous stubbing of the `Reporter`.

I should have checked more thoroughly before merging, hopefully you can fix the problem soon. Alternatively, I will just rollback the one commit (the first one is good) and we can reapply the patch once you fixed the two unit tests. Thank you, really, this was great clean-up.

I fixed the one test error. I push it tonight.

PS: I also fixed a bug in the stack trace cleaner. Not a biggy but please do not `@Ignore` tests. Especially in big commits, it is easy to miss that single annotation.

@raphw Which test(s) is/are failing? I will fix it asap! Too bad that some test fail on a regulare base, is it possible to ignore them in the ide only?

You can see the build output here: https://travis-ci.org/mockito/mockito#L254-L269

I advise you to run the tests with `./gradlew build`. This should work.

@TimvdLippe know what you mean! The next PR's include only one refactored class at a time.

I have it all fixed on local but I did not have access to wifi without 22 blocked. Will commit soon.

@raphw can you please reopen this issue 

Sorry, GitHub automatically closes issues that reference a PR.

@ChristianSchwarz If a commit contains a comment like "Fixes #426" the mentioned issue is automatically closed by github.

@PascalSchumacher Good to know! I will leave it out for the upcoming PR's. Thanks!

Now that we are pulling in static methods, I would like to propose a new (linter) rule. To make it easier to read a file, I would like that all methods invoked in the current class are referenced with `this.` (and `super.` for that matter). Therefore if we see `this.verify`, we know it is in the current class and the same object, whereas `verify` references a static method in this class, or an imported static method. Do you agree @mockito/developers ?

> I would like that all methods invoked in the current class are referenced with this. (and super. for that matter).

To me it feels like unnecessary/duplicate code cause `this` is implicit. Adding `this.` before every instance call would create a lot more text and would IMHO reduce readability. E.g.:

`this.doSometing(this.withPrivateMethod())` vs. `doSomething(withPrivateMethod())`

> Therefore if we see this.verify, we know it is in the current class and the same object, whereas verify references a static method in this class, or an imported static method.

An other option avoid ambiguity is to qualify static methods via its class name.  This way you can also distinguish which verify(..) is called ( `MockitoCore.verify(..)` / `Mocktio.verify(..)`) , which is not an easy task when a static import is used.

I'm not coding too much in Mockito ATM (hopefully now after SpringOne conference I'll have more time) but I fully agree with @ChristianSchwarz . IMO the best solution is to: 
- omit `this` before method calls. 
- if necessary provide the class for static method call

Respectful -1

I like when the class formally declares collaborators instead of calling out to static methods. This makes it easy to reason about the code. I don't need to read every line of code in the class to find out external couplings realized via static methods. I can see the couplings via fields, I can easily query how the field variable is used, etc. Another use case is when we discover missing/incorrect unit test coverage (or we do some larger refactorings) and we cannot easily write tests because code is too procedural.

The benefits for converting to static utilities have minimal significance to me. Yet, there is a downside I care about (e.g. maintainability of procedural code, static methods that consume static methods, that consume static methods...).

Hence, I down vote this sort of changes. Going down this path, all stateless classes in Mockito would become static utilities :)

You can get +1's from other maintainers and have your changes merged - I'm not here to block your changes but to give honest feedback. I see merit in arguments for static utilities. They do not outweigh the cost in my opinion.

I'm mitigated about this as well. I understand well that mockito creates garbage, but they are short lived and **most probably** won't go in the old generation especially in the test phase. Yet the faster the tests are the more developers will run them, it **may** have impacts on big projects. Also design wise I don't like much static methods too.

However I don't totally agree with the above points : 

> I don't need to read every line of code in the class to find out external couplings realized via static methods. I can see the couplings via fields, I can easily query how the field variable is used, etc.

Coupling appears also in the import section ; static methods are visible there. And modern IDE usually highlight this. IntelliJ even have a warning if import section is too big, just as there's warning if there's too many fields. This point should not be the reason to avoid static methods.

> maintainability of procedural code, static methods that consume static methods, that consume static methods...

Having instance methods does not protect again procedural code.

---

I believe there's middle ground there : 
- Mockito project contains a lot of small utility stateless objects that are supporting mockito features, these are usually collections tools, reflection tools, those could are good candidate for static methods. Objects like `FieldSetter`, `FieldCopier`, `LenientCopyTool` could be nice candidate for static methods
- Mockito features could be backed by object instances. Objects like `MockitoCore`, `MockCreationValidator`, `ArgumentMatchingTool` are candidate to stay objects.

Exactly the middle ground described by Brice is my motivation for merging most of the PRs. This is also the reason I have not yet merged the MockitoCore PR for this exact reason.

If an object is not a attribute or parameter, but an internal creation and immediately dismissed, I value a pure function more.

Thought: when we switch to Java 8, we can use interfaces with default
methods. The switch from static utility to interface is very easy now (just
a couple of text replaces, no method reference modifications).

On Fri, 12 Aug 2016, 17:23 Brice Dutheil, notifications@github.com wrote:

> I'm mitigated about this as well. I understand well that mockito creates
> garbage, but they are short lived and _most probably_ won't go in the old
> generation especially in the test phase. Yet the faster the tests are the
> more developers will run them, it _may_ have impacts on big projects.
> Also design wise I don't like much static methods too.
> 
> However I don't totally agree with the above points :
> 
> I don't need to read every line of code in the class to find out external
> couplings realized via static methods. I can see the couplings via fields,
> I can easily query how the field variable is used, etc.
> 
> Coupling appears also in the import section ; static methods are visible
> there. And modern IDE usually highlight this. IntelliJ even have a warning
> if import section is too big, just as there's warning if there's too many
> fields. This point should not be the reason to avoid static methods.
> 
> maintainability of procedural code, static methods that consume static
> methods, that consume static methods...
> 
> ## Having instance methods does not protect again procedural code.
> 
> I believe there's middle ground there :
> 
>    -
> 
>    Mockito project contains a lot of small utility stateless objects that
>    are supporting mockito features, these are usually collections tools,
>    reflection tools, those could are good candidate for static methods.
>    Objects like FieldSetter, FieldCopier, LenientCopyTool could be nice
>    candidate for static methods
>    -
> 
>    Mockito features could be backed by object instances. Objects like
>    MockitoCore, MockCreationValidator, ArgumentMatchingTool are candidate
>    to stay objects.
> 
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly, view it on GitHub
> https://github.com/mockito/mockito/issues/426#issuecomment-239476519,
> or mute the thread
> https://github.com/notifications/unsubscribe-auth/AFrDb6QVlVesWgPAhurimgSUPQTRcTZSks5qfJALgaJpZM4IzjKm
> .

This feels like a misuse of the default methods.

I think you mean static-methods in interfaces here? Default-methods require an instance to be called on.
Anyway I don't think that it is a good idea.  It would a result in an interface that is not intended to be implemented or extended and only serves as container for utility methods. IMHO a class with private constructor is the best construct to do this.

> > Thought: when we switch to Java 8, we can use interfaces with default
> > methods.
> 
> Default-methods require an instance to be called on.

I was thinking exactly that, default methods in the interface plus instance (either as a separate file or as a singleton declared within the interface).

@ChristianSchwarz What do you think to continue the work here with the middle ground described [here](https://github.com/mockito/mockito/issues/426#issuecomment-239476519) ?

I am attempting to refactor the MatcherBinder class to a static utility class and am having trouble refactoring the following from MockHandlerImplTest.java: `
handler.matchersBinder = new MatchersBinder() {
            public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
                throw new InvalidUseOfMatchersException();
            }
}; `
How can I maintain the abstract class definition when I am not able to create an object of MatcherBinder?

Any help is appreciated! 
Let's close this ticket. Refactorings can be done as needed as we work with the code.

Pull request review comments:
Formatting again?

?

I added a new line in order to trigger a new build. The concurrent test are failing on every 2nd run.

tab vs. 4x space , fixed...


Patch that resolved the issue:
diff --git a/src/main/java/org/mockito/internal/invocation/InvocationMarker.java b/src/main/java/org/mockito/internal/invocation/InvocationMarker.java
index 882ccf2681..f05a22158b 100644
--- a/src/main/java/org/mockito/internal/invocation/InvocationMarker.java
+++ b/src/main/java/org/mockito/internal/invocation/InvocationMarker.java
@@ -11,22 +11,24 @@
 
 public class InvocationMarker {
 
-    public void markVerified(List<Invocation> invocations, CapturesArgumentsFromInvocation wanted) {
+    private InvocationMarker(){}
+	
+    public static void markVerified(List<Invocation> invocations, CapturesArgumentsFromInvocation wanted) {
         for (Invocation invocation : invocations) {
             markVerified(invocation, wanted);
         }
     }
 
-    public void markVerified(Invocation invocation, CapturesArgumentsFromInvocation wanted) {
+    public static void markVerified(Invocation invocation, CapturesArgumentsFromInvocation wanted) {
         invocation.markVerified();
         wanted.captureArgumentsFrom(invocation);
     }
 
-    public void markVerifiedInOrder(List<Invocation> chunk, CapturesArgumentsFromInvocation wanted, InOrderContext context) {
+    public static void markVerifiedInOrder(List<Invocation> chunk, CapturesArgumentsFromInvocation wanted, InOrderContext context) {
         markVerified(chunk, wanted);
 
         for (Invocation i : chunk) {
             context.markVerified(i);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/mockito/internal/verification/AtMost.java b/src/main/java/org/mockito/internal/verification/AtMost.java
index 8b5e0eeef9..a47c832949 100644
--- a/src/main/java/org/mockito/internal/verification/AtMost.java
+++ b/src/main/java/org/mockito/internal/verification/AtMost.java
@@ -6,14 +6,13 @@
 package org.mockito.internal.verification;
 
 import static org.mockito.exceptions.Reporter.wantedAtMostX;
+import static org.mockito.internal.invocation.InvocationMarker.markVerified;
 
 import java.util.Iterator;
 import java.util.List;
 
-import org.mockito.exceptions.Reporter;
 import org.mockito.exceptions.base.MockitoException;
 import org.mockito.internal.invocation.InvocationMatcher;
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.verification.api.VerificationData;
 import org.mockito.invocation.Invocation;
@@ -22,7 +21,6 @@
 public class AtMost implements VerificationMode {
 
     private final int maxNumberOfInvocations;
-    private final InvocationMarker invocationMarker = new InvocationMarker();
 
     public AtMost(int maxNumberOfInvocations) {
         if (maxNumberOfInvocations < 0) {
@@ -43,7 +41,7 @@ public void verify(VerificationData data) {
         }
 
         removeAlreadyVerified(found);
-        invocationMarker.markVerified(found, wanted);
+        markVerified(found, wanted);
     }
 
     @Override
diff --git a/src/main/java/org/mockito/internal/verification/Only.java b/src/main/java/org/mockito/internal/verification/Only.java
index 04b4bdbfcc..cf7febb8aa 100644
--- a/src/main/java/org/mockito/internal/verification/Only.java
+++ b/src/main/java/org/mockito/internal/verification/Only.java
@@ -6,10 +6,10 @@
 
 import static org.mockito.exceptions.Reporter.noMoreInteractionsWanted;
 import static org.mockito.exceptions.Reporter.wantedButNotInvoked;
+import static org.mockito.internal.invocation.InvocationMarker.markVerified;
 
 import java.util.List;
 
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.verification.api.VerificationData;
@@ -19,7 +19,6 @@
 public class Only implements VerificationMode {
 
     private final InvocationsFinder finder = new InvocationsFinder();
-    private final InvocationMarker marker = new InvocationMarker();
 
     @SuppressWarnings("unchecked")
     public void verify(VerificationData data) {
@@ -33,7 +32,7 @@ public void verify(VerificationData data) {
         if (invocations.size() != 1 || chunk.size() == 0) {
             throw wantedButNotInvoked(wantedMatcher);
         }
-        marker.markVerified(chunk.get(0), wantedMatcher);
+        markVerified(chunk.get(0), wantedMatcher);
     }
 
     public VerificationMode description(String description) {
diff --git a/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsChecker.java b/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsChecker.java
index 4eadb22e85..4a9e5dca7e 100644
--- a/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsChecker.java
+++ b/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsChecker.java
@@ -6,10 +6,10 @@
 package org.mockito.internal.verification.checkers;
 
 import static org.mockito.exceptions.Reporter.tooLittleActualInvocations;
+import static org.mockito.internal.invocation.InvocationMarker.markVerified;
 
 import java.util.List;
 
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.invocation.Invocation;
@@ -18,7 +18,6 @@
 public class AtLeastXNumberOfInvocationsChecker {
     
     InvocationsFinder finder = new InvocationsFinder();
-    InvocationMarker invocationMarker = new InvocationMarker();
 
     public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount) {
         List<Invocation> actualInvocations = finder.findInvocations(invocations, wanted);
@@ -29,6 +28,6 @@ public void check(List<Invocation> invocations, InvocationMatcher wanted, int wa
             throw tooLittleActualInvocations(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);        
         }
         
-        invocationMarker.markVerified(actualInvocations, wanted);
+        markVerified(actualInvocations, wanted);
     }
 }
\ No newline at end of file
diff --git a/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsInOrderChecker.java b/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsInOrderChecker.java
index c3d7f93cbb..96c61dc43d 100644
--- a/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsInOrderChecker.java
+++ b/src/main/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsInOrderChecker.java
@@ -6,10 +6,10 @@
 package org.mockito.internal.verification.checkers;
 
 import static org.mockito.exceptions.Reporter.tooLittleActualInvocationsInOrder;
+import static org.mockito.internal.invocation.InvocationMarker.markVerifiedInOrder;
 
 import java.util.List;
 
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.verification.api.InOrderContext;
@@ -19,7 +19,6 @@
 public class AtLeastXNumberOfInvocationsInOrderChecker {
     
     private final InvocationsFinder finder = new InvocationsFinder();
-    private final InvocationMarker invocationMarker = new InvocationMarker();
     private final InOrderContext orderingContext;
     
     public AtLeastXNumberOfInvocationsInOrderChecker(InOrderContext orderingContext) {
@@ -36,6 +35,6 @@ public void check(List<Invocation> invocations, InvocationMatcher wanted, int wa
             throw tooLittleActualInvocationsInOrder(new AtLeastDiscrepancy(wantedCount, actualCount), wanted, lastLocation);
         }
         
-        invocationMarker.markVerifiedInOrder(chunk, wanted, orderingContext);
+        markVerifiedInOrder(chunk, wanted, orderingContext);
     }
 }
\ No newline at end of file
diff --git a/src/main/java/org/mockito/internal/verification/checkers/NonGreedyNumberOfInvocationsInOrderChecker.java b/src/main/java/org/mockito/internal/verification/checkers/NonGreedyNumberOfInvocationsInOrderChecker.java
index a6c205b06a..6f40481ee8 100644
--- a/src/main/java/org/mockito/internal/verification/checkers/NonGreedyNumberOfInvocationsInOrderChecker.java
+++ b/src/main/java/org/mockito/internal/verification/checkers/NonGreedyNumberOfInvocationsInOrderChecker.java
@@ -5,8 +5,11 @@
 
 package org.mockito.internal.verification.checkers;
 
-import org.mockito.exceptions.Reporter;
-import org.mockito.internal.invocation.InvocationMarker;
+import static org.mockito.exceptions.Reporter.tooLittleActualInvocationsInOrder;
+import static org.mockito.internal.invocation.InvocationMarker.markVerified;
+
+import java.util.List;
+
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.reporting.Discrepancy;
@@ -14,22 +17,16 @@
 import org.mockito.invocation.Invocation;
 import org.mockito.invocation.Location;
 
-import static org.mockito.exceptions.Reporter.tooLittleActualInvocationsInOrder;
-
-import java.util.List;
-
 public class NonGreedyNumberOfInvocationsInOrderChecker {
 
     private final InvocationsFinder finder;
-    private final InvocationMarker marker;
 
     public NonGreedyNumberOfInvocationsInOrderChecker() {
-        this(new InvocationsFinder(), new InvocationMarker());
+        this(new InvocationsFinder());
     }
 
-    NonGreedyNumberOfInvocationsInOrderChecker(InvocationsFinder finder, InvocationMarker marker ) {
+    NonGreedyNumberOfInvocationsInOrderChecker(InvocationsFinder finder ) {
         this.finder = finder;
-        this.marker = marker;
     }
     
     public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) {
@@ -40,7 +37,7 @@ public void check(List<Invocation> invocations, InvocationMatcher wanted, int wa
             if( next == null ){
                 throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastLocation );
             }
-            marker.markVerified( next, wanted );
+            markVerified( next, wanted );
             context.markVerified( next );
             lastLocation = next.getLocation();
             actualCount++;
diff --git a/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsChecker.java b/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsChecker.java
index 7b277e880b..15c7594a47 100644
--- a/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsChecker.java
+++ b/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsChecker.java
@@ -8,10 +8,10 @@
 import static org.mockito.exceptions.Reporter.neverWantedButInvoked;
 import static org.mockito.exceptions.Reporter.tooLittleActualInvocations;
 import static org.mockito.exceptions.Reporter.tooManyActualInvocations;
+import static org.mockito.internal.invocation.InvocationMarker.markVerified;
 
 import java.util.List;
 
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.reporting.Discrepancy;
@@ -21,8 +21,6 @@
 public class NumberOfInvocationsChecker {
     
     private final InvocationsFinder finder=new InvocationsFinder();
-    private final InvocationMarker invocationMarker = new InvocationMarker();
-
     
     public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount) {
         List<Invocation> actualInvocations = finder.findInvocations(invocations, wanted);
@@ -41,6 +39,6 @@ public void check(List<Invocation> invocations, InvocationMatcher wanted, int wa
             throw tooManyActualInvocations(wantedCount, actualCount, wanted, firstUndesired);
         }
         
-        invocationMarker.markVerified(actualInvocations, wanted);
+        markVerified(actualInvocations, wanted);
     }
 }
\ No newline at end of file
diff --git a/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsInOrderChecker.java b/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsInOrderChecker.java
index 5063955968..c9a769546d 100644
--- a/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsInOrderChecker.java
+++ b/src/main/java/org/mockito/internal/verification/checkers/NumberOfInvocationsInOrderChecker.java
@@ -7,10 +7,10 @@
 
 import static org.mockito.exceptions.Reporter.tooLittleActualInvocationsInOrder;
 import static org.mockito.exceptions.Reporter.tooManyActualInvocationsInOrder;
+import static org.mockito.internal.invocation.InvocationMarker.markVerifiedInOrder;
 
 import java.util.List;
 
-import org.mockito.internal.invocation.InvocationMarker;
 import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.reporting.Discrepancy;
@@ -19,10 +19,8 @@
 import org.mockito.invocation.Location;
 
 public class NumberOfInvocationsInOrderChecker {
-    
   
     private final InvocationsFinder finder;
-    private final InvocationMarker invocationMarker = new InvocationMarker();
     
     public NumberOfInvocationsInOrderChecker() {
         this(new InvocationsFinder());
@@ -30,7 +28,6 @@ public NumberOfInvocationsInOrderChecker() {
     
     NumberOfInvocationsInOrderChecker(InvocationsFinder finder) {
         this.finder = finder;
-       
     }
     
     public void check(List<Invocation> invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) {
@@ -47,6 +44,6 @@ public void check(List<Invocation> invocations, InvocationMatcher wanted, int wa
             throw tooManyActualInvocationsInOrder(wantedCount, actualCount, wanted, firstUndesired);
         }
         
-        invocationMarker.markVerifiedInOrder(chunk, wanted, context);
+        markVerifiedInOrder(chunk, wanted, context);
     }
 }
\ No newline at end of file


Test patch:
diff --git a/src/test/java/org/mockito/internal/invocation/InvocationMarkerTest.java b/src/test/java/org/mockito/internal/invocation/InvocationMarkerTest.java
index d85320c485..777e76b517 100644
--- a/src/test/java/org/mockito/internal/invocation/InvocationMarkerTest.java
+++ b/src/test/java/org/mockito/internal/invocation/InvocationMarkerTest.java
@@ -17,13 +17,12 @@ public class InvocationMarkerTest extends TestBase {
     @Test
     public void shouldMarkInvocationAsVerified() {
         //given
-        InvocationMarker marker = new InvocationMarker();
         Invocation i = new InvocationBuilder().toInvocation();
         InvocationMatcher im = new InvocationBuilder().toInvocationMatcher();
         assertFalse(i.isVerified());
         
         //when
-        marker.markVerified(Arrays.asList(i), im);
+        InvocationMarker.markVerified(Arrays.asList(i), im);
         
         //then
         assertTrue(i.isVerified());
@@ -32,7 +31,6 @@ public void shouldMarkInvocationAsVerified() {
     @Test
     public void shouldCaptureArguments() {
         //given
-        InvocationMarker marker = new InvocationMarker();
         Invocation i = new InvocationBuilder().toInvocation();
         final ObjectBox box = new ObjectBox();
         CapturesArgumentsFromInvocation c = new CapturesArgumentsFromInvocation() {
@@ -41,7 +39,7 @@ public void captureArgumentsFrom(Invocation i) {
             }};
         
         //when
-        marker.markVerified(Arrays.asList(i), c);
+        InvocationMarker.markVerified(Arrays.asList(i), c);
         
         //then
         assertEquals(i, box.getObject());
@@ -51,14 +49,14 @@ public void captureArgumentsFrom(Invocation i) {
     public void shouldMarkInvocationsAsVerifiedInOrder() {
         //given
         InOrderContextImpl context = new InOrderContextImpl();
-        InvocationMarker marker = new InvocationMarker();
+        
         Invocation i = new InvocationBuilder().toInvocation();
         InvocationMatcher im = new InvocationBuilder().toInvocationMatcher();
         assertFalse(context.isVerified(i));
         assertFalse(i.isVerified());
         
         //when
-        marker.markVerifiedInOrder(Arrays.asList(i), im, context);
+        InvocationMarker.markVerifiedInOrder(Arrays.asList(i), im, context);
         
         //then
         assertTrue(context.isVerified(i));
diff --git a/src/test/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsCheckerTest.java b/src/test/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsCheckerTest.java
index 9dfb7ca1c7..9e318a4611 100644
--- a/src/test/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsCheckerTest.java
+++ b/src/test/java/org/mockito/internal/verification/checkers/AtLeastXNumberOfInvocationsCheckerTest.java
@@ -5,22 +5,20 @@
 package org.mockito.internal.verification.checkers;
 
 import static java.util.Arrays.asList;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.internal.invocation.*;
+import org.mockito.internal.invocation.InvocationBuilder;
+import org.mockito.internal.invocation.InvocationMatcher;
 import org.mockito.invocation.Invocation;
-import org.mockitoutil.TestBase;
 
-public class AtLeastXNumberOfInvocationsCheckerTest extends TestBase {
+public class AtLeastXNumberOfInvocationsCheckerTest   {
 
     @Test
     public void shouldMarkActualInvocationsAsVerified() {
         //given
         AtLeastXNumberOfInvocationsChecker c = new AtLeastXNumberOfInvocationsChecker();
-        c.invocationMarker = Mockito.mock(InvocationMarker.class);
+       
         Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
         Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
 
@@ -28,6 +26,6 @@ public void shouldMarkActualInvocationsAsVerified() {
         c.check(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 1);
 
         //then
-        Mockito.verify(c.invocationMarker).markVerified(eq(asList(invocation)), any(CapturesArgumentsFromInvocation.class));
+        assertThat(invocation.isVerified()).isTrue();
     }
 }