• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Invocation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mockito.invocation.Invocation的典型用法代码示例。如果您正苦于以下问题:Java Invocation类的具体用法?Java Invocation怎么用?Java Invocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Invocation类属于org.mockito.invocation包,在下文中一共展示了Invocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: intercept

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy)
        throws Throwable {
    if (objectMethodsGuru.isEqualsMethod(method)) {
        return proxy == args[0];
    } else if (objectMethodsGuru.isHashCodeMethod(method)) {
        return hashCodeForMock(proxy);
    } else if (acrossJVMSerializationFeature.isWriteReplace(method)) {
        return acrossJVMSerializationFeature.writeReplace(proxy);
    }
    
    MockitoMethodProxy mockitoMethodProxy = createMockitoMethodProxy(methodProxy);
    new CGLIBHacker().setMockitoNamingPolicy(methodProxy);
    
    MockitoMethod mockitoMethod = createMockitoMethod(method);
    
    CleanTraceRealMethod realMethod = new CleanTraceRealMethod(mockitoMethodProxy);
    Invocation invocation = new InvocationImpl(proxy, mockitoMethod, args, SequenceNumber.next(), realMethod);
    return handler.handle(invocation);
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:20,代码来源:MethodInterceptorFilter.java


示例2: verify

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public void verify(VerificationData verificationData) {
  List<Invocation> invocations = verificationData.getAllInvocations();
  InvocationMatcher invocationMatcher = verificationData.getWanted();

  if (invocations == null || invocations.isEmpty()) {
    throw new MockitoException(
        "\nNo interactions with "
            + invocationMatcher.getInvocation().getMock()
            + " mock so far");
  }
  Invocation invocation = invocations.get(invocations.size() - 1);

  if (!invocationMatcher.matches(invocation)) {
    throw new MockitoException("\nWanted but not invoked:\n" + invocationMatcher);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ConcurrentCompositeLineConsumerTest.java


示例3: hasSimilarMethod

import org.mockito.invocation.Invocation; //导入依赖的package包/类
/**
 * similar means the same method name, same mock, unverified 
 * and: if arguments are the same cannot be overloaded
 */
public boolean hasSimilarMethod(Invocation candidate) {
    String wantedMethodName = getMethod().getName();
    String currentMethodName = candidate.getMethod().getName();
    
    final boolean methodNameEquals = wantedMethodName.equals(currentMethodName);
    final boolean isUnverified = !candidate.isVerified();
    final boolean mockIsTheSame = getInvocation().getMock() == candidate.getMock();
    final boolean methodEquals = hasSameMethod(candidate);

    if (!methodNameEquals || !isUnverified || !mockIsTheSame) {
        return false;
    }

    final boolean overloadedButSameArgs = !methodEquals && safelyArgumentsMatch(candidate.getArguments());

    return !overloadedButSameArgs;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:InvocationMatcher.java


示例4: hasSameMethod

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public boolean hasSameMethod(Invocation candidate) {
    //not using method.equals() for 1 good reason:
    //sometimes java generates forwarding methods when generics are in play see JavaGenericsForwardingMethodsTest
    Method m1 = invocation.getMethod();
    Method m2 = candidate.getMethod();
    
    if (m1.getName() != null && m1.getName().equals(m2.getName())) {
    	/* Avoid unnecessary cloning */
    	Class[] params1 = m1.getParameterTypes();
    	Class[] params2 = m2.getParameterTypes();
    	if (params1.length == params2.length) {
    	    for (int i = 0; i < params1.length; i++) {
    		if (params1[i] != params2[i])
    		    return false;
    	    }
    	    return true;
    	}
    }
    return false;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:InvocationMatcher.java


示例5: captureArgumentsFrom

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public void captureArgumentsFrom(Invocation invocation) {
    for (int position = 0; position < matchers.size(); position++) {
        Matcher m = matchers.get(position);
        if (m instanceof CapturesArguments && invocation.getRawArguments().length > position) {
            //TODO SF - this whole lot can be moved captureFrom implementation
            if(isVariableArgument(invocation, position) && isVarargMatcher(m)) {
                Object array = invocation.getRawArguments()[position];
                for (int i = 0; i < Array.getLength(array); i++) {
                    ((CapturesArguments) m).captureFrom(Array.get(array, i));
                }
                //since we've captured all varargs already, it does not make sense to process other matchers.
                return;
            } else {
                ((CapturesArguments) m).captureFrom(invocation.getRawArguments()[position]);
            }
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:InvocationMatcher.java


示例6: should_get_results_for_methods_stub_only

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
    invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
    invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"));

    Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
    invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
    invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()));

    assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));

    try {
        invocationContainerImplStubOnly.answerTo(differentMethod);
        fail();
    } catch (MyException e) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:InvocationContainerImplStubbingTest.java


示例7: findSimilarInvocation

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public Invocation findSimilarInvocation(List<Invocation> invocations, InvocationMatcher wanted) {
    Invocation firstSimilar = null;
    for (Invocation invocation : invocations) {
        if (!wanted.hasSimilarMethod(invocation)) {
            continue;
        }
        if (firstSimilar == null) {
            firstSimilar = invocation;
        }
        if (wanted.hasSameMethod(invocation)) {
            return invocation;
        }
    }
    
    return firstSimilar;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:InvocationsFinder.java


示例8: should_get_results_for_methods

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void should_get_results_for_methods() throws Throwable {
    invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
    invocationContainerImpl.addAnswer(new Returns("simpleMethod"));

    Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
    invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
    invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));

    assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));

    try {
        invocationContainerImpl.answerTo(differentMethod);
        fail();
    } catch (MyException e) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:InvocationContainerImplStubbingTest.java


示例9: shouldMarkInvocationsAsVerifiedInOrder

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void shouldMarkInvocationsAsVerifiedInOrder() {
    //given
    InOrderContextImpl context = new InOrderContextImpl();
    InvocationMarker marker = new InvocationMarker();
    Invocation i = new InvocationBuilder().toInvocation();
    InvocationMatcher im = new InvocationBuilder().toInvocationMatcher();
    assertFalse(context.isVerified(i));
    assertFalse(i.isVerified());
    
    //when
    marker.markVerifiedInOrder(Arrays.asList(i), im, context);
    
    //then
    assertTrue(context.isVerified(i));
    assertTrue(i.isVerified());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:InvocationMarkerTest.java


示例10: verifySameInvocation

import org.mockito.invocation.Invocation; //导入依赖的package包/类
private static void verifySameInvocation(Invocation expectedInvocation, Invocation actualInvocation, InvocationArgumentsAdapter... argumentAdapters) {
	System.out.println(expectedInvocation);
	System.out.println(actualInvocation);
	assertThat(expectedInvocation.getMethod(), is(equalTo(actualInvocation.getMethod())));
	Object[] expectedArguments = getInvocationArguments(expectedInvocation, argumentAdapters);
	Object[] actualArguments = getInvocationArguments(actualInvocation, argumentAdapters);
	assertThat(expectedArguments, is(equalTo(actualArguments)));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:MockitoUtils.java


示例11: getInvocationArguments

import org.mockito.invocation.Invocation; //导入依赖的package包/类
private static Object[] getInvocationArguments(Invocation invocation, InvocationArgumentsAdapter... argumentAdapters) {
	Object[] arguments = invocation.getArguments();
	for (InvocationArgumentsAdapter adapter : argumentAdapters) {
		arguments = adapter.adaptArguments(arguments);
	}
	return arguments;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:MockitoUtils.java


示例12: bindMatchers

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, final Invocation invocation) {
    List<LocalizedMatcher> lastMatchers = argumentMatcherStorage.pullLocalizedMatchers();
    validateMatchers(invocation, lastMatchers);

    final InvocationMatcher invocationWithMatchers = new InvocationMatcher(invocation, (List<Matcher>)(List) lastMatchers) {
        @Override
        public String toString() {
            return invocation.toString();
        }
    };
    return invocationWithMatchers;
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:13,代码来源:PowerMockMatchersBinder.java


示例13: validateMatchers

import org.mockito.invocation.Invocation; //导入依赖的package包/类
private void validateMatchers(Invocation invocation, List<LocalizedMatcher> lastMatchers) {
    if (!lastMatchers.isEmpty()) {
        int recordedMatchersSize = lastMatchers.size();
        int expectedMatchersSize = invocation.getArguments().length;
        if (expectedMatchersSize != recordedMatchersSize) {
            new Reporter().invalidUseOfMatchers(expectedMatchersSize, lastMatchers);
        }
    }
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:10,代码来源:PowerMockMatchersBinder.java


示例14: toInvocation

import org.mockito.invocation.Invocation; //导入依赖的package包/类
/**
 * Build the invocation
 *
 * If the method was not specified, use IMethods methods.
 *
 * @return invocation
 */
public Invocation toInvocation() {
    if (method == null) {
        if (argTypes == null) {
            argTypes = new LinkedList<Class<?>>();
            for (Object arg : args) {
                if (arg == null) {
                    argTypes.add(Object.class);
                } else {
                    argTypes.add(arg.getClass());
                }
            }
        }

        try {
            method = MethodsImpl.class.getMethod(methodName, argTypes.toArray(new Class[argTypes.size()]));
        } catch (Exception e) {
            throw new RuntimeException("builder only creates invocations of IMethods interface", e);
        }
    }
    
    Invocation i = new InvocationImpl(mock, new SerializableMethod(method), args, sequenceNumber, null);
    if (verified) {
        i.markVerified();
    }
    return i;
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:34,代码来源:InvocationBuilder.java


示例15: allConfigurationGettersShouldBeCalled

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void allConfigurationGettersShouldBeCalled() {
  plugin = new ValidateMojo(configuration);

  List<Method> invokedMethods = new ArrayList<Method>();
  for (Invocation invocation : mockingDetails(configuration).getInvocations()) {
    invokedMethods.add(invocation.getMethod());
  }

  for (Method method : L10nValidationConfiguration.class.getDeclaredMethods()) {
    if (method.getName().startsWith("get")) {
      assertThat("A getter was not called", invokedMethods, hasItem(method));
    }
  }
}
 
开发者ID:rquinio,项目名称:l10n-maven-plugin,代码行数:16,代码来源:ValidateMojoTest.java


示例16: shouldReturnAllChunksWhenWantedCountDoesntMatch

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void shouldReturnAllChunksWhenWantedCountDoesntMatch() throws Exception {
    Invocation simpleMethodInvocationThree = new InvocationBuilder().mock(mock).toInvocation();
    invocations.add(simpleMethodInvocationThree);
    
    List<Invocation> chunk = finder.findMatchingChunk(invocations, new InvocationMatcher(simpleMethodInvocation), 1, context);
    assertThat(chunk, hasExactlyInOrder(simpleMethodInvocation, simpleMethodInvocationTwo, simpleMethodInvocationThree));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:InvocationsFinderTest.java


示例17: shouldKnowWhenVarargsMatch

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
public void shouldKnowWhenVarargsMatch() {
    //given
    mock.varargs("1", "2", "3");
    Invocation invocation = getLastInvocation();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new Equals("1"), Any.ANY, new InstanceOf(String.class)));

    //when
    boolean match = comparator.argumentsMatch(invocationMatcher, invocation);

    //then
    assertTrue(match);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:ArgumentsComparatorTest.java


示例18: should_capture_arguments_when_args_count_does_NOT_match

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test  // like using several time the captor in the vararg
public void should_capture_arguments_when_args_count_does_NOT_match() throws Exception {
    //given
    mock.varargs();
    Invocation invocation = getLastInvocation();

    //when
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new LocalizedMatcher(AnyVararg.ANY_VARARG)));

    //then
    invocationMatcher.captureArgumentsFrom(invocation);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:InvocationMatcherTest.java


示例19: SmartPrinter

import org.mockito.invocation.Invocation; //导入依赖的package包/类
public SmartPrinter(InvocationMatcher wanted, Invocation actual, Integer ... indexesOfMatchersToBeDescribedWithExtraTypeInfo) {
    PrintSettings printSettings = new PrintSettings();
    printSettings.setMultiline(wanted.toString().contains("\n") || actual.toString().contains("\n"));
    printSettings.setMatchersToBeDescribedWithExtraTypeInfo(indexesOfMatchersToBeDescribedWithExtraTypeInfo);
    
    this.wanted = printSettings.print(wanted);
    this.actual = printSettings.print(actual);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:SmartPrinter.java


示例20: handle_result_must_not_be_null_for_primitives

import org.mockito.invocation.Invocation; //导入依赖的package包/类
@Test
//see issue 331
public void handle_result_must_not_be_null_for_primitives() throws Throwable {
    //given:
    MockCreationSettings settings = (MockCreationSettings) new MockSettingsImpl().defaultAnswer(new Returns(null));
    InternalMockHandler handler = new MockHandlerFactory().create(settings);

    mock.intReturningMethod();
    Invocation invocation = super.getLastInvocation();

    //when:
    Object result = handler.handle(invocation);

    //then null value is not a valid result for a primitive
    assertNotNull(result);
    assertEquals(0, result);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:MockHandlerFactoryTest.java



注:本文中的org.mockito.invocation.Invocation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParDo类代码示例发布时间:2022-05-21
下一篇:
Java WrappedMapper类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap