@Test
  public void should_create_a_complex_contract_input_with_generated_child_input_from_mapping()
      throws Exception {
    final SimpleFieldToContractInputMapping notGeneratedMapping =
        new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("input2").build());
    notGeneratedMapping.setGenerated(false);
    final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
    final BusinessObjectModelRepositoryStore businessStore =
        mock(BusinessObjectModelRepositoryStore.class);
    when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class))
        .thenReturn(businessStore);
    final RootContractInputGenerator rootContractInputGenerator =
        new RootContractInputGenerator(
            "rootInputName",
            newArrayList(
                notGeneratedMapping,
                new SimpleFieldToContractInputMapping(
                    SimpleFieldBuilder.aStringField("input1").build())),
            repositoryAccessor,
            mock(FieldToContractInputMappingOperationBuilder.class),
            mock(FieldToContractInputMappingExpressionBuilder.class));

    rootContractInputGenerator.build(aBusinessData().build());

    assertThat(rootContractInputGenerator.getRootContractInput().getInputs()).hasSize(1);
  }
  @Test
  public void should_create_operation_for_given_business_data_and_generated_contract_input()
      throws Exception {
    final SimpleFieldToContractInputMapping mapping =
        new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("firstName").build());

    final FieldToContractInputMappingOperationBuilder operationBuilder =
        mock(FieldToContractInputMappingOperationBuilder.class);
    final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
    final BusinessObjectModelRepositoryStore businessStore =
        mock(BusinessObjectModelRepositoryStore.class);
    when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class))
        .thenReturn(businessStore);
    final RootContractInputGenerator rootContractInputGenerator =
        new RootContractInputGenerator(
            "rootInputName",
            newArrayList(mapping),
            repositoryAccessor,
            operationBuilder,
            mock(FieldToContractInputMappingExpressionBuilder.class));
    final BusinessObjectData businessObjectData = aBusinessData().withName("employee").build();
    rootContractInputGenerator.build(businessObjectData);

    verify(operationBuilder).toOperation(businessObjectData, mapping);
  }
  @Test
  public void
      should_create_initilal_value_expression_for_given_multiple_business_data_and_generated_contract_input()
          throws Exception {
    final SimpleFieldToContractInputMapping mapping =
        new SimpleFieldToContractInputMapping(SimpleFieldBuilder.aStringField("firstName").build());

    final FieldToContractInputMappingOperationBuilder operationBuilder =
        mock(FieldToContractInputMappingOperationBuilder.class);
    final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
    final BusinessObjectModelRepositoryStore businessStore =
        mock(BusinessObjectModelRepositoryStore.class);
    when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class))
        .thenReturn(businessStore);
    final FieldToContractInputMappingExpressionBuilder expressionBuilder =
        mock(FieldToContractInputMappingExpressionBuilder.class);
    final RootContractInputGenerator rootContractInputGenerator =
        new RootContractInputGenerator(
            "rootInputName",
            newArrayList(mapping),
            repositoryAccessor,
            operationBuilder,
            expressionBuilder);
    final BusinessObjectData businessObjectData =
        aBusinessData().withName("employee").multiple().build();
    rootContractInputGenerator.build(businessObjectData);

    final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor =
        ArgumentCaptor.forClass(FieldToContractInputMapping.class);
    verify(expressionBuilder).toExpression(eq(businessObjectData), argumentCaptor.capture());
    final FieldToContractInputMapping fieldToContractInputMapping = argumentCaptor.getValue();
    assertThat(fieldToContractInputMapping.getField().getName()).isEqualTo("rootInputName");
    assertThat(fieldToContractInputMapping.getField().isCollection()).isTrue();
    assertThat(fieldToContractInputMapping.getChildren()).hasSize(1);
  }
  @Test
  public void
      should_create_operation_for_given_multiple_business_data_and_generated_contract_input()
          throws Exception {
    final SimpleField firstNameField = SimpleFieldBuilder.aStringField("firstName").build();
    final SimpleFieldToContractInputMapping mapping =
        new SimpleFieldToContractInputMapping(firstNameField);

    final BusinessObjectModelRepositoryStore businessObjectStore =
        mock(BusinessObjectModelRepositoryStore.class);
    final BusinessObject bo = aBO("org.test.Employee").withField(firstNameField).build();
    when(businessObjectStore.getBusinessObjectByQualifiedName("org.test.Employee")).thenReturn(bo);
    final RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
    when(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class))
        .thenReturn(businessObjectStore);
    final FieldToContractInputMappingOperationBuilder operationBuilder =
        mock(FieldToContractInputMappingOperationBuilder.class);
    final RootContractInputGenerator rootContractInputGenerator =
        new RootContractInputGenerator(
            "employeesInput",
            newArrayList(mapping),
            repositoryAccessor,
            operationBuilder,
            mock(FieldToContractInputMappingExpressionBuilder.class));
    final BusinessObjectData businessObjectData =
        aBusinessData().withName("employees").withClassname("org.test.Employee").multiple().build();
    rootContractInputGenerator.build(businessObjectData);

    final ArgumentCaptor<FieldToContractInputMapping> argumentCaptor =
        ArgumentCaptor.forClass(FieldToContractInputMapping.class);
    verify(operationBuilder).toOperation(eq(businessObjectData), argumentCaptor.capture());
    final Field field = argumentCaptor.getValue().getField();
    assertThat(field).isInstanceOf(RelationField.class);
    assertThat(field.getName()).isEqualTo("employeesInput");
    assertThat(field.isCollection()).isTrue();
    assertThat(((RelationField) field).getReference().getQualifiedName())
        .isEqualTo("org.test.Employee");
    assertThat(((RelationField) field).getType()).isEqualTo(RelationField.Type.COMPOSITION);
  }