mockit.internal.faking.FakeClasses 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 automated developer testing.
It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external
APIs; JUnit (4 & 5) and TestNG test runners are supported.
It also contains an advanced code coverage tool.
The newest version!
/*
* Copyright (c) 2006 JMockit developers
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.faking;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Map.Entry;
import mockit.MockUp;
import mockit.internal.util.ClassLoad;
public final class FakeClasses {
private static final Field INVOKED_INSTANCE_FIELD;
private static final Method ON_TEAR_DOWN_METHOD;
static {
try {
INVOKED_INSTANCE_FIELD = MockUp.class.getDeclaredField("invokedInstance");
INVOKED_INSTANCE_FIELD.setAccessible(true);
ON_TEAR_DOWN_METHOD = MockUp.class.getDeclaredMethod("onTearDown");
ON_TEAR_DOWN_METHOD.setAccessible(true);
} catch (NoSuchFieldException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
private static void notifyOfTearDown(@NonNull MockUp> mockUp) {
try {
ON_TEAR_DOWN_METHOD.invoke(mockUp);
} catch (IllegalAccessException ignore) {
} catch (InvocationTargetException e) {
e.getCause().printStackTrace();
}
}
public static final class MockUpInstances {
@NonNull
public final MockUp> initialMockUp;
boolean hasMockupsForSingleInstances;
MockUpInstances(@NonNull MockUp> initialMockUp) {
this.initialMockUp = initialMockUp;
hasMockupsForSingleInstances = false;
}
public boolean hasMockUpsForSingleInstances() {
return hasMockupsForSingleInstances;
}
void notifyMockUpOfTearDown() {
notifyOfTearDown(initialMockUp);
}
}
@NonNull
private final Map> startupMocks;
@NonNull
private final Map, MockUpInstances> mockupClassesToMockupInstances;
@NonNull
private final Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy