Search in sources :

Example 16 with MockSettings

use of org.mockito.MockSettings in project spring-boot by spring-projects.

the class MockDefinition method createMock.

@SuppressWarnings("unchecked")
<T> T createMock(String name) {
    MockSettings settings = MockReset.withSettings(getReset());
    if (StringUtils.hasLength(name)) {
        settings.name(name);
    }
    if (!this.extraInterfaces.isEmpty()) {
        settings.extraInterfaces(ClassUtils.toClassArray(this.extraInterfaces));
    }
    settings.defaultAnswer(this.answer);
    if (this.serializable) {
        settings.serializable();
    }
    return (T) mock(this.typeToMock.resolve(), settings);
}
Also used : MockSettings(org.mockito.MockSettings)

Example 17 with MockSettings

use of org.mockito.MockSettings in project mockito by mockito.

the class DeepStubbingTest method named_to_string.

@Test
public void named_to_string() {
    MockSettings settings = withSettings().name("name of mock").defaultAnswer(RETURNS_DEEP_STUBS);
    SocketFactory sf = mock(SocketFactory.class, settings);
    assertEquals("name of mock", sf.toString());
}
Also used : SocketFactory(javax.net.SocketFactory) MockSettings(org.mockito.MockSettings) Test(org.junit.Test)

Example 18 with MockSettings

use of org.mockito.MockSettings in project mockito by mockito.

the class MockAnnotationProcessor method processAnnotationForMock.

public static Object processAnnotationForMock(Mock annotation, Class<?> type, Supplier<Type> genericType, String name) {
    MockSettings mockSettings = Mockito.withSettings();
    if (annotation.extraInterfaces().length > 0) {
        // never null
        mockSettings.extraInterfaces(annotation.extraInterfaces());
    }
    if ("".equals(annotation.name())) {
        mockSettings.name(name);
    } else {
        mockSettings.name(annotation.name());
    }
    if (annotation.serializable()) {
        mockSettings.serializable();
    }
    if (annotation.stubOnly()) {
        mockSettings.stubOnly();
    }
    if (annotation.lenient()) {
        mockSettings.lenient();
    }
    // see @Mock answer default value
    mockSettings.defaultAnswer(annotation.answer());
    if (type == MockedStatic.class) {
        return Mockito.mockStatic(inferParameterizedType(genericType.get(), name, MockedStatic.class.getSimpleName()), mockSettings);
    } else if (type == MockedConstruction.class) {
        return Mockito.mockConstruction(inferParameterizedType(genericType.get(), name, MockedConstruction.class.getSimpleName()), mockSettings);
    } else {
        return Mockito.mock(type, mockSettings);
    }
}
Also used : MockedConstruction(org.mockito.MockedConstruction) MockSettings(org.mockito.MockSettings)

Aggregations

MockSettings (org.mockito.MockSettings)18 Test (org.junit.Test)10 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)5 CollectionData (com.torodb.core.d2r.CollectionData)4 DocPartData (com.torodb.core.d2r.DocPartData)4 BackendTransactionJob (com.torodb.core.dsl.backend.BackendTransactionJob)4 InsertBackendJob (com.torodb.core.dsl.backend.InsertBackendJob)4 Optional (java.util.Optional)4 AddFieldDdlJob (com.torodb.core.dsl.backend.AddFieldDdlJob)2 AddScalarDddlJob (com.torodb.core.dsl.backend.AddScalarDddlJob)2 ImmutableMetaField (com.torodb.core.transaction.metainf.ImmutableMetaField)2 ImmutableMetaScalar (com.torodb.core.transaction.metainf.ImmutableMetaScalar)2 MockName (org.mockito.mock.MockName)2 AddDocPartDdlJob (com.torodb.core.dsl.backend.AddDocPartDdlJob)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Set (java.util.Set)1 SocketFactory (javax.net.SocketFactory)1 VariablePath (org.eclipse.che.api.debug.shared.model.VariablePath)1