mockit.internal.state.SavePoint 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.state;
import static mockit.internal.expectations.RecordAndReplayExecution.RECORD_OR_REPLAY_LOCK;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mockit.internal.ClassIdentification;
import mockit.internal.faking.FakeClasses;
public final class SavePoint {
@NonNull
private final Set previousTransformedClasses;
@NonNull
private final Map, byte[]> previousRedefinedClasses;
private final int previousCaptureTransformerCount;
@NonNull
private final List> previousMockedClasses;
@NonNull
private final FakeClasses.SavePoint previousFakeClasses;
public SavePoint() {
MockFixture mockFixture = TestRun.mockFixture();
previousTransformedClasses = mockFixture.getTransformedClasses();
previousRedefinedClasses = mockFixture.getRedefinedClasses();
previousCaptureTransformerCount = mockFixture.getCaptureTransformerCount();
previousMockedClasses = mockFixture.getMockedClasses();
previousFakeClasses = TestRun.getFakeClasses().new SavePoint();
}
public synchronized void rollback() {
RECORD_OR_REPLAY_LOCK.lock();
try {
MockFixture mockFixture = TestRun.mockFixture();
mockFixture.removeCaptureTransformers(previousCaptureTransformerCount);
mockFixture.restoreTransformedClasses(previousTransformedClasses);
mockFixture.restoreRedefinedClasses(previousRedefinedClasses);
mockFixture.removeMockedClasses(previousMockedClasses);
previousFakeClasses.rollback();
} finally {
RECORD_OR_REPLAY_LOCK.unlock();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy