![JAR search and dependency download from the Maven repository](/logo.png)
mockit.internal.expectations.mocking.MockedBridge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for developer (unit/integration) testing.
It contains mocking APIs and other tools, supporting both JUnit and TestNG.
The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested
in isolation from selected dependencies.
/*
* Copyright (c) 2006-2013 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.expectations.mocking;
import java.lang.reflect.*;
import org.jetbrains.annotations.*;
import mockit.internal.*;
import mockit.internal.expectations.*;
import mockit.internal.state.*;
import mockit.internal.util.*;
public final class MockedBridge extends MockingBridge
{
public static final MockingBridge MB = new MockedBridge();
private MockedBridge() { super(MockedBridge.class); }
@Nullable
public Object invoke(Object mocked, Method method, @NotNull Object[] args) throws Throwable
{
String mockedClassDesc = (String) args[1];
if (notToBeMocked(mocked, mockedClassDesc)) {
return Void.class;
}
String mockName = (String) args[2];
String mockDesc = (String) args[3];
String mockNameAndDesc = mockName + mockDesc;
Object[] mockArgs = extractMockArguments(args);
int executionMode = (Integer) args[6];
boolean lockHeldByCurrentThread = RecordAndReplayExecution.RECORD_OR_REPLAY_LOCK.isHeldByCurrentThread();
if (lockHeldByCurrentThread && mocked != null && executionMode == 0) {
Object rv = ObjectMethods.evaluateOverride(mocked, mockNameAndDesc, args);
if (rv != null) {
return rv;
}
}
if (TestRun.isInsideNoMockingZone()) {
return Void.class;
}
String genericSignature = (String) args[4];
if (lockHeldByCurrentThread && executionMode == 0) {
return RecordAndReplayExecution.defaultReturnValue(
mocked, mockedClassDesc, mockNameAndDesc, genericSignature, 1, mockArgs);
}
int mockAccess = (Integer) args[0];
String exceptions = (String) args[5];
TestRun.enterNoMockingZone();
try {
return RecordAndReplayExecution.recordOrReplay(
mocked, mockAccess, mockedClassDesc, mockNameAndDesc, genericSignature, exceptions,
executionMode, mockArgs);
}
finally {
TestRun.exitNoMockingZone();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy