@Test
  public void annotationSettingsAreComposedWithInstalledModules() {
    final C10NConfigBase childConfig =
        new C10NConfigBase() {
          @Override
          public void configure() {
            bindAnnotation(Jp.class).toLocale(Locale.JAPANESE);
          }
        };

    C10NConfigBase config =
        new C10NConfigBase() {
          @Override
          public void configure() {
            install(childConfig);
            bindAnnotation(Eng.class).toLocale(Locale.ENGLISH);
          }
        };

    C10N.configure(config);
    Locale.setDefault(Locale.ENGLISH);
    assertThat(C10N.get(Messages.class).greeting(), is("hello"));
    Locale.setDefault(Locale.JAPANESE);
    assertThat(C10N.get(ChildMessages.class).greeting(), is("こんにちは"));
  }
Пример #2
0
 /**
  * See if it can cope with odd shaped rule table, including missing conditions. Also is not
  * "sequential".
  */
 @Test
 public void testComplexWorksheetMissingConditionsInLocaleEnUs() throws Exception {
   Locale originalDefaultLocale = Locale.getDefault();
   Locale.setDefault(Locale.US);
   doComplexWorksheetMissingConditions();
   Locale.setDefault(originalDefaultLocale);
 }
Пример #3
0
  /** @tests java.lang.String#compareToIgnoreCase(java.lang.String) */
  public void test_compareToIgnoreCaseLjava_lang_String() {
    // Test for method int
    // java.lang.String.compareToIgnoreCase(java.lang.String)
    assertTrue(
        "Returned incorrect value for first < second", "aaaaab".compareToIgnoreCase("aaaaac") < 0);
    assertEquals(
        "Returned incorrect value for first = second", 0, "aaaaac".compareToIgnoreCase("aaaaac"));
    assertTrue(
        "Returned incorrect value for first > second", "aaaaac".compareToIgnoreCase("aaaaab") > 0);
    assertEquals("Considered case to not be of importance", 0, "A".compareToIgnoreCase("a"));

    assertTrue("0xbf should not compare = to 'ss'", "\u00df".compareToIgnoreCase("ss") != 0);
    assertEquals("0x130 should compare = to 'i'", 0, "\u0130".compareToIgnoreCase("i"));
    assertEquals("0x131 should compare = to 'i'", 0, "\u0131".compareToIgnoreCase("i"));

    Locale defLocale = Locale.getDefault();
    try {
      Locale.setDefault(new Locale("tr", ""));
      assertEquals(
          "Locale tr: 0x130 should compare = to 'i'", 0, "\u0130".compareToIgnoreCase("i"));
      assertEquals(
          "Locale tr: 0x131 should compare = to 'i'", 0, "\u0131".compareToIgnoreCase("i"));
    } finally {
      Locale.setDefault(defLocale);
    }

    try {
      "fixture".compareToIgnoreCase(null);
      fail("No NPE");
    } catch (NullPointerException e) {
    }
  }
  /**
   * Tests the CellConstraints parser on valid encodings with a given locale.
   *
   * @param locale the Locale used while parsing the strings
   */
  private void testValidEncodings(Locale locale) {
    Locale oldDefault = Locale.getDefault();
    Locale.setDefault(locale);
    try {
      CellConstraints cc;
      cc = new CellConstraints();
      assertEquals(cc, new CellConstraints("1, 1"));

      cc = new CellConstraints(2, 3);
      assertEquals(cc, new CellConstraints("2, 3"));

      cc = new CellConstraints(3, 4, 2, 5);
      assertEquals(cc, new CellConstraints("3, 4, 2, 5"));

      cc = new CellConstraints(5, 6, CellConstraints.LEFT, CellConstraints.BOTTOM);
      assertEquals(cc, new CellConstraints("5, 6, l, b"));
      assertEquals(cc, new CellConstraints("5, 6, L, B"));
      assertEquals(cc, new CellConstraints("5, 6, left, bottom"));
      assertEquals(cc, new CellConstraints("5, 6, LEFT, BOTTOM"));

      cc = new CellConstraints(7, 8, 3, 2, CellConstraints.FILL, CellConstraints.DEFAULT);
      assertEquals(cc, new CellConstraints("7, 8, 3, 2, f, d"));
      assertEquals(cc, new CellConstraints("7, 8, 3, 2, F, D"));
      assertEquals(cc, new CellConstraints("7, 8, 3, 2, fill, default"));
      assertEquals(cc, new CellConstraints("7, 8, 3, 2, FILL, DEFAULT"));
    } finally {
      Locale.setDefault(oldDefault);
    }
  }
  public void testCheckOutCheckInWithAlteredWorkingCopyName() {
    // Check-out nodeRef using the locale fr_FR
    Locale.setDefault(Locale.FRANCE);
    NodeRef workingCopy =
        this.cociService.checkout(
            this.nodeRef,
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("workingCopy"));
    assertNotNull(workingCopy);

    // Check that the working copy name has been set correctly
    String workingCopyName = (String) nodeService.getProperty(workingCopy, PROP_NAME_QNAME);
    assertEquals(
        "Working copy name not correct", "myDocument (Copie de Travail).doc", workingCopyName);

    // Alter the working copy name
    nodeService.setProperty(workingCopy, PROP_NAME_QNAME, "newName (Copie de Travail).doc");

    // Check-in using the locale en_GB
    Locale.setDefault(Locale.UK);
    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
    versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version");
    cociService.checkin(workingCopy, versionProperties);

    String name = (String) nodeService.getProperty(nodeRef, PROP_NAME_QNAME);
    assertEquals("File not renamed correctly.", "newName.doc", name);
  }
Пример #6
0
  @Test
  public void testExcelSampleAggregatedWeekly() {
    // first day of week is locale dependent
    Locale locale = Locale.getDefault();
    Locale.setDefault(Locale.GERMAN);

    try {
      Client client = createClient();

      ReportingPeriod.FromXtoY reportInterval =
          new ReportingPeriod.FromXtoY( //
              LocalDate.of(2011, Month.DECEMBER, 31), LocalDate.of(2012, Month.JANUARY, 8));
      CurrencyConverter converter = new TestCurrencyConverter();
      PerformanceIndex index =
          PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());

      index = Aggregation.aggregate(index, Aggregation.Period.WEEKLY);

      assertNotNull(index);

      double[] delta = index.getDeltaPercentage();
      assertThat(delta.length, is(2));
      assertThat(delta[0], IsCloseTo.closeTo(0.023d, PRECISION));
      assertThat(delta[1], IsCloseTo.closeTo(-0.0713587d, PRECISION));

      double[] accumulated = index.getAccumulatedPercentage();
      assertThat(accumulated[0], IsCloseTo.closeTo(0.023d, PRECISION));
      assertThat(accumulated[1], IsCloseTo.closeTo(-0.05d, PRECISION));
    } finally {
      Locale.setDefault(locale);
    }
  }
  @Test
  public void testPdfRenderer() throws IOException {

    Locale locale = Locale.getDefault();
    try {
      Locale.setDefault(new Locale.Builder().setLanguage("en").setRegion("US").build());

      this.rm.render(
          this.outputDir,
          this.alr.getApplicationTemplate(),
          this.applicationDirectory,
          Renderer.PDF,
          null,
          null);
      File pdffile = new File(this.outputDir, "index.pdf");
      Assert.assertTrue(pdffile.exists());
      Assert.assertTrue(pdffile.length() > 0);

      PDF genPdf = new PDF(pdffile);
      Assert.assertThat(genPdf, containsText("Legacy LAMP"));
      Assert.assertThat(
          genPdf,
          containsText("This document lists the Software components used in this application"));

    } finally {
      Locale.setDefault(locale);
    }
  }
