/** * @return The problem encountered while localizing this internationalization object to the default locale, or * <code>null</code> if none was encountered. */ public String problem() { return problem(null); }
/** * @return The problem encountered while localizing this internationalization object to the default locale, or * <code>null</code> if none was encountered. */ public String problem() { return problem(null); }
/** * @return The problem encountered while localizing this internationalization object to the default locale, or * <code>null</code> if none was encountered. */ public String problem() { return problem(null); }
/** * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the default * locale. */ public boolean hasProblem() { return (problem() != null); }
/** * @param locale The locale for which to check whether a problem was encountered. * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the supplied * locale. */ public boolean hasProblem( Locale locale ) { return (problem(locale) != null); }
/** * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the default * locale. */ public boolean hasProblem() { return (problem() != null); }
/** * @param locale The locale for which to check whether a problem was encountered. * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the supplied * locale. */ public boolean hasProblem( Locale locale ) { return (problem(locale) != null); }
/** * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the default * locale. */ public boolean hasProblem() { return (problem() != null); }
/** * @param locale The locale for which to check whether a problem was encountered. * @return <code>true</code> if a problem was encountered while localizing this internationalization object to the supplied * locale. */ public boolean hasProblem( Locale locale ) { return (problem(locale) != null); }
private String rawText( Locale locale ) { assert locale != null; localize(i18nClass, locale); // Check if text exists String text = localeToTextMap.get(locale); if (text != null) { return text; } // If not, there was a problem, so throw it within an exception so upstream callers can tell the difference between normal // text and problem text. throw new SystemFailureException(problem(locale)); }
private String rawText( Locale locale ) { assert locale != null; localize(i18nClass, locale); // Check if text exists String text = localeToTextMap.get(locale); if (text != null) { return text; } // If not, there was a problem, so throw it within an exception so upstream callers can tell the difference between normal // text and problem text. throw new SystemFailureException(problem(locale)); }
private String rawText( Locale locale ) { assert locale != null; localize(i18nClass, locale); // Check if text exists String text = localeToTextMap.get(locale); if (text != null) { return text; } // If not, there was a problem, so throw it within an exception so upstream callers can tell the difference between normal // text and problem text. throw new SystemFailureException(problem(locale)); }
@Test public void shouldBeLocalizedIfAskedForProblem() { I18n.initialize(TestI18nDuplicateProperty.class); TestI18nDuplicateProperty.testMessage.problem(); assertThat(TestI18nDuplicateProperty.testMessage.localeToTextMap.get(Locale.getDefault()), notNullValue()); assertThat(TestI18nDuplicateProperty.testMessage.localeToProblemMap.get(Locale.getDefault()), notNullValue()); }
@Test public void shouldHaveProblemIfMissingLocalization() { I18n.initialize(TestI18nMissingLocalization.class); assertThat(TestI18nMissingLocalization.testMessage.hasProblem(), is(true)); String problem = TestI18nMissingLocalization.testMessage.problem(); assertThat(problem, is(CommonI18n.i18nLocalizationProblems.text(TestI18nMissingLocalization.class, Locale.getDefault()))); System.out.println("Problem: " + problem); }
@Test public void shouldNotHaveProblems() throws Exception { for (Field fld : i18nClass.getDeclaredFields()) { if (fld.getType() == I18n.class && (fld.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC && (fld.getModifiers() & Modifier.STATIC) == Modifier.STATIC && (fld.getModifiers() & Modifier.FINAL) != Modifier.FINAL) { I18n i18n = (I18n)fld.get(null); if (i18n.hasProblem()) { fail(i18n.problem()); } } } // Check for global problems after checking field problems since global problems are detected lazily upon field usage Set<Locale> locales = I18n.getLocalizationProblemLocales(i18nClass); if (!locales.isEmpty()) { for (Locale locale : locales) { Set<String> problems = I18n.getLocalizationProblems(i18nClass, locale); try { assertThat(problems.isEmpty(), is(true)); } catch (AssertionError error) { fail(problems.iterator().next()); } } } }
@Test public void shouldHaveProblemIfPropertyDuplicate() { I18n.initialize(TestI18nDuplicateProperty.class); assertThat(TestI18nDuplicateProperty.testMessage.hasProblem(), is(true)); String problem = TestI18nDuplicateProperty.testMessage.problem(); assertThat(problem, notNullValue()); System.out.println("Problem: " + problem); }
@Test public void shouldHaveProblemIfPropertyMissing() { I18n.initialize(TestI18nMissingProperty.class); assertThat(TestI18nMissingProperty.testMessage1.hasProblem(), is(true)); String problem = TestI18nMissingProperty.testMessage1.problem(); assertThat(problem, notNullValue()); System.out.println("Problem: " + problem); }
I18n i18n = (I18n)fld.get(null); if (i18n.hasProblem()) { fail(i18n.problem());