コード例 #1
0
  @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());
  }
コード例 #2
0
 @Test(expected = ConversionException.class)
 public void testPopulateLanguageUnknownIdent() {
   final CustomerData customerData = mock(CustomerData.class);
   final CustomerModel customerModel = new CustomerModel();
   final LanguageData languageData = mock(LanguageData.class);
   given(customerData.getLanguage()).willReturn(languageData);
   given(languageData.getIsocode()).willReturn("languageIso");
   given(commonI18NService.getLanguage("languageIso"))
       .willThrow(new UnknownIdentifierException(""));
   customerReversePopulator.populate(customerData, customerModel);
 }