Пример #8
0
 private void changeLanguage() {
   String lang = getLang();
   if (lang.equals("EN")) {
     Locale locale = new Locale("ru");
     Locale.setDefault(locale);
     Configuration config = new Configuration();
     config.locale = locale;
     getBaseContext()
         .getResources()
         .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
     invalidateOptionsMenu();
     loadActivity();
     setLang("RU");
   } else {
     if (lang.equals("RU")) {
       Locale locale = new Locale("en");
       Locale.setDefault(locale);
       Configuration config = new Configuration();
       config.locale = locale;
       getBaseContext()
           .getResources()
           .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
       invalidateOptionsMenu();
       loadActivity();
       setLang("EN");
     }
   }
 }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getFirstDayOfWeek",
        args = {}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getInstance",
        args = {})
  })
  public void test_getFirstDayOfWeek() {
    Locale[] requiredLocales = {Locale.US, Locale.FRANCE};
    if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
      // locale dependent test, bug 1943269
      return;
    }
    Calendar cal = Calendar.getInstance();

    assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek());
    Locale.setDefault(Locale.FRANCE);
    cal = Calendar.getInstance();
    assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek());
    Locale.setDefault(Locale.US);
  }
Пример #10
0
  /*
   * @bug 4101316
   * @bug 4084688 (This bug appears to be a duplicate of something, because it was fixed
   *              between 1.1.5 and 1.1.6, but I included a new test for it anyway)
   * @bug 4052440 Stop falling back to the default locale.
   */
  public void TestDisplayNames() {
    Locale saveDefault = Locale.getDefault();
    Locale english = new Locale("en", "US");
    Locale french = new Locale("fr", "FR");
    Locale croatian = new Locale("hr", "HR");
    Locale greek = new Locale("el", "GR");

    Locale.setDefault(english);
    logln("With default = en_US...");
    logln("  In default locale...");
    doTestDisplayNames(null, DLANG_EN, false);
    logln("  In locale = en_US...");
    doTestDisplayNames(english, DLANG_EN, false);
    logln("  In locale = fr_FR...");
    doTestDisplayNames(french, DLANG_FR, false);
    logln("  In locale = hr_HR...");
    doTestDisplayNames(croatian, DLANG_HR, false);
    logln("  In locale = el_GR...");
    doTestDisplayNames(greek, DLANG_EL, false);

    Locale.setDefault(french);
    logln("With default = fr_FR...");
    logln("  In default locale...");
    doTestDisplayNames(null, DLANG_FR, true);
    logln("  In locale = en_US...");
    doTestDisplayNames(english, DLANG_EN, true);
    logln("  In locale = fr_FR...");
    doTestDisplayNames(french, DLANG_FR, true);
    logln("  In locale = hr_HR...");
    doTestDisplayNames(croatian, DLANG_HR, true);
    logln("  In locale = el_GR...");
    doTestDisplayNames(greek, DLANG_EL, true);

    Locale.setDefault(saveDefault);
  }
Пример #11
0
  /**
   * Produces a java map that maps a {@link Country} to it's ISO 3166 country code.<br>
   * Each map entry consists of:<br>
   *
   * <table border=1>
   * <tr>
   * <td>key:</td>
   * <td>ISO 3166 country code</td>
   * </tr>
   * <tr>
   * <td>value:</td>
   * <td>the corresponding country as {@link Country}-instance</td>
   * </table>
   *
   * @return
   */
  public static Map<String, Country> createCountryMap() {
    // ISO3166-ALPHA-2 codes
    String[] countryCodes = Locale.getISOCountries();

    // Key = CountryCode
    // Value = Country
    Map<String, Country> countries = new HashMap<String, Country>(countryCodes.length);

    for (String cc : countryCodes) {

      Locale.setDefault(Locale.US);
      String countryNameEnglish = new Locale(Locale.US.getLanguage(), cc).getDisplayCountry();

      Locale.setDefault(Locale.GERMANY);
      String countryNameGerman = new Locale(Locale.GERMANY.getLanguage(), cc).getDisplayCountry();

      Country country = new Country(cc.toUpperCase(), countryNameEnglish, countryNameGerman);

      countries.put(cc, country);
    }

    if (logger.isInfoEnabled()) {
      logger.info(
          "Created a country-iso3166Code Map<String, Country> with {} entries.", countries.size());
    }

    return countries;
  }
