Java Code Examples for org.mockito.mock.MockCreationSettings#getTypeToMock()
The following examples show how to use
org.mockito.mock.MockCreationSettings#getTypeToMock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AcrossJVMSerializationFeature.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example 2
Source File: InlineStaticMockMaker.java From dexmaker with Apache License 2.0 | 5 votes |
@Override public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) { Class<T> typeToMock = settings.getTypeToMock(); if (!typeToMock.equals(mockingInProgressClass.get()) || Modifier.isAbstract(typeToMock .getModifiers())) { return null; } Set<Class<?>> interfacesSet = settings.getExtraInterfaces(); InvocationHandlerAdapter handlerAdapter = new InvocationHandlerAdapter(handler); classTransformer.mockClass(MockFeatures.withMockFeatures(typeToMock, interfacesSet)); Instantiator instantiator = Mockito.framework().getPlugins().getDefaultPlugin (InstantiatorProvider2.class).getInstantiator(settings); T mock; try { mock = instantiator.newInstance(typeToMock); } catch (org.mockito.creation.instance.InstantiationException e) { throw new MockitoException("Unable to create mock instance of type '" + typeToMock .getSimpleName() + "'", e); } if (classToMarker.containsKey(typeToMock)) { throw new MockitoException(typeToMock + " is already mocked"); } classToMarker.put(typeToMock, mock); markerToHandler.put(mock, handlerAdapter); return mock; }