@Test
  public void twoCountriesWithDifferentGisFeatureShouldNotBeEqual() {
    Country country1 =
        Country.countryName("France")
            .withIsoCountryCode(franceCountryCode())
            .withContinent(europe())
            .andGisFeature(franceGisFeature())
            .withCurrency(Currency.getInstance("EUR"))
            .withFipsCountryCode(franceFipsCountryCode())
            .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
            .withGeographicCountryInformation(franceGeographicCountryInformation());

    Country country2 =
        Country.countryName("France")
            .withIsoCountryCode(franceCountryCode())
            .withContinent(europe())
            .andGisFeature(antarcticaGisFeature()) // different feature
            .withCurrency(Currency.getInstance("EUR"))
            .withFipsCountryCode(franceFipsCountryCode())
            .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
            .withGeographicCountryInformation(franceGeographicCountryInformation());

    Assert.assertFalse(country1.equals(country2));
    Assert.assertTrue(country1.hashCode() != country2.hashCode());
  }
  @Test
  public void twoCountriesWithSameGisFeatureShouldBeEqual() {
    Country country1 =
        Country.countryName("France")
            .withIsoCountryCode(franceCountryCode())
            .withContinent(europe())
            .andGisFeature(franceGisFeature())
            .withCurrency(Currency.getInstance("EUR"))
            .withFipsCountryCode(franceFipsCountryCode())
            .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
            .withGeographicCountryInformation(franceGeographicCountryInformation());

    Country country2 =
        Country.countryName("Antarctica")
            .withIsoCountryCode(antarcticaCountryCode())
            .withContinent(antarcticaContinent())
            .andGisFeature(franceGisFeature()) // france gis feature
            .withCurrency(null)
            .withFipsCountryCode(antarcticaFipsCountryCode())
            .withAdministrativeCountryInformation(antarcticaAdministrativeCountryInformation())
            .withGeographicCountryInformation(antarcticaGeographicCountryInformation());

    Assert.assertEquals(country1, country2);
    Assert.assertEquals(country1.hashCode(), country2.hashCode());
  }
 private Country createFranceWithMockGisFeatureProvider(GisFeatureProvider gisFeatureProvider) {
   return Country.countryName("France")
       .withIsoCountryCode(franceCountryCode())
       .withContinent(europe())
       .andGisFeatureProvider(gisFeatureProvider)
       .withCurrency(Currency.getInstance("EUR"))
       .withFipsCountryCode(franceFipsCountryCode())
       .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
       .withGeographicCountryInformation(franceGeographicCountryInformation());
 }
 @Test(expected = IllegalArgumentException.class)
 public void shouldNotCreateCountryWhenContinentIsNull() {
   Country.countryName("France")
       .withIsoCountryCode(franceCountryCode())
       .withContinent(null)
       .andGisFeature(franceGisFeature())
       .withCurrency(Currency.getInstance("EUR"))
       .withFipsCountryCode(franceFipsCountryCode())
       .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
       .withGeographicCountryInformation(franceGeographicCountryInformation());
 }
 private void assertFrance(Country france) {
   assertEquals("France", france.getName());
   assertEquals(franceCountryCode(), france.getIsoCountryCode());
   assertEquals(europe(), france.getContinent());
   assertEquals(franceGisFeature(), france.getGisFeature());
   assertEquals(Currency.getInstance("EUR"), france.getCurrency());
   assertEquals(franceFipsCountryCode(), france.getFipsCountryCode());
   assertEquals(
       franceAdministrativeCountryInformation(), france.getAdministrativeCountryInformation());
   assertEquals(franceGeographicCountryInformation(), france.getGeographicCountryInformation());
 }
 @Test
 public void shouldCreateFranceUsingGisFeatureProvider() {
   Country france =
       Country.countryName("France")
           .withIsoCountryCode(franceCountryCode())
           .withContinent(europe())
           .andGisFeatureProvider(new InMemoryGeonamesGisFeatureProvider(franceGisFeature()))
           .withCurrency(Currency.getInstance("EUR"))
           .withFipsCountryCode(franceFipsCountryCode())
           .withAdministrativeCountryInformation(franceAdministrativeCountryInformation())
           .withGeographicCountryInformation(franceGeographicCountryInformation());
   assertFrance(france);
 }
Example #7
0
  public LocaleValueProvider() {
    Builder<String, Object> builder = ImmutableMap.builder();

    AuraLocale al = Aura.getLocalizationAdapter().getAuraLocale();

    Locale userLocale = al.getLocale();
    Locale lang = al.getLanguageLocale();
    Locale dateLocale = al.getDateLocale();

    builder.put(USER_LOCALE_LANGUAGE, userLocale.getLanguage());
    builder.put(USER_LOCALE_COUNTRY, userLocale.getCountry());
    builder.put(LANGUAGE, lang.getLanguage());
    builder.put(COUNTRY, lang.getCountry());
    builder.put(VARIANT, lang.getVariant());
    builder.put(LANGUAGE_LOCALE, lang.toString());

    try {
      builder.put(MONTH_NAME, this.getNameOfMonths(al));
      builder.put(WEEKDAY_NAME, this.getNameOfWeekdays(al));
      builder.put(TODAY_LABEL, this.getLabelForToday());
    } catch (QuickFixException qfe) {
      // Ignore
    }

    builder.put(
        FIRST_DAY_OF_WEEK, Calendar.getInstance(al.getTimeZone(), userLocale).getFirstDayOfWeek());

    // using java DateFormat because the year pattern "MMM d, y" (although valid) isn't understood
    // by moment.js
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, dateLocale);
    DateFormat datetimeFormat =
        DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, dateLocale);
    DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.DEFAULT, dateLocale);
    try {
      SimpleDateFormat sdf = (SimpleDateFormat) dateFormat;
      builder.put(DATE_FORMAT, sdf.toPattern());

      SimpleDateFormat sdtf = (SimpleDateFormat) datetimeFormat;
      builder.put(DATETIME_FORMAT, sdtf.toPattern());

      SimpleDateFormat stf = (SimpleDateFormat) timeFormat;
      builder.put(TIME_FORMAT, stf.toPattern());
    } catch (ClassCastException cce) {
      builder.put(DATE_FORMAT, DEFAULT_DATE_FORMAT);
      builder.put(DATETIME_FORMAT, DEFAULT_DATETIME_FORMAT);
      builder.put(TIME_FORMAT, DEFAULT_TIME_FORMAT);
    }

    String timezoneId = al.getTimeZone().getID();
    String availableTimezoneId = Aura.getConfigAdapter().getAvailableTimezone(timezoneId);
    builder.put(TIME_ZONE, availableTimezoneId);
    builder.put(TIME_ZONE_FILE_NAME, availableTimezoneId.replace("/", "-"));

    builder.put(IS_EASTERN_NAME_STYLE, al.isEasternNameStyle());

    // DecimalFormat is expected
    DecimalFormat df = (DecimalFormat) DecimalFormat.getNumberInstance(al.getNumberLocale());

    // Patterns are not localized; the "." means "locale decimal" not "dot"
    builder.put(NUMBER_FORMAT, df.toPattern());
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
    builder.put(DECIMAL, dfs.getDecimalSeparator());
    builder.put(GROUPING, dfs.getGroupingSeparator());
    builder.put(ZERO_DIGIT, dfs.getZeroDigit());

    df = (DecimalFormat) DecimalFormat.getPercentInstance(al.getNumberLocale());

    // Don't localize the patterns
    builder.put(PERCENT_FORMAT, df.toPattern());

    df = (DecimalFormat) DecimalFormat.getCurrencyInstance(al.getCurrencyLocale());

    // Don't localize the patterns
    builder.put(CURRENCY_FORMAT, df.toPattern());
    DecimalFormatSymbols cdfs = df.getDecimalFormatSymbols();
    Currency cur = cdfs.getCurrency();
    builder.put(CURRENCY_CODE, cur != null ? cur.getCurrencyCode() : "");
    builder.put(CURRENCY, cdfs.getCurrencySymbol());

    data = builder.build();
  }