Пример #12
0
  private static void testGetFallbackLocale() {
    Locale current = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    try {
      Locale loc = CONTROL.getFallbackLocale("any", Locale.FRANCE);
      if (loc != Locale.ITALY) {
        error("getFallbackLocale: got %s, expected %s%n", toString(loc), toString(Locale.ITALY));
      }
      loc = CONTROL.getFallbackLocale("any", Locale.ITALY);
      if (loc != null) {
        error("getFallbackLocale: got %s, expected null%n", toString(loc));
      }
    } finally {
      Locale.setDefault(current);
    }

    final int NARGS = 2;
    for (int mask = 0; mask < (1 << NARGS) - 1; mask++) {
      Object[] data = getNpeArgs(NARGS, mask);
      try {
        Locale loc = CONTROL.getFallbackLocale((String) data[0], (Locale) data[1]);
        error("getFallbackLocale(%s, %s) doesn't throw NPE.%n", data[0], data[1]);
      } catch (NullPointerException e) {
      }
    }
  }
  @Test
  public void shouldUseGivenDistanceUnits() throws Exception {
    Locale.setDefault(Locale.GERMANY);
    assertThat(format(1000, false, Router.DistanceUnits.MILES)).isEqualTo("0,6 mi");

    Locale.setDefault(Locale.US);
    assertThat(format(1000, false, Router.DistanceUnits.KILOMETERS)).isEqualTo("1 km");
  }
Пример #14
0
 public void testConvertDbToUserFmt() throws InvalidDateException {
   Locale.setDefault(new Locale("en", "GB"));
   DateUtils.convertDbToUserFmt("2009-01-26", "dd/MM/yyyy");
   Locale.setDefault(new Locale("fr", "FR"));
   DateUtils.convertDbToUserFmt("2009-01-26", "dd/MM/yyyy");
   Locale.setDefault(new Locale("ar", "LB"));
   DateUtils.convertDbToUserFmt("2009-01-26", "dd/MM/yyyy");
 }
  @Test
  public void shouldUseGivenLocale() throws Exception {
    Locale.setDefault(Locale.GERMANY);
    assertThat(format(1000, false, Locale.US)).isEqualTo("0.6 mi");

    Locale.setDefault(Locale.US);
    assertThat(format(1000, false, Locale.GERMANY)).isEqualTo("1 km");
  }
Пример #16
0
 /** Test that dotted lower I + "nfo" is recognized as INFO even in Turkish locale. */
 @Test
 public void testDottedLowerI() {
   final Locale defaultLocale = Locale.getDefault();
   final Locale turkey = new Locale("tr", "TR");
   Locale.setDefault(turkey);
   final Level level = Level.toLevel("info");
   Locale.setDefault(defaultLocale);
   assertEquals("INFO", level.toString());
 }
Пример #17
0
 @Test
 @Ignore // TODO JBRULES-2880 TIRELLI: Ignore test while we decide what to do in order to solve
 // i18n issues
 public void testComplexWorksheetMissingConditionsInLocaleFrFr() throws Exception {
   Locale originalDefaultLocale = Locale.getDefault();
   Locale.setDefault(Locale.FRANCE);
   doComplexWorksheetMissingConditions();
   Locale.setDefault(originalDefaultLocale);
 }
