You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.nls;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.fail;
  13. import java.util.Locale;
  14. import org.eclipse.jgit.errors.TranslationBundleLoadingException;
  15. import org.eclipse.jgit.errors.TranslationStringMissingException;
  16. import org.junit.Test;
  17. public class TranslationBundleTest {
  18. @Test
  19. public void testMissingPropertiesFile() {
  20. try {
  21. new NoPropertiesBundle().load(NLS.ROOT_LOCALE);
  22. fail("Expected TranslationBundleLoadingException");
  23. } catch (TranslationBundleLoadingException e) {
  24. assertEquals(NoPropertiesBundle.class, e.getBundleClass());
  25. assertEquals(NLS.ROOT_LOCALE, e.getLocale());
  26. // pass
  27. }
  28. }
  29. @Test
  30. public void testMissingString() {
  31. try {
  32. new MissingPropertyBundle().load(NLS.ROOT_LOCALE);
  33. fail("Expected TranslationStringMissingException");
  34. } catch (TranslationStringMissingException e) {
  35. assertEquals("nonTranslatedKey", e.getKey());
  36. assertEquals(MissingPropertyBundle.class, e.getBundleClass());
  37. assertEquals(NLS.ROOT_LOCALE, e.getLocale());
  38. // pass
  39. }
  40. }
  41. @Test
  42. public void testNonTranslatedBundle() {
  43. NonTranslatedBundle bundle = new NonTranslatedBundle();
  44. bundle.load(NLS.ROOT_LOCALE);
  45. assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
  46. assertEquals("Good morning {0}", bundle.goodMorning);
  47. bundle.load(Locale.ENGLISH);
  48. assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
  49. assertEquals("Good morning {0}", bundle.goodMorning);
  50. bundle.load(Locale.GERMAN);
  51. assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
  52. assertEquals("Good morning {0}", bundle.goodMorning);
  53. }
  54. @Test
  55. public void testGermanTranslation() {
  56. GermanTranslatedBundle bundle = new GermanTranslatedBundle();
  57. bundle.load(NLS.ROOT_LOCALE);
  58. assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
  59. assertEquals("Good morning {0}", bundle.goodMorning);
  60. bundle.load(Locale.GERMAN);
  61. assertEquals(Locale.GERMAN, bundle.effectiveLocale());
  62. assertEquals("Guten Morgen {0}", bundle.goodMorning);
  63. }
  64. }