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);
}
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());
}
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);
}
}
Aggregations