Verification(Object target) { MockUtil mockUtil = new MockUtil(); InternalMockHandler<?> handler = mockUtil.getMockHandler(target); InvocationContainer container = handler.getInvocationContainer(); Field field = ReflectionUtils.findField(container.getClass(), "mockingProgress"); ReflectionUtils.makeAccessible(field); this.progress = (MockingProgress) ReflectionUtils.getField(field, container); }
private VerificationMode getVerificationMode() { try { MockingProgress progress = (MockingProgress) Whitebox.invokeMethod(ThreadSafeMockingProgress.class, "threadSafely"); return getVerificationModeFromMockProgress(progress); } catch (Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") private VerificationMode getVerificationModeFromMockProgress(MockingProgress mockingProgress) { if (mockingProgress == null) { return null; } if (mockingProgress instanceof ThreadSafeMockingProgress) { ThreadLocal<MockingProgress> threadLocal = Whitebox.getInternalState(mockingProgress, ThreadLocal.class); return getVerificationModeFromMockProgress(threadLocal.get()); } else { Localized<VerificationMode> verificationMode = Whitebox.getInternalState(mockingProgress, Localized.class); return verificationMode == null ? null : verificationMode.getObject(); } }
public MocksCollector() { createdMocks = new LinkedList<Object>(); final MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
private MockingProgress getMockingProgress() { return Whitebox.getInternalState(Mockito.class, MockingProgress.class); }
public MocksCollector() { createdMocks = new LinkedList<>(); final MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
public InvocationContainerImpl(MockingProgress mockingProgress) { this.mockingProgress = mockingProgress; }
public WarningsCollector() { createdMocks = new LinkedList(); MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
public InvocationContainerImpl(MockingProgress mockingProgress, MockCreationSettings mockSettings) { this.mockingProgress = mockingProgress; this.registeredInvocations = createRegisteredInvocations(mockSettings); }
/** * Verify a private method invocation with a given verification mode. * * @see {@link Mockito#verify(Object)} * @throws Exception * If something unexpected goes wrong. */ public static PrivateMethodVerification verifyPrivate(Object object, VerificationMode verificationMode) throws Exception { Whitebox.getInternalState(Mockito.class, MockingProgress.class).verificationStarted( POWERMOCKITO_CORE.wrapInMockitoSpecificVerificationMode(object, verificationMode)); return new DefaultPrivateMethodVerification(object); }
/** * Verifies certain behavior happened at least once / exact number of times * / never. E.g: * * <pre> * verifyStatic(times(5)); * ClassWithStaticMethod.someStaticMethod("was called five times"); * * verifyStatic(atLeast(2)); * ClassWithStaticMethod.someStaticMethod("was called at least two times"); * * //you can use flexible argument matchers, e.g: * verifyStatic(atLeastOnce()); * ClassWithStaticMethod.someMethod(<b>anyString()</b>); * </pre> * * <b>times(1) is the default</b> and can be omitted * <p> * * @param verificationMode * times(x), atLeastOnce() or never() */ public static synchronized void verifyStatic(VerificationMode verificationMode) { Whitebox.getInternalState(Mockito.class, MockingProgress.class).verificationStarted( POWERMOCKITO_CORE.wrapInStaticVerificationMode(verificationMode)); }