本文整理汇总了Java中org.mockito.MockSettings类的典型用法代码示例。如果您正苦于以下问题:Java MockSettings类的具体用法?Java MockSettings怎么用?Java MockSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockSettings类属于org.mockito包,在下文中一共展示了MockSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EventCollector
import org.mockito.MockSettings; //导入依赖的package包/类
private EventCollector(Class<Target> targetClass, EventCombiner<Target, Event> combiner,
Collection<Predicate<? super Event>> filters) {
this.combiner = Objects.requireNonNull(combiner, "Event combiner cannot be null!");
this.eventFilters = ImmutableList.copyOf(filters);
this.eventHandlers = selectEventHandlers(filters);
List<DescribedInvocation> invocations = new ArrayList<>();
MockSettings settings = Mockito.withSettings()
.invocationListeners(report -> invocations.add(report.getInvocation()));
this.target = Mockito.mock(targetClass, settings);
combiner.accept(Mockito.doAnswer(this::answer).when(target));
if (invocations.size() != 1)
throw new IllegalStateException("Single listener interaction was expected! But actual: " + invocations);
this.invocation = invocations.get(0);
}
示例2: process
import org.mockito.MockSettings; //导入依赖的package包/类
public Object process(Mock annotation, Field field) {
MockSettings mockSettings = Mockito.withSettings();
if (annotation.extraInterfaces().length > 0) { // never null
mockSettings.extraInterfaces(annotation.extraInterfaces());
}
if ("".equals(annotation.name())) {
mockSettings.name(field.getName());
} else {
mockSettings.name(annotation.name());
}
if(annotation.serializable()){
mockSettings.serializable();
}
// see @Mock answer default value
mockSettings.defaultAnswer(annotation.answer().get());
return Mockito.mock(field.getType(), mockSettings);
}
示例3: getParameterValue
import org.mockito.MockSettings; //导入依赖的package包/类
@Override
public Object getParameterValue(Parameter parameter) {
Mock annotation = parameter.getAnnotation(Mock.class);
MockSettings settings = Mockito.withSettings();
if (annotation.extraInterfaces().length > 0) {
settings.extraInterfaces(annotation.extraInterfaces());
}
if (annotation.serializable()) {
settings.serializable();
}
settings.name(annotation.name().isEmpty() ? parameter.getName() : annotation.name());
settings.defaultAnswer(annotation.answer());
return Mockito.mock(parameter.getType(), settings);
}
示例4: apply
import org.mockito.MockSettings; //导入依赖的package包/类
@Override
public MockSettings apply(MockSettings mockSettings) {
if(Answer.class.equals(answerClass)) {
return mockSettings;
}
return mockSettings.defaultAnswer(createAnswerInstance());
}
示例5: apply
import org.mockito.MockSettings; //导入依赖的package包/类
@Override
public MockSettings apply(MockSettings mockSettings) {
if(listenerClasses.isEmpty()) {
return mockSettings;
}
return mockSettings.invocationListeners(createListeners());
}
示例6: createMockSettings
import org.mockito.MockSettings; //导入依赖的package包/类
public MockSettings createMockSettings(MockSettings mockSettings) {
MockSettings settings = mockSettings;
for (SettingsDecorator decorator : settingsDecorators) {
settings = decorator.apply(settings);
}
return settings;
}
示例7: createSpy
import org.mockito.MockSettings; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T createSpy(String name, Object instance) {
Assert.notNull(instance, "Instance must not be null");
Assert.isInstanceOf(this.classToSpy, instance);
if (this.mockUtil.isSpy(instance)) {
return (T) instance;
}
MockSettings settings = MockReset.withSettings(getReset());
if (StringUtils.hasLength(name)) {
settings.name(name);
}
settings.spiedInstance(instance);
settings.defaultAnswer(Mockito.CALLS_REAL_METHODS);
return (T) Mockito.mock(instance.getClass(), settings);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:SpyDefinition.java
示例8: createMock
import org.mockito.MockSettings; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T createMock(String name) {
MockSettings settings = MockReset.withSettings(getReset());
if (StringUtils.hasLength(name)) {
settings.name(name);
}
if (!this.extraInterfaces.isEmpty()) {
settings.extraInterfaces(this.extraInterfaces.toArray(new Class<?>[] {}));
}
settings.defaultAnswer(getAnswer(this.answer));
if (this.serializable) {
settings.serializable();
}
return (T) Mockito.mock(this.classToMock, settings);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:MockDefinition.java
示例9: createMock
import org.mockito.MockSettings; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T createMock(String name) {
MockSettings settings = MockReset.withSettings(getReset());
if (StringUtils.hasLength(name)) {
settings.name(name);
}
if (!this.extraInterfaces.isEmpty()) {
settings.extraInterfaces(this.extraInterfaces.toArray(new Class<?>[] {}));
}
settings.defaultAnswer(this.answer.get());
if (this.serializable) {
settings.serializable();
}
return (T) Mockito.mock(this.classToMock, settings);
}
示例10: mock
import org.mockito.MockSettings; //导入依赖的package包/类
public static <T> T mock(final Class<T> classToMock, final MockSettings mockSettings) {
return AccessController.doPrivileged(new PrivilegedAction<T>() {
@Override
public T run() {
return org.mockito.Mockito.mock(classToMock, mockSettings);
}
});
}
示例11: withSettings
import org.mockito.MockSettings; //导入依赖的package包/类
public static MockSettings withSettings() {
return AccessController.doPrivileged(new PrivilegedAction<MockSettings>() {
@Override
public MockSettings run() {
return org.mockito.Mockito.withSettings();
}
});
}
示例12: invocationListeners
import org.mockito.MockSettings; //导入依赖的package包/类
public MockSettings invocationListeners(InvocationListener... listeners) {
if (listeners == null || listeners.length == 0) {
new Reporter().invocationListenersRequiresAtLeastOneListener();
}
for (InvocationListener listener : listeners) {
if (listener == null) {
new Reporter().invocationListenerDoesNotAcceptNullParameters();
}
this.invocationListeners.add(listener);
}
return this;
}
示例13: testAddBreakpoint
import org.mockito.MockSettings; //导入依赖的package包/类
@Test
public void testAddBreakpoint() throws Exception {
MockSettings mockSettings =
new MockSettingsImpl<>().defaultAnswer(RETURNS_SMART_NULLS).extraInterfaces(Resource.class);
Project project = mock(Project.class);
when(optional.isPresent()).thenReturn(true);
when(optional.get()).thenReturn(project);
when(project.getPath()).thenReturn(PATH);
VirtualFile virtualFile = mock(VirtualFile.class, mockSettings);
Path path = mock(Path.class);
when(path.toString()).thenReturn(PATH);
when(virtualFile.getLocation()).thenReturn(path);
when(virtualFile.toString()).thenReturn(PATH);
Resource resource = (Resource) virtualFile;
when(resource.getRelatedProject()).thenReturn(optional);
doReturn(promiseVoid).when(service).addBreakpoint(SESSION_ID, breakpointDto);
doReturn(promiseVoid).when(promiseVoid).then((Operation<Void>) any());
doReturn(breakpointDto).when(debugger).toDto(any(Breakpoint.class));
debugger.addBreakpoint(breakpointDto);
verify(service).addBreakpoint(SESSION_ID, breakpointDto);
verify(promiseVoid).then(operationVoidCaptor.capture());
operationVoidCaptor.getValue().apply(null);
verify(observer).onBreakpointAdded(breakpointCaptor.capture());
assertEquals(breakpointCaptor.getValue(), breakpointDto);
verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
operationPromiseErrorCaptor.getValue().apply(promiseError);
verify(promiseError).getMessage();
}
示例14: setUpMockCreator
import org.mockito.MockSettings; //导入依赖的package包/类
private void setUpMockCreator(){
ClassLoader loader = targetClass.getClassLoader();
try {
Class<?> mockito = loader.loadClass(Mockito.class.getName());
mockCreator = mockito.getDeclaredMethod("mock",
loader.loadClass(Class.class.getName()), loader.loadClass(MockSettings.class.getName()));
} catch (Exception e) {
logger.error("Failed to setup mock creator: "+e.getMessage());
}
}
示例15: processAnnotationOn
import org.mockito.MockSettings; //导入依赖的package包/类
private Object processAnnotationOn(Mock annotation, Field field) {
MockSettings mockSettings = Mockito.withSettings();
if (annotation.extraInterfaces().length > 0) { // never null
mockSettings.extraInterfaces(annotation.extraInterfaces());
}
if ("".equals(annotation.name())) {
mockSettings.name(field.getName());
} else {
mockSettings.name(annotation.name());
}
// see @Mock answer default value
mockSettings.defaultAnswer(annotation.answer().get());
return Mockito.mock(field.getType(), mockSettings);
}