ComponentUtil { public static ResourceBundle getCurrentResourceBundle(String locale) { try { if (null != locale && !locale.isEmpty()) { return getCurrentResourceBundle(LocaleUtils.toLocale(locale)); } } catch (IllegalArgumentException ex) { } return getCurrentResourceBundle((Locale) null); } private  ComponentUtil(); static ResourceBundle getCurrentResourceBundle(String locale); static ResourceBundle getCurrentResourceBundle(Locale locale);  }
@Test public void testGetResourceBundleEn() throws Exception { String locale = "en"; ResourceBundle resourceBundle = ComponentUtil.getCurrentResourceBundle(locale); Assert.assertEquals(locale.toLowerCase(), resourceBundle.getLocale().toString().toLowerCase()); }
@Test public void testGetResourceBundleNl() throws Exception { String locale = "nl"; ResourceBundle resourceBundle = ComponentUtil.getCurrentResourceBundle(locale); Assert.assertEquals(locale.toLowerCase(), resourceBundle.getLocale().toString().toLowerCase()); }
@Test public void testGetResourceBundleFallbackOnLanguage() throws Exception { String locale = "en_GB"; ResourceBundle resourceBundle = ComponentUtil.getCurrentResourceBundle(locale); Assert.assertEquals("en", resourceBundle.getLocale().toString().toLowerCase()); }
@Test public void testGetResourceBundleEnUs() throws Exception { String locale = "en_US"; ResourceBundle resourceBundle = ComponentUtil.getCurrentResourceBundle(locale); Assert.assertEquals(locale.toLowerCase(), resourceBundle.getLocale().toString().toLowerCase()); }
@Test public void testGetResourceBundleUnknown() throws Exception { String locale = "xyz"; String[] defaultLocaleArray = new String[] {"en", "nl"}; for (String defaultLocale : defaultLocaleArray) { Locale.setDefault(LocaleUtils.toLocale(defaultLocale)); ResourceBundle resourceBundle = ComponentUtil.getCurrentResourceBundle(locale); Assert.assertEquals(defaultLocale.toLowerCase(), resourceBundle.getLocale().toString().toLowerCase()); } }