当前位置: 首页>>代码示例>>Java>>正文


Java Invocation类代码示例

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


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


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