Преглед изворни кода

Merge "Fix NLS to build under Java 5" into stable-0.7

tags/v0.7.0
Shawn O. Pearce пре 14 година
родитељ
комит
d42603578c

+ 7
- 7
org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestNLS.java Прегледај датотеку

public class TestNLS extends TestCase { public class TestNLS extends TestCase {


public void testNLSLocale() { public void testNLSLocale() {
NLS.setLocale(Locale.ROOT);
NLS.setLocale(NLS.ROOT_LOCALE);
GermanTranslatedBundle bundle = GermanTranslatedBundle.get(); GermanTranslatedBundle bundle = GermanTranslatedBundle.get();
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());


NLS.setLocale(Locale.GERMAN); NLS.setLocale(Locale.GERMAN);
bundle = GermanTranslatedBundle.get(); bundle = GermanTranslatedBundle.get();
} }


public void testJVMDefaultLocale() { public void testJVMDefaultLocale() {
Locale.setDefault(Locale.ROOT);
Locale.setDefault(NLS.ROOT_LOCALE);
NLS.useJVMDefaultLocale(); NLS.useJVMDefaultLocale();
GermanTranslatedBundle bundle = GermanTranslatedBundle.get(); GermanTranslatedBundle bundle = GermanTranslatedBundle.get();
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());


Locale.setDefault(Locale.GERMAN); Locale.setDefault(Locale.GERMAN);
NLS.useJVMDefaultLocale(); NLS.useJVMDefaultLocale();
} }
} }


NLS.setLocale(Locale.ROOT);
NLS.setLocale(NLS.ROOT_LOCALE);
GermanTranslatedBundle mainThreadsBundle = GermanTranslatedBundle.get(); GermanTranslatedBundle mainThreadsBundle = GermanTranslatedBundle.get();
T t = new T(); T t = new T();
t.start(); t.start();
} }
} }


T t1 = new T(Locale.ROOT);
T t1 = new T(NLS.ROOT_LOCALE);
T t2 = new T(Locale.GERMAN); T t2 = new T(Locale.GERMAN);
t1.start(); t1.start();
t2.start(); t2.start();


assertNull("t1 was interrupted or barrier was broken", t1.e); assertNull("t1 was interrupted or barrier was broken", t1.e);
assertNull("t2 was interrupted or barrier was broken", t2.e); assertNull("t2 was interrupted or barrier was broken", t2.e);
assertEquals(Locale.ROOT, t1.bundle.getEffectiveLocale());
assertEquals(NLS.ROOT_LOCALE, t1.bundle.getEffectiveLocale());
assertEquals(Locale.GERMAN, t2.bundle.getEffectiveLocale()); assertEquals(Locale.GERMAN, t2.bundle.getEffectiveLocale());
} }
} }

+ 10
- 10
org.eclipse.jgit.test/tst/org/eclipse/jgit/nls/TestTranslationBundle.java Прегледај датотеку



public void testMissingPropertiesFile() { public void testMissingPropertiesFile() {
try { try {
new NoPropertiesBundle().load(Locale.ROOT);
new NoPropertiesBundle().load(NLS.ROOT_LOCALE);
fail("Expected TranslationBundleLoadingException"); fail("Expected TranslationBundleLoadingException");
} catch (TranslationBundleLoadingException e) { } catch (TranslationBundleLoadingException e) {
assertEquals(NoPropertiesBundle.class, e.getBundleClass()); assertEquals(NoPropertiesBundle.class, e.getBundleClass());
assertEquals(Locale.ROOT, e.getLocale());
assertEquals(NLS.ROOT_LOCALE, e.getLocale());
// pass // pass
} }
} }


public void testMissingString() { public void testMissingString() {
try { try {
new MissingPropertyBundle().load(Locale.ROOT);
new MissingPropertyBundle().load(NLS.ROOT_LOCALE);
fail("Expected TranslationStringMissingException"); fail("Expected TranslationStringMissingException");
} catch (TranslationStringMissingException e) { } catch (TranslationStringMissingException e) {
assertEquals("nonTranslatedKey", e.getKey()); assertEquals("nonTranslatedKey", e.getKey());
assertEquals(MissingPropertyBundle.class, e.getBundleClass()); assertEquals(MissingPropertyBundle.class, e.getBundleClass());
assertEquals(Locale.ROOT, e.getLocale());
assertEquals(NLS.ROOT_LOCALE, e.getLocale());
// pass // pass
} }
} }
public void testNonTranslatedBundle() { public void testNonTranslatedBundle() {
NonTranslatedBundle bundle = new NonTranslatedBundle(); NonTranslatedBundle bundle = new NonTranslatedBundle();


bundle.load(Locale.ROOT);
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
bundle.load(NLS.ROOT_LOCALE);
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());
assertEquals("Good morning {0}", bundle.goodMorning); assertEquals("Good morning {0}", bundle.goodMorning);


bundle.load(Locale.ENGLISH); bundle.load(Locale.ENGLISH);
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());
assertEquals("Good morning {0}", bundle.goodMorning); assertEquals("Good morning {0}", bundle.goodMorning);


bundle.load(Locale.GERMAN); bundle.load(Locale.GERMAN);
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());
assertEquals("Good morning {0}", bundle.goodMorning); assertEquals("Good morning {0}", bundle.goodMorning);
} }


public void testGermanTranslation() { public void testGermanTranslation() {
GermanTranslatedBundle bundle = new GermanTranslatedBundle(); GermanTranslatedBundle bundle = new GermanTranslatedBundle();


bundle.load(Locale.ROOT);
assertEquals(Locale.ROOT, bundle.getEffectiveLocale());
bundle.load(NLS.ROOT_LOCALE);
assertEquals(NLS.ROOT_LOCALE, bundle.getEffectiveLocale());
assertEquals("Good morning {0}", bundle.goodMorning); assertEquals("Good morning {0}", bundle.goodMorning);


bundle.load(Locale.GERMAN); bundle.load(Locale.GERMAN);

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java Прегледај датотеку

* </pre> * </pre>
*/ */
public class NLS { public class NLS {
static final Locale ROOT_LOCALE = new Locale("", "", "");


private static final InheritableThreadLocal<NLS> local = new InheritableThreadLocal<NLS>() { private static final InheritableThreadLocal<NLS> local = new InheritableThreadLocal<NLS>() {
protected NLS initialValue() { protected NLS initialValue() {

Loading…
Откажи
Сачувај