Пример #18
0
 /** Some checks for the getFirstMillisecond() method. */
 public void testGetFirstMillisecond() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.UK);
   TimeZone savedZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
   Second s = new Second(15, 43, 15, 1, 4, 2006);
   assertEquals(1143902595000L, s.getFirstMillisecond());
   Locale.setDefault(saved);
   TimeZone.setDefault(savedZone);
 }
Пример #19
0
  protected static <T extends LocalFeature<?, ?>> void writeASCII(
      PrintWriter out, LocalFeatureList<T> list) throws IOException {
    final Locale def = Locale.getDefault();
    Locale.setDefault(Locale.ENGLISH);

    out.println(list.size() + " " + list.vecLength());
    for (final T k : list) k.writeASCII(out);

    Locale.setDefault(def);
  }
Пример #20
0
 /** Some checks for the getEnd() method. */
 public void testGetEnd() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.ITALY);
   Calendar cal = Calendar.getInstance(Locale.ITALY);
   cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55);
   cal.set(Calendar.MILLISECOND, 999);
   Second s = new Second(55, 47, 3, 16, 1, 2006);
   assertEquals(cal.getTime(), s.getEnd());
   Locale.setDefault(saved);
 }
  private void checkPropertiesFile(Locale locale, String prefix) {
    Locale oldLocale = Locale.getDefault();
    try {
      Locale.setDefault(locale);

      ResourceBundle.getBundle(prefix, locale, new EncodingControl(StandardCharsets.UTF_8));
    } finally {
      Locale.setDefault(oldLocale);
    }
  }
Пример #22
0
 /** Some checks for the getLastMillisecond() method. */
 public void testGetLastMillisecond() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.UK);
   TimeZone savedZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
   Second s = new Second(1, 1, 1, 1, 1, 1970);
   assertEquals(61999L, s.getLastMillisecond());
   Locale.setDefault(saved);
   TimeZone.setDefault(savedZone);
 }
Пример #23
0
  public void testJVMDefaultLocale() {
    Locale.setDefault(NLS.ROOT_LOCALE);
    NLS.useJVMDefaultLocale();
    GermanTranslatedBundle bundle = GermanTranslatedBundle.get();
    assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());

    Locale.setDefault(Locale.GERMAN);
    NLS.useJVMDefaultLocale();
    bundle = GermanTranslatedBundle.get();
    assertEquals(Locale.GERMAN, bundle.getEffectiveLocale());
  }
Пример #24
0
 /** Some checks for the getLastMillisecond() method. */
 @Test
 public void testGetLastMillisecond() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.UK);
   TimeZone savedZone = TimeZone.getDefault();
   TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
   Millisecond m = new Millisecond(750, 1, 1, 1, 1, 1, 1970);
   assertEquals(61750L, m.getLastMillisecond());
   Locale.setDefault(saved);
   TimeZone.setDefault(savedZone);
 }
