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


Java Stubber类代码示例

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


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

示例1: doThrowWhenCallStackMatches

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
/**
 * Throw an exception from the mock/spy only in the case that the
 * call stack at the time the method has a line which matches the given
 * pattern.
 *
 * @param t the Throwable to throw
 * @param pattern the pattern against which to match the call stack trace
 * @return the stub in progress
 */
public static Stubber doThrowWhenCallStackMatches(
    final Throwable t, final String pattern) {
  return Mockito.doAnswer(new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      t.setStackTrace(Thread.currentThread().getStackTrace());
      for (StackTraceElement elem : t.getStackTrace()) {
        if (elem.toString().matches(pattern)) {
          throw t;
        }
      }
      return invocation.callRealMethod();
    }
  });
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:MockitoUtil.java

示例2: answerStringByReference

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber answerStringByReference(String value) {
	return doAnswer((Answer<Integer>) invocation -> {

           Object[] args = invocation.getArguments();
           PointerByReference reference = (PointerByReference)args[0];

           Pointer pointer = new Memory(Native.WCHAR_SIZE * (value.length() +1));
           pointer.setWideString(0, value);

           reference.setValue(pointer);

           return 0;
       });
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:15,代码来源:BaseAutomationTest.java

示例3: answerIntByReference

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber answerIntByReference(int value) {
	return doAnswer((Answer<Integer>) invocation -> {

           Object[] args = invocation.getArguments();
           IntByReference reference = (IntByReference)args[0];

           reference.setValue(value);

           return 0;
       });
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:12,代码来源:BaseAutomationTest.java

示例4: doUpdateInto

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private Stubber doUpdateInto(final List<Update> updates) {
    return doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation)
                throws Throwable {
            //noinspection unchecked
            Iterables.addAll(updates, (Iterable<Update>) invocation.getArguments()[0]);
            return null;
        }
    });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:12,代码来源:DataStoreJerseyTest.java

示例5: captureUpdatesAndTags

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private Stubber captureUpdatesAndTags(final List<Update> updates, final Set<String> tags) {
    return doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation)
                throws Throwable {
            //noinspection unchecked
            Iterables.addAll(updates, (Iterable<Update>) invocation.getArguments()[0]);
            //noinspection unchecked
            tags.addAll((Collection<? extends String>) invocation.getArguments()[1]);
            return null;
        }
    });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:14,代码来源:DataStoreJerseyTest.java

示例6: doThrow

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doThrow(final Throwable toBeThrown) {
    return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
        @Override
        public Stubber run() {
            return org.mockito.Mockito.doThrow(toBeThrown);
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例7: doCallRealMethod

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doCallRealMethod() {
    return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
        @Override
        public Stubber run() {
            return org.mockito.Mockito.doCallRealMethod();
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例8: doAnswer

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doAnswer(final Answer answer) {
    return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
        @Override
        public Stubber run() {
            return org.mockito.Mockito.doAnswer(answer);
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例9: doNothing

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doNothing() {
    return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
        @Override
        public Stubber run() {
            return org.mockito.Mockito.doNothing();
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例10: doReturn

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doReturn(final Object toBeReturned) {
    return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
        @Override
        public Stubber run() {
            return org.mockito.Mockito.doReturn(toBeReturned);
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例11: copyToParameter

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber copyToParameter(byte[] result)
{
	return Mockito.doAnswer((x) ->
	{
		byte[] dst = (byte[])x.getArguments()[0];
		
		System.arraycopy(result, 0, dst, 0, result.length);
		return null;
	});
}
 
开发者ID:Strachu,项目名称:VirtualSlideViewer,代码行数:11,代码来源:TestUtil.java

示例12: doReturn

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
/**
 * Extend Mockito API by allowing an arbitrary number of inputs to
 * the method {@code doReturn()}
 *
 * @param value
 * @param values
 * @return
 */
public static Stubber doReturn(Object value, Object... values){

    Stubber stubber = Mockito.doReturn(value);
    for(Object v : values){
        stubber = stubber.doReturn(v);
    }

    return stubber;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:18,代码来源:MockitoExtension.java

示例13: toAnswer

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Stubber toAnswer(final Runnable method) {
    return Mockito.doAnswer(invocation -> {
        Object[] arguments = invocation.getArguments();
        method.run();
        return null;
    });
}
 
开发者ID:RichardWarburton,项目名称:lambda-behave,代码行数:9,代码来源:Expect.java

示例14: doAnswer

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private  Stubber doAnswer(final Consumer<Object[]> method, final int argumentCount) {
    return Mockito.doAnswer(invocation -> {
        Object[] arguments = invocation.getArguments();
        if (arguments.length >= argumentCount) {
            method.accept(arguments);
        } else {
            failure("Invocation requires at least " + argumentCount + " argument");
        }
        return null;
    });
}
 
开发者ID:RichardWarburton,项目名称:lambda-behave,代码行数:12,代码来源:Expect.java

示例15: spyReturnValue

import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public Stubber spyReturnValue() {
    return Mockito.doAnswer(new Answer<T>() {
        public T answer(InvocationOnMock invocation) throws Throwable {
            return setupSpy(invocation.callRealMethod());
        }
    });
}
 
开发者ID:joshng,项目名称:papaya,代码行数:8,代码来源:SpyRef.java


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