protected B2BPermissionData populateB2BPermissionDataFromForm(
      final B2BPermissionForm b2BPermissionForm) throws ParseException {
    final B2BPermissionData b2BPermissionData = new B2BPermissionData();
    b2BPermissionData.setOriginalCode(b2BPermissionForm.getOriginalCode());
    final String permissionCode = b2BPermissionForm.getCode();
    if (StringUtils.isNotEmpty(permissionCode)) {
      b2BPermissionData.setCode(permissionCode);
    } else {
      b2BPermissionData.setCode(assignPermissionName(b2BPermissionForm));
    }
    final B2BPermissionTypeData b2BPermissionTypeData =
        b2BPermissionForm.getB2BPermissionTypeData();
    b2BPermissionData.setB2BPermissionTypeData(b2BPermissionTypeData);
    final CurrencyData currencyData = new CurrencyData();
    currencyData.setIsocode(b2BPermissionForm.getCurrency());
    b2BPermissionData.setCurrency(currencyData);

    b2BPermissionData.setUnit(
        companyB2BCommerceFacade.getUnitForUid(b2BPermissionForm.getParentUnitName()));
    final String permissionTimespan = b2BPermissionForm.getTimeSpan();
    if (StringUtils.isNotEmpty(permissionTimespan)) {
      b2BPermissionData.setPeriodRange(B2BPeriodRange.valueOf(b2BPermissionForm.getTimeSpan()));
    }
    final String monetaryValue = b2BPermissionForm.getValue();
    if (StringUtils.isNotEmpty(monetaryValue)) {
      b2BPermissionData.setValue(
          Double.valueOf(formatFactory.createNumberFormat().parse(monetaryValue).doubleValue()));
    }
    return b2BPermissionData;
  }
  @Test
  public void testPopulateAll() {
    final CustomerData customerData = mock(CustomerData.class);
    final CustomerModel customerModel = new CustomerModel();

    final CurrencyData currencyData = mock(CurrencyData.class);
    final LanguageData languageData = mock(LanguageData.class);
    final CurrencyModel currencyModel = mock(CurrencyModel.class);
    final LanguageModel languageModel = mock(LanguageModel.class);

    given(customerData.getFirstName()).willReturn("firstName");
    given(customerData.getLastName()).willReturn("lastName");
    given(customerData.getTitleCode()).willReturn(null);
    given(customerNameStrategy.getName("firstName", "lastName")).willReturn("firstName lastName");

    given(customerData.getCurrency()).willReturn(currencyData);
    given(currencyData.getIsocode()).willReturn("USD");
    given(currencyModel.getIsocode()).willReturn("USD");
    given(commonI18NService.getCurrency("USD")).willReturn(currencyModel);

    given(customerData.getLanguage()).willReturn(languageData);
    given(languageData.getIsocode()).willReturn("en");
    given(languageModel.getIsocode()).willReturn("en");
    given(commonI18NService.getLanguage("en")).willReturn(languageModel);

    customerReversePopulator.populate(customerData, customerModel);
    Assert.assertEquals("firstName lastName", customerModel.getName());
    Assert.assertNull(customerModel.getTitle());
    Assert.assertEquals("USD", customerModel.getSessionCurrency().getIsocode());
    Assert.assertEquals("en", customerModel.getSessionLanguage().getIsocode());
  }
 @Test(expected = ConversionException.class)
 public void testPopulateCurrencyUnknownIdent() {
   final CustomerData customerData = mock(CustomerData.class);
   final CustomerModel customerModel = new CustomerModel();
   final CurrencyData currencyData = mock(CurrencyData.class);
   given(customerData.getCurrency()).willReturn(currencyData);
   given(currencyData.getIsocode()).willReturn("currencyIso");
   given(commonI18NService.getCurrency("currencyIso"))
       .willThrow(new UnknownIdentifierException(""));
   customerReversePopulator.populate(customerData, customerModel);
 }
  protected B2BCostCenterData populateB2BCostCenterDataFromForm(
      final B2BCostCenterForm b2BCostCenterForm) {
    final B2BCostCenterData b2BCostCenterData = new B2BCostCenterData();
    b2BCostCenterData.setOriginalCode(b2BCostCenterForm.getOriginalCode());
    b2BCostCenterData.setCode(b2BCostCenterForm.getCode());
    b2BCostCenterData.setName(b2BCostCenterForm.getName());
    final CurrencyData currencyData = new CurrencyData();
    currencyData.setIsocode(b2BCostCenterForm.getCurrency());
    b2BCostCenterData.setCurrency(currencyData);
    b2BCostCenterData.setUnit(
        companyB2BCommerceFacade.getUnitForUid(b2BCostCenterForm.getParentB2BUnit()));

    return b2BCostCenterData;
  }
  @Test
  public void testConvert() {
    final CurrencyModel currencyModel = mock(CurrencyModel.class);

    given(currencyModel.getName()).willReturn(ISOCODE);
    given(currencyModel.getIsocode()).willReturn(ISOCODE);
    given(currencyModel.getActive()).willReturn(Boolean.TRUE);
    given(currencyModel.getSymbol()).willReturn(ISOCODE);

    final CurrencyData currencyData = currencyConverter.convert(currencyModel);

    Assert.assertEquals(currencyModel.getIsocode(), currencyData.getIsocode());
    Assert.assertEquals(currencyModel.getActive(), Boolean.valueOf(currencyData.isActive()));
    Assert.assertEquals(currencyModel.getSymbol(), currencyData.getSymbol());
    Assert.assertEquals(currencyModel.getName(), currencyData.getName());
  }
  protected B2BBudgetData populateB2BBudgetDataFromForm(final B2BBudgetForm b2BBudgetForm)
      throws ParseException {
    final B2BBudgetData b2BBudgetData = new B2BBudgetData();
    b2BBudgetData.setOriginalCode(b2BBudgetForm.getOriginalCode());
    b2BBudgetData.setCode(b2BBudgetForm.getCode());
    b2BBudgetData.setName(b2BBudgetForm.getName());
    b2BBudgetData.setUnit(companyB2BCommerceFacade.getUnitForUid(b2BBudgetForm.getParentB2BUnit()));
    final CurrencyData currencyData = new CurrencyData();
    currencyData.setIsocode(b2BBudgetForm.getCurrency());
    b2BBudgetData.setCurrency(currencyData);
    b2BBudgetData.setStartDate(b2BBudgetForm.getStartDate());
    b2BBudgetData.setEndDate(b2BBudgetForm.getEndDate());
    b2BBudgetData.setBudget(
        BigDecimal.valueOf(
            formatFactory.createNumberFormat().parse(b2BBudgetForm.getBudget()).doubleValue()));

    return b2BBudgetData;
  }