LocalizableFactory { @SuppressWarnings("PMD.UseProperClassLoader") public static Localizable getLocalizable(Object object) { final Logger logger = LoggerFactory.getLogger(MapLoader.class); Class<?> clazz = object.getClass(); Localizable loc; if(object instanceof Localizable) { loc = (Localizable) object; if(logger.isDebugEnabled()) logger.debug("Casting to Localizable."); } else { loc = (Localizable) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[]{Localizable.class}, new LocalizableInvocationHandler(object)); if(logger.isDebugEnabled()) logger.debug("Created Localizable proxy."); } return loc; } private  LocalizableFactory(); @SuppressWarnings("PMD.UseProperClassLoader") static Localizable getLocalizable(Object object);  }
@Test public void getLocalizable() throws Exception { Locale locale = new Locale("de_DE"); Localizable loc; Locale l; Object o; o = new Foobar(); loc = internalGetLocalizable(o, false); loc.setLocale(locale); l = loc.getLocale(); assertEquals(locale, l); o = ((Foobar) o).new Internal(); loc = internalGetLocalizable(o, true); loc.setLocale(null); l = loc.getLocale(); assertEquals(locale, l); o = new Foobar.StaticInternal(); loc = internalGetLocalizable(o, true); loc.setLocale(locale); l = loc.getLocale(); assertEquals(locale, l); o = new Foobar.StaticInternal.Foo(); loc = internalGetLocalizable(o, true); loc.setLocale(locale); l = loc.getLocale(); assertEquals(null, l); }