use of org.mockito.internal.creation.settings.CreationSettings in project j2objc by google.
the class MockSettingsImpl method validatedSettings.
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) {
MockCreationValidator validator = new MockCreationValidator();
validator.validateType(typeToMock);
validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces());
validator.validateMockedType(typeToMock, source.getSpiedInstance());
//TODO SF - add this validation and also add missing coverage
// validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance());
CreationSettings<T> settings = new CreationSettings<T>(source);
settings.setMockName(new MockNameImpl(source.getName(), typeToMock));
settings.setTypeToMock(typeToMock);
settings.setExtraInterfaces(prepareExtraInterfaces(source));
return settings;
}
use of org.mockito.internal.creation.settings.CreationSettings in project mockito by mockito.
the class MockSettingsImpl method validatedStaticSettings.
private static <T> CreationSettings<T> validatedStaticSettings(Class<T> classToMock, CreationSettings<T> source) {
if (classToMock.isPrimitive()) {
throw new MockitoException("Cannot create static mock of primitive type " + classToMock);
}
if (!source.getExtraInterfaces().isEmpty()) {
throw new MockitoException("Cannot specify additional interfaces for static mock of " + classToMock);
}
if (source.getSpiedInstance() != null) {
throw new MockitoException("Cannot specify spied instance for static mock of " + classToMock);
}
CreationSettings<T> settings = new CreationSettings<T>(source);
settings.setMockName(new MockNameImpl(source.getName(), classToMock, true));
settings.setTypeToMock(classToMock);
return settings;
}
use of org.mockito.internal.creation.settings.CreationSettings in project mockito by mockito.
the class MockSettingsImpl method validatedSettings.
private static <T> CreationSettings<T> validatedSettings(Class<T> typeToMock, CreationSettings<T> source) {
MockCreationValidator validator = new MockCreationValidator();
validator.validateType(typeToMock);
validator.validateExtraInterfaces(typeToMock, source.getExtraInterfaces());
validator.validateMockedType(typeToMock, source.getSpiedInstance());
// TODO SF - add this validation and also add missing coverage
// validator.validateDelegatedInstance(classToMock, settings.getDelegatedInstance());
validator.validateConstructorUse(source.isUsingConstructor(), source.getSerializableMode());
// TODO SF - I don't think we really need CreationSettings type
// TODO do we really need to copy the entire settings every time we create mock object? it
// does not seem necessary.
CreationSettings<T> settings = new CreationSettings<T>(source);
settings.setMockName(new MockNameImpl(source.getName(), typeToMock, false));
settings.setTypeToMock(typeToMock);
settings.setExtraInterfaces(prepareExtraInterfaces(source));
return settings;
}
use of org.mockito.internal.creation.settings.CreationSettings in project mockito by mockito.
the class MockSettingsTest method test_without_annotations.
@Test
public void test_without_annotations() throws Exception {
MockCreationSettings<List> settings = Mockito.withSettings().withoutAnnotations().build(List.class);
CreationSettings copy = new CreationSettings((CreationSettings) settings);
assertEquals(List.class, settings.getTypeToMock());
assertEquals(List.class, copy.getTypeToMock());
assertTrue(settings.isStripAnnotations());
assertTrue(copy.isStripAnnotations());
}
use of org.mockito.internal.creation.settings.CreationSettings in project mockito by mockito.
the class MockUtil method maybeRedefineMockName.
public static void maybeRedefineMockName(Object mock, String newName) {
MockName mockName = getMockName(mock);
// TODO SF hacky...
MockCreationSettings mockSettings = getMockHandler(mock).getMockSettings();
if (mockName.isDefault() && mockSettings instanceof CreationSettings) {
((CreationSettings) mockSettings).setMockName(new MockNameImpl(newName));
}
}
Aggregations