I18nProvider { public String getMessage(MessageTag messageTag) { if (messageTag == null) { throw new IllegalArgumentException("messageTag cannot be null!"); } else if (keySet.contains(messageTag.getId())) { String patternString = bundle.getString(messageTag.getId()); return MessageFormat.format(patternString, getArgs(messageTag)); } else { LOG.warn("A value for the MessageTag [{}] not defined!", messageTag.getId()); return messageTag.getId(); } } I18nProvider();  I18nProvider(Locale locale); String getMessage(MessageTag messageTag);  }
@Test public void test() { Locale systemLocale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); final I18nProvider i18nProvider = new I18nProvider(Locale.ENGLISH); String message = i18nProvider.getMessage(MessageTag.BBB_XCV_CCCBB); assertNotNull(message); assertEquals("Can the certificate chain be built till a trust anchor?", message); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { i18nProvider.getMessage(null); }); assertEquals("messageTag cannot be null!", exception.getMessage()); final I18nProvider i18nFranceProvider = new I18nProvider(Locale.FRANCE); message = i18nFranceProvider.getMessage(MessageTag.BBB_XCV_CCCBB); assertNotNull(message); assertEquals("Peut-on remonter jusqu'\u00E0 une ancre de confiance ?", message); final I18nProvider i18nFrenchProvider = new I18nProvider(Locale.FRENCH); message = i18nFrenchProvider.getMessage(MessageTag.BBB_XCV_CCCBB); assertNotNull(message); assertEquals("Peut-on remonter jusqu'\u00E0 une ancre de confiance ?", message); final I18nProvider i18nGermanProvider = new I18nProvider(Locale.GERMAN); message = i18nGermanProvider.getMessage(MessageTag.BBB_XCV_CCCBB); assertNotNull(message); assertEquals("Can the certificate chain be built till a trust anchor?", message); } finally { Locale.setDefault(systemLocale); } }
@Test public void parametrizedTest() { Locale systemLocale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); String status = "granted"; MessageTag messageTag = MessageTag.TRUSTED_SERVICE_STATUS.setArgs(status); final I18nProvider i18nProvider = new I18nProvider(Locale.ENGLISH); String message = i18nProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Status : granted", message); final I18nProvider i18nFrenchProvider = new I18nProvider(Locale.FRENCH); message = i18nFrenchProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Statut : granted", message); final I18nProvider i18nGermanProvider = new I18nProvider(Locale.GERMAN); message = i18nGermanProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Status : granted", message); } finally { Locale.setDefault(systemLocale); } }
@Test public void nestedMessageTagTest() { Locale systemLocale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); MessageTag validationTime = MessageTag.VT_VALIDATION_TIME; MessageTag messageTag = MessageTag.CERT_QUALIFICATION_AT_TIME.setArgs(validationTime); final I18nProvider i18nProvider = new I18nProvider(Locale.ENGLISH); String message = i18nProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Certificate Qualification at validation time", message); final I18nProvider i18nFrenchProvider = new I18nProvider(Locale.FRENCH); message = i18nFrenchProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Qualification du certificat au moment de la validation", message); final I18nProvider i18nGermanProvider = new I18nProvider(Locale.GERMAN); message = i18nGermanProvider.getMessage(messageTag); assertNotNull(message); assertEquals("Certificate Qualification at validation time", message); } finally { Locale.setDefault(systemLocale); } }
@Test public void apostropheTest() { Locale systemLocale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); final I18nProvider i18nProvider = new I18nProvider(Locale.ENGLISH); MessageTag tstIntact = MessageTag.BBB_CV_ISIT; String message = i18nProvider.getMessage(tstIntact); assertNotNull(message); assertEquals("Is timestamp's signature intact?", message); MessageTag signedAttribute = MessageTag.BBB_ICS_ISASCP; message = i18nProvider.getMessage(signedAttribute); assertNotNull(message); assertEquals("Is the signed attribute: 'signing-certificate' present?", message); MessageTag signedQualifyingProperty = MessageTag.BBB_SAV_ISQPMDOSPP; message = i18nProvider.getMessage(signedQualifyingProperty); assertNotNull(message); assertEquals("Is the signed qualifying property: 'message-digest' or 'SignedProperties' present?", message); } finally { Locale.setDefault(systemLocale); } }