本文整理汇总了Java中org.mockito.mock.MockCreationSettings类的典型用法代码示例。如果您正苦于以下问题:Java MockCreationSettings类的具体用法?Java MockCreationSettings怎么用?Java MockCreationSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockCreationSettings类属于org.mockito.mock包,在下文中一共展示了MockCreationSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
@Test
public void createMock() throws Exception {
MockDefinition definition = new MockDefinition("name", ExampleService.class,
new Class<?>[] { ExampleExtraInterface.class },
Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE, true);
ExampleService mock = definition.createMock();
MockCreationSettings<?> settings = new MockUtil().getMockSettings(mock);
assertThat(mock).isInstanceOf(ExampleService.class);
assertThat(mock).isInstanceOf(ExampleExtraInterface.class);
assertThat(settings.getMockName().toString()).isEqualTo("name");
assertThat(settings.getDefaultAnswer())
.isEqualTo(Answers.RETURNS_SMART_NULLS.get());
assertThat(settings.isSerializable()).isTrue();
assertThat(MockReset.get(mock)).isEqualTo(MockReset.BEFORE);
}
示例2: createSpy
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
@Test
public void createSpy() throws Exception {
SpyDefinition definition = new SpyDefinition("name", RealExampleService.class,
MockReset.BEFORE, true);
RealExampleService spy = definition.createSpy(new RealExampleService("hello"));
MockCreationSettings<?> settings = new MockUtil().getMockSettings(spy);
assertThat(spy).isInstanceOf(ExampleService.class);
assertThat(settings.getMockName().toString()).isEqualTo("name");
assertThat(settings.getDefaultAnswer())
.isEqualTo(Answers.CALLS_REAL_METHODS.get());
assertThat(MockReset.get(spy)).isEqualTo(MockReset.BEFORE);
}
示例3: create
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public InternalMockHandler create(MockCreationSettings settings) {
InternalMockHandler handler = new MockHandlerImpl(settings);
InternalMockHandler nullResultGuardian = new NullResultGuardian(handler);
InternalMockHandler notifier = new InvocationNotifierHandler(nullResultGuardian, settings);
return notifier;
}
示例4: AcrossJVMMockSerializationProxy
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
/**
* Creates the wrapper that be used in the serialization stream.
*
* <p>Immediately serializes the Mockito mock using specifically crafted {@link MockitoMockObjectOutputStream},
* in a byte array.</p>
*
* @param mockitoMock The Mockito mock to serialize.
* @throws IOException
*/
public AcrossJVMMockSerializationProxy(Object mockitoMock) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new MockitoMockObjectOutputStream(out);
objectOutputStream.writeObject(mockitoMock);
objectOutputStream.close();
out.close();
MockCreationSettings mockSettings = new MockUtil().getMockSettings(mockitoMock);
this.serializedMock = out.toByteArray();
this.typeToMock = mockSettings.getTypeToMock();
this.extraInterfaces = mockSettings.getExtraInterfaces();
}
示例5: createMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public <T> T createMock(MockCreationSettings<T> settings) {
MockHandler mockHandler = new MockHandlerFactory().create(settings);
T mock = mockMaker.createMock(settings, mockHandler);
Object spiedInstance = settings.getSpiedInstance();
if (spiedInstance != null) {
new LenientCopyTool().copyToMock(spiedInstance, mock);
}
return mock;
}
示例6: resetMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public <T> void resetMock(T mock) {
InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
MockCreationSettings settings = oldHandler.getMockSettings();
MockHandler newHandler = new MockHandlerFactory().create(settings);
mockMaker.resetMock(mock, newHandler, settings);
}
示例7: handle_result_must_not_be_null_for_primitives
import org.mockito.mock.MockCreationSettings; //导入依赖的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);
}
示例8: valid_handle_result_is_permitted
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
@Test
//see issue 331
public void valid_handle_result_is_permitted() throws Throwable {
//given:
MockCreationSettings settings = (MockCreationSettings) new MockSettingsImpl().defaultAnswer(new Returns(123));
InternalMockHandler handler = new MockHandlerFactory().create(settings);
mock.intReturningMethod();
Invocation invocation = super.getLastInvocation();
//when:
Object result = handler.handle(invocation);
//then
assertEquals(123, result);
}
示例9: resetMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
@Override
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
if (adapter != null) {
adapter.setHandler(newHandler);
}
}
示例10: onMockCreated
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
@SuppressWarnings("rawtypes") // The MockCreationListener interface forces this
@Override
public void onMockCreated(Object mock, MockCreationSettings settings) {
mocks.add(mock);
}
示例11: createMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
return cglibMockMaker.createMock(settings, handler);
}
示例12: resetMock
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
cglibMockMaker.resetMock(mock, newHandler, settings);
}
示例13: getMockSettings
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public MockCreationSettings getMockSettings() {
final MockSettingsImpl mockSettings = new MockSettingsImpl();
mockSettings.setMockName(new MockNameImpl(mock.getName()));
mockSettings.setTypeToMock(mock);
return mockSettings;
}
示例14: PowerMockMethodInterceptorFilter
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public PowerMockMethodInterceptorFilter(InternalMockHandler handler,
MockCreationSettings mockSettings) {
super(handler, mockSettings);
}
示例15: MethodInterceptorFilter
import org.mockito.mock.MockCreationSettings; //导入依赖的package包/类
public MethodInterceptorFilter(InternalMockHandler handler, MockCreationSettings mockSettings) {
this.handler = handler;
this.mockSettings = mockSettings;
}