本文整理汇总了Java中org.mockito.internal.util.MockUtil类的典型用法代码示例。如果您正苦于以下问题:Java MockUtil类的具体用法?Java MockUtil怎么用?Java MockUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockUtil类属于org.mockito.internal.util包,在下文中一共展示了MockUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
@Before
public void setup() {
WXEnvironment.sApplication = RuntimeEnvironment.application;
WXSDKManager wxsdkManager = WXSDKManager.getInstance();
if (!new MockUtil().isSpy(wxsdkManager)) {
WXSDKManager spy = Mockito.spy(wxsdkManager);
WXSDKManagerTest.setInstance(spy);
Mockito.when(spy.getIWXHttpAdapter()).thenReturn(new IWXHttpAdapter() {
@Override
public void sendRequest(WXRequest request, OnHttpListener listener) {
//do nothing.
}
});
}
adapter = new DefaultUriAdapter();
instance = WXSDKInstanceTest.createInstance();
}
示例2: answer
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public Object answer(InvocationOnMock invocation) {
if (methodsGuru.isToString(invocation.getMethod())) {
Object mock = invocation.getMock();
MockName name = new MockUtil().getMockName(mock);
if (name.isSurrogate()) {
return "Mock for " + ClassNameFinder.classNameForMock(mock) + ", hashCode: " + mock.hashCode();
} else {
return name.toString();
}
} else if (methodsGuru.isCompareToMethod(invocation.getMethod())) {
//see issue 184.
//mocks by default should not return 0 for compareTo because they are not the same. Hence we return 1 (anything but 0 is good).
//Only for compareTo() method by the Comparable interface
return 1;
}
Class<?> returnType = invocation.getMethod().getReturnType();
return returnValueFor(returnType);
}
示例3: wrongTypeOfArgumentToReturn
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public void wrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expectedType, Class actualType, int argumentIndex) {
throw new WrongTypeOfReturnValue(join(
"The argument of type '" + actualType.getSimpleName() + "' cannot be returned because the following ",
"method should return the type '" + expectedType + "'",
" -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
"",
"The reason for this error can be :",
"1. The wanted argument position is incorrect.",
"2. The answer is used on the wrong interaction.",
"",
"Position of the wanted argument is " + argumentIndex + " and " + possibleArgumentTypesOf(invocation),
"***",
"However if you're still unsure why you're getting above error read on.",
"Due to the nature of the syntax above problem might occur because:",
"1. This exception *might* occur in wrongly written multi-threaded tests.",
" Please refer to Mockito FAQ on limitations of concurrency testing.",
"2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - ",
" - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.",
""
));
}
示例4: answer
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
@Nullable
public T answer(InvocationOnMock invocation) throws Throwable {
if (throwables.iterator().hasNext()) {
Throwable throwable = throwables.iterator().next();
if (new MockUtil().isMock(throwable)) {
throw throwable;
}
Throwable t = throwable.fillInStackTrace();
filter.filter(t);
throw t;
}
if (values.iterator().hasNext()) {
return values.iterator().next();
} else {
return null;
}
}
示例5: mockWithName
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
private static Condition<DataSource> mockWithName(Object object, String name) {
MockUtil mockUtil = new MockUtil();
Condition<Object> isMock = new Condition<>(
dataSource -> mockUtil.isMock(object),
"target object is not a mock");
Condition<Object> hasName = new Condition<>(
dataSource -> name.equals(mockUtil.getMockName(object).toString()),
"mock has an unexpected name");
return allOf(isMock, hasName);
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:13,代码来源:MultipleDataSourcesIntegrationTest.java
示例6: assertListenerReceivedExtractionMessages
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public static void assertListenerReceivedExtractionMessages(
MessageListener messageListener, Path testRoot) {
if (!MockUtil.isMock(messageListener)) {
throw new IllegalArgumentException("Listener must be a mock.");
}
// tars allow for duplicate entries
Mockito.verify(messageListener, Mockito.atLeastOnce()).message(testRoot.resolve(ROOT) + "\n");
Mockito.verify(messageListener, Mockito.atLeastOnce()).message(testRoot.resolve(FILE_1) + "\n");
Mockito.verify(messageListener, Mockito.atLeastOnce()).message(testRoot.resolve(SUB) + "\n");
Mockito.verify(messageListener, Mockito.atLeastOnce()).message(testRoot.resolve(FILE_2) + "\n");
}
示例7: Verification
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
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);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:MockitoAopProxyTargetInterceptor.java
示例8: createMock
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
@Test
public void createMock() throws Exception {
MockDefinition definition = new MockDefinition("name", ExampleService.class,
new Class<?>[] { ExampleExtraInterface.class },
Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE, true);
ExampleService mock = definition.createMock();
MockCreationSettings<?> settings = new MockUtil().getMockSettings(mock);
assertThat(mock).isInstanceOf(ExampleService.class);
assertThat(mock).isInstanceOf(ExampleExtraInterface.class);
assertThat(settings.getMockName().toString()).isEqualTo("name");
assertThat(settings.getDefaultAnswer())
.isEqualTo(Answers.RETURNS_SMART_NULLS.get());
assertThat(settings.isSerializable()).isTrue();
assertThat(MockReset.get(mock)).isEqualTo(MockReset.BEFORE);
}
示例9: createSpy
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
@Test
public void createSpy() throws Exception {
SpyDefinition definition = new SpyDefinition("name", RealExampleService.class,
MockReset.BEFORE, true);
RealExampleService spy = definition.createSpy(new RealExampleService("hello"));
MockCreationSettings<?> settings = new MockUtil().getMockSettings(spy);
assertThat(spy).isInstanceOf(ExampleService.class);
assertThat(settings.getMockName().toString()).isEqualTo("name");
assertThat(settings.getDefaultAnswer())
.isEqualTo(Answers.CALLS_REAL_METHODS.get());
assertThat(MockReset.get(spy)).isEqualTo(MockReset.BEFORE);
}
示例10: initBaseActionLoader
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
protected void initBaseActionLoader() {
loaderMock = BeanLoader.loadBean(BaseActionLoaderImpl.class);
if (new MockUtil().isMock(loaderMock)) {
reset(loaderMock);
when(loaderMock.getSahiReport()).thenReturn(mock(Report.class));
}
}
示例11: find
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
/**
* gets all invocations from mocks. Invocations are ordered earlier first.
*
* @param mocks mocks
* @return invocations
*/
public List<Invocation> find(List<?> mocks) {
Set<Invocation> invocationsInOrder = new TreeSet<Invocation>(new SequenceNumberComparator());
for (Object mock : mocks) {
MockHandlerInterface<Object> handler = new MockUtil().getMockHandler(mock);
List<Invocation> fromSingleMock = handler.getInvocationContainer().getInvocations();
invocationsInOrder.addAll(fromSingleMock);
}
return new LinkedList<Invocation>(invocationsInOrder);
}
示例12: find
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
/**
* Finds all unused stubs for given mocks
*
* @param mocks
*/
public List<Invocation> find(List<?> mocks) {
List<Invocation> unused = new LinkedList<Invocation>();
for (Object mock : mocks) {
MockHandlerInterface<Object> handler = new MockUtil().getMockHandler(mock);
List<StubbedInvocationMatcher> fromSingleMock = handler.getInvocationContainer().getStubbedInvocations();
for(StubbedInvocationMatcher s : fromSingleMock) {
if (!s.wasUsed()) {
unused.add(s.getInvocation());
}
}
}
return unused;
}
示例13: when
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public <T> T when(T mock) {
MockUtil mockUtil = new MockUtil();
if (mock == null) {
reporter.nullPassedToWhenMethod();
} else {
if (!mockUtil.isMock(mock)) {
reporter.notAMockPassedToWhenMethod();
}
}
mockUtil.getMockHandler(mock).setAnswersForStubbing(answers);
return mock;
}
示例14: answer
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public Object answer(InvocationOnMock invocation) throws Throwable {
if (new MockUtil().isMock(throwable)) {
throw throwable;
}
Throwable t = throwable.fillInStackTrace();
filter.filter(t);
throw t;
}
示例15: cannotInjectDependency
import org.mockito.internal.util.MockUtil; //导入依赖的package包/类
public void cannotInjectDependency(Field field, Object matchingMock, Exception details) {
throw new MockitoException(join(
"Mockito couldn't inject mock dependency '" + new MockUtil().getMockName(matchingMock) + "' on field ",
"'" + field + "'",
"whose type '" + field.getDeclaringClass().getCanonicalName() + "' was annotated by @InjectMocks in your test.",
"Also I failed because: " + details.getCause().getMessage(),
""
), details);
}