Search in sources :

Example 1 with CreationSettings

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;
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) CreationSettings(org.mockito.internal.creation.settings.CreationSettings) MockCreationValidator(org.mockito.internal.util.MockCreationValidator) MockNameImpl(org.mockito.internal.util.MockNameImpl)

Example 2 with CreationSettings

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;
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) CreationSettings(org.mockito.internal.creation.settings.CreationSettings) MockitoException(org.mockito.exceptions.base.MockitoException) MockNameImpl(org.mockito.internal.util.MockNameImpl)

Example 3 with CreationSettings

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;
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) CreationSettings(org.mockito.internal.creation.settings.CreationSettings) MockCreationValidator(org.mockito.internal.util.MockCreationValidator) MockNameImpl(org.mockito.internal.util.MockNameImpl)

Example 4 with CreationSettings

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());
}
Also used : MockCreationSettings(org.mockito.mock.MockCreationSettings) CreationSettings(org.mockito.internal.creation.settings.CreationSettings) List(java.util.List) Test(org.junit.Test)

Example 5 with CreationSettings

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));
    }
}
Also used : MockName(org.mockito.mock.MockName) MockCreationSettings(org.mockito.mock.MockCreationSettings) CreationSettings(org.mockito.internal.creation.settings.CreationSettings) MockCreationSettings(org.mockito.mock.MockCreationSettings)

Aggregations

CreationSettings (org.mockito.internal.creation.settings.CreationSettings)5 MockCreationSettings (org.mockito.mock.MockCreationSettings)5 MockNameImpl (org.mockito.internal.util.MockNameImpl)3 MockCreationValidator (org.mockito.internal.util.MockCreationValidator)2 List (java.util.List)1 Test (org.junit.Test)1 MockitoException (org.mockito.exceptions.base.MockitoException)1 MockName (org.mockito.mock.MockName)1