Пример #25
0
 /** Some checks for the getStart() method. */
 @Test
 public void testGetStart() {
   Locale saved = Locale.getDefault();
   Locale.setDefault(Locale.ITALY);
   Calendar cal = Calendar.getInstance(Locale.ITALY);
   cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55);
   cal.set(Calendar.MILLISECOND, 555);
   Millisecond m = new Millisecond(555, 55, 47, 3, 16, 1, 2006);
   assertEquals(cal.getTime(), m.getStart());
   Locale.setDefault(saved);
 }
 @Test
 public void testMixedCaseSpacesWithDifferentLocales() {
   Locale[] differentLocales = new Locale[] {new Locale("TR", "tr")};
   Locale defaultLocale = Locale.getDefault();
   try {
     for (Locale differentLocale : differentLocales) {
       Locale.setDefault(differentLocale);
       testMixedCaseSpaces();
     }
   } finally {
     Locale.setDefault(defaultLocale);
   }
 }
  void test2() {
    Locale defaultLocale = Locale.getDefault();
    TimeZone reservedTimeZone = TimeZone.getDefault();
    Date d = new Date(2005 - 1900, Calendar.DECEMBER, 22);
    String formatted;

    TimeZone tz;
    SimpleDateFormat df;

    try {
      for (int i = 0; i < TIMEZONES.length; i++) {
        tz = TimeZone.getTimeZone(TIMEZONES[i]);
        TimeZone.setDefault(tz);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(OSAKA));
        Locale.setDefault(defaultLocale);
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_OSAKA[i])) {
          throw new RuntimeException(
              "TimeZone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_OSAKA[i]);
        }

        df.parse(DISPLAY_NAMES_OSAKA[i]);

        Locale.setDefault(KYOTO);
        df = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance());
        System.out.println(formatted = df.format(d));
        if (!formatted.equals(DISPLAY_NAMES_KYOTO[i])) {
          throw new RuntimeException(
              "Timezone "
                  + TIMEZONES[i]
                  + ": formatted zone names mismatch. "
                  + formatted
                  + " should match with "
                  + DISPLAY_NAMES_KYOTO[i]);
        }
        df.parse(DISPLAY_NAMES_KYOTO[i]);
      }
    } catch (ParseException pe) {
      throw new RuntimeException("parse error occured" + pe);
    } finally {
      // restore the reserved locale and time zone
      Locale.setDefault(defaultLocale);
      TimeZone.setDefault(reservedTimeZone);
    }
  }
Пример #28
0
  @Test
  public void findFakePath() {

    Locale defaultLocale = Locale.getDefault();

    Locale.setDefault(new Locale("ZZ"));

    String path = ClassPathUtils.getLocalizedPath("/jgnash/resource/account");

    System.out.println(path);

    Locale.setDefault(defaultLocale);

    assertNotNull("failed test", path);
  }
 @Test
 public void defaultLocale() {
   Locale originalDefaultLocale = Locale.getDefault();
   try {
     Locale newDefaultLocale =
         originalDefaultLocale.equals(Locale.GERMANY) ? Locale.FRANCE : Locale.GERMANY;
     Locale.setDefault(newDefaultLocale);
     // Create the request after changing the default locale.
     MockHttpServletRequest request = new MockHttpServletRequest();
     assertFalse(newDefaultLocale.equals(request.getLocale()));
     assertEquals(Locale.ENGLISH, request.getLocale());
   } finally {
     Locale.setDefault(originalDefaultLocale);
   }
 }
Пример #30
0
  /*
  Défini l'action a réaliser lorsqu'on clique sur un des boutons du menu
   */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    Configuration config;
    switch (item.getItemId()) {
      case R.id.action_english:
        mLocale = new Locale(LOCALE_ENGLISH);
        Locale.setDefault(mLocale);
        config = new Configuration();
        config.locale = mLocale;
        getBaseContext()
            .getResources()
            .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        if (User.getConnectedUser().getStatus().compareTo("client") == 0
            || User.getConnectedUser().getStatus().compareTo("user") == 0) {
          setContentView(R.layout.activity_main);
        } else {
          Barman b = new Barman(User.getConnectedUser().getId());
          if (!b.Is_manager()) {
            setContentView(R.layout.activity_main_barman);
          } else {
            setContentView(R.layout.activity_main_manager);
          }
        }
        return true;

      case R.id.action_french:
        mLocale = new Locale(LOCALE_FRANCAIS);
        Locale.setDefault(mLocale);
        config = new Configuration();
        config.locale = mLocale;
        getBaseContext()
            .getResources()
            .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        if (User.getConnectedUser().getStatus().compareTo("client") == 0
            || User.getConnectedUser().getStatus().compareTo("user") == 0) {
          setContentView(R.layout.activity_main);
        } else {
          Barman b = new Barman(User.getConnectedUser().getId());
          if (!b.Is_manager()) {
            setContentView(R.layout.activity_main_barman);
          } else {
            setContentView(R.layout.activity_main_manager);
          }
        }
        return true;
    }
    return false;
  }