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


Java MockSettings类代码示例

本文整理汇总了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);
}
 
开发者ID:Whaka-project,项目名称:whakamatautau-util,代码行数:20,代码来源:EventCollector.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:MockAnnotationProcessor.java

示例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);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:16,代码来源:MockParameterFactory.java

示例4: apply

import org.mockito.MockSettings; //导入依赖的package包/类
@Override
public MockSettings apply(MockSettings mockSettings) {
	if(Answer.class.equals(answerClass)) {
		return mockSettings;
	}

	return mockSettings.defaultAnswer(createAnswerInstance());
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:9,代码来源:DefaultAnswerMockSettings.java

示例5: apply

import org.mockito.MockSettings; //导入依赖的package包/类
@Override
public MockSettings apply(MockSettings mockSettings) {
	if(listenerClasses.isEmpty()) {
		return mockSettings;
	}

	return mockSettings.invocationListeners(createListeners());
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:9,代码来源:InvocationListenersSettings.java

示例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;
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:8,代码来源:MockitoDoubleConfiguration.java

示例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);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:16,代码来源:MockDefinition.java

示例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);
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例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();
        }
    });
}
 
开发者ID:elastic,项目名称:securemock,代码行数:9,代码来源:Mockito.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:13,代码来源:MockSettingsImpl.java

示例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();
}
 
开发者ID:eclipse,项目名称:che,代码行数:34,代码来源:DebuggerTest.java

示例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());
    }
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:12,代码来源:FunctionalMockStatement.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:DefaultAnnotationEngine.java


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