public void evaluate() throws Throwable { if (session == null) { session = Mockito.mockitoSession() .name(target.getClass().getSimpleName() + "." + method.getName()) .strictness(strictness) .logger(new MockitoSessionLoggerAdapter(logger)) .initMocks(target) .startMocking(); } else { MockitoAnnotations.initMocks(target); } Throwable testFailure = evaluateSafely(base); session.finishMocking(testFailure); if (testFailure != null) { throw testFailure; } }
/** * Same as {@link Mockito#mockitoSession()} but adds the ability to mock static methods * calls via {@link StaticMockitoSessionBuilder#mockStatic(Class)}, * {@link StaticMockitoSessionBuilder#mockStatic(Class, Answer)}, and {@link * StaticMockitoSessionBuilder#mockStatic(Class, MockSettings)}; * <p>All mocking spying will be removed once the session is finished. */ public static StaticMockitoSessionBuilder mockitoSession() { return new StaticMockitoSessionBuilder(Mockito.mockitoSession()); }
@BeforeMethod public void initMocks() { mockitoSession = mockitoSession().initMocks(this).strictness(strictness).startMocking(); }
@BeforeMethod public void initMocks() { mockitoSession = mockitoSession().initMocks(this).strictness(strictness).startMocking(); }
/** * Callback that is invoked <em>before</em> each test is invoked. * * @param context the current extension context; never {@code null} */ @Override public void beforeEach(final ExtensionContext context) { Set<Object> testInstances = new LinkedHashSet<>(); testInstances.add(context.getRequiredTestInstance()); this.collectParentTestInstances(context, testInstances); Strictness actualStrictness = this.retrieveAnnotationFromTestClasses(context) .map(MockitoSettings::strictness) .orElse(strictness); MockitoSession session = Mockito.mockitoSession() .initMocks(testInstances.toArray()) .strictness(actualStrictness) .startMocking(); context.getStore(MOCKITO).put(SESSION, session); }
@BeforeMethod(alwaysRun = true) public void setup() { mockitoSession = Mockito.mockitoSession().strictness(Strictness.STRICT_STUBS).startMocking(); EventLogManager eventLogManager = new EventLogManagerImpl(); PersistentUUIDManager persistentUUIDManager = new PersistentUUIDManagerImpl(); EmbeddedCacheManager cacheManager = mock(EmbeddedCacheManager.class); topologyManager = mock(ClusterTopologyManager.class); transport = mock(Transport.class); PreferAvailabilityStrategy availabilityStrategy = new PreferAvailabilityStrategy(eventLogManager, persistentUUIDManager, ClusterTopologyManagerImpl::distLostDataCheck); status = new ClusterCacheStatus(cacheManager, CACHE_NAME, availabilityStrategy, RebalanceType.FOUR_PHASE, topologyManager, transport, persistentUUIDManager, eventLogManager, Optional.empty(), false); }
@BeforeMethod(alwaysRun = true) public void setup() { mockitoSession = Mockito.mockitoSession() .strictness(Strictness.STRICT_STUBS) .startMocking(); persistentUUIDManager = new PersistentUUIDManagerImpl(); eventLogManager = new EventLogManagerImpl(); context = mock(AvailabilityStrategyContext.class); persistentUUIDManager.addPersistentAddressMapping(A, persistentUUID(A)); persistentUUIDManager.addPersistentAddressMapping(B, persistentUUID(B)); persistentUUIDManager.addPersistentAddressMapping(C, persistentUUID(C)); strategy = new PreferAvailabilityStrategy(eventLogManager, persistentUUIDManager, ClusterTopologyManagerImpl::distLostDataCheck); }