Created
May 31, 2012 08:38
-
-
Save tobyweston/2841959 to your computer and use it in GitHub Desktop.
Avoid finalizer problems with JMocks SingleThreadedPolicy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SingleThreadedPolicyAvoidingFinaliseProblems extends SingleThreadedPolicy { | |
@Override | |
public Invokable synchroniseAccessTo(final Invokable mockObject) { | |
final Invokable synchronizedMockObject = super.synchroniseAccessTo(mockObject); | |
return new Invokable() { | |
@Override | |
public Object invoke(Invocation invocation) throws Throwable { | |
if (Thread.currentThread().getName().equalsIgnoreCase("Finalizer")) | |
return mockObject.invoke(invocation); | |
return synchronizedMockObject.invoke(invocation); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bit of an improvment