public static Object processAnnotationForMock(Mock annotation, Class<?> type, 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()); return Mockito.mock(type, mockSettings); } }
public static MuleContextWithRegistry mockMuleContext() { final MuleContextWithRegistry muleContext = mock(DefaultMuleContext.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS).extraInterfaces(PrivilegedMuleContext.class).lenient()); when(muleContext.getUniqueIdString()).thenReturn(UUID.getUUID()); when(muleContext.getDefaultErrorHandler(empty())).thenReturn(new OnErrorPropagateHandler()); StreamingManager streamingManager = mock(StreamingManager.class, RETURNS_DEEP_STUBS); try { MuleRegistry registry = mock(MuleRegistry.class, withSettings().lenient()); when(muleContext.getRegistry()).thenReturn(registry); ComponentInitialStateManager componentInitialStateManager = mock(ComponentInitialStateManager.class, withSettings().lenient()); when(componentInitialStateManager.mustStartMessageSource(any())).thenReturn(true); when(registry.lookupObject(ComponentInitialStateManager.SERVICE_ID)).thenReturn(componentInitialStateManager); doReturn(streamingManager).when(registry).lookupObject(StreamingManager.class); doReturn(mock(NotificationDispatcher.class)).when(registry).lookupObject(NotificationDispatcher.class); doReturn(mock(ObjectStoreManager.class, RETURNS_DEEP_STUBS)).when(registry).lookupObject(OBJECT_STORE_MANAGER); } catch (RegistrationException e) { throw new RuntimeException(e); } return muleContext; }
ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class, withSettings().lenient()); when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository); when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class))); ConfigurationProperties configProps = mock(ConfigurationProperties.class, withSettings().lenient()); when(configProps.resolveBooleanProperty(any())).thenReturn(empty()); mock(ConfigurationComponentLocator.class, withSettings().lenient()); when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty()); when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
public static ParameterGroupModel mockParameters(ParameterizedModel parameterizedModel, String groupName, ParameterModel... parameterModels) { ParameterGroupModel group = mock(ParameterGroupModel.class, withSettings().lenient()); when(group.getName()).thenReturn(groupName); when(group.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty()); when(parameterizedModel.getParameterGroupModels()).thenReturn(asList(group)); when(group.getParameterModels()).thenReturn(asList(parameterModels)); when(parameterizedModel.getAllParameterModels()).thenReturn(asList(parameterModels)); return group; }
private OutputModel mockOutputModel(Type type) { OutputModel om = mock(OutputModel.class, withSettings().lenient()); when(om.getType()).thenReturn(loader.load(type)); return om; }
private static ParameterModel getParameter() { ParameterModel parameterModel = mock(ParameterModel.class, withSettings().lenient()); when(parameterModel.getModelProperty(any())).thenReturn(Optional.empty()); when(parameterModel.getDslConfiguration()).thenReturn(ParameterDslConfiguration.getDefaultInstance()); when(parameterModel.getRole()).thenReturn(BEHAVIOUR); return parameterModel; }
private OutputModel mockOutputModel(Type type) { OutputModel om = mock(OutputModel.class, withSettings().lenient()); when(om.getType()).thenReturn(loader.load(type)); return om; }
private OperationModel mockOperationModel(OutputModel output, OutputModel attributes, ParameterModel... params) { OperationModel op = mock(OperationModel.class, withSettings().lenient()); when(op.getOutput()).thenReturn(output); when(op.getOutputAttributes()).thenReturn(attributes); if (params != null) { mockParameters(op, params); } return op; } }
private OperationModel mockOperationModel(OutputModel output, OutputModel attributes, ParameterModel... params) { OperationModel op = mock(OperationModel.class, withSettings().lenient()); when(op.getOutput()).thenReturn(output); when(op.getOutputAttributes()).thenReturn(attributes); if (params != null) { mockParameters(op, params); } return op; } }
@Test(expected = IllegalModelDefinitionException.class) public void repeatedEncodingOperationArgumentObjectFields() { when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); withMethod(operationModel, "argumentWithRepeatedEncodingFields"); ParameterModel parameterModel = mock(ParameterModel.class, withSettings().lenient()); when(parameterModel.getType()).thenReturn(toMetadataType(RepeatedEncoding.class)); mockParameters(operationModel, parameterModel); validate(extensionModel, validator); }