Author: tchemit Date: 2009-05-08 16:03:32 +0000 (Fri, 08 May 2009) New Revision: 1477 Modified: lutinutil/trunk/pom.xml lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java Log: make tests works again on i18n bump i18n plugin version Modified: lutinutil/trunk/pom.xml =================================================================== --- lutinutil/trunk/pom.xml 2009-05-08 15:44:52 UTC (rev 1476) +++ lutinutil/trunk/pom.xml 2009-05-08 16:03:32 UTC (rev 1477) @@ -77,7 +77,7 @@ <labs.project>lutinutil</labs.project> - <i18n.version>0.9</i18n.version> + <i18n.version>0.11</i18n.version> </properties> <build> Modified: lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java =================================================================== --- lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 15:44:52 UTC (rev 1476) +++ lutinutil/trunk/src/main/java/org/codelutin/i18n/I18n.java 2009-05-08 16:03:32 UTC (rev 1477) @@ -294,7 +294,7 @@ * * @return the instanciated i18n loader */ - protected static synchronized I18nLoader getLoader() { + public static synchronized I18nLoader getLoader() { if (loader == null) { loader = new I18nLoader(DEFAULT_LOCALE, uniqueBundleName); Modified: lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java =================================================================== --- lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 15:44:52 UTC (rev 1476) +++ lutinutil/trunk/src/test/java/org/codelutin/i18n/bundle/I18nBundleManagerTest.java 2009-05-08 16:03:32 UTC (rev 1477) @@ -18,16 +18,18 @@ */ package org.codelutin.i18n.bundle; +import org.codelutin.i18n.*; import org.apache.commons.logging.LogFactory; -import org.codelutin.i18n.I18n; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import java.io.File; import java.net.MalformedURLException; +import java.net.URL; import java.net.URLClassLoader; import java.util.Locale; +import org.junit.Assert; /** * I18nBundleFinder Tester. @@ -60,27 +62,20 @@ */ public class I18nBundleManagerTest { - /** to use log facility, just put in your code: log.info(\"...\"); */ static private org.apache.commons.logging.Log log = LogFactory.getLog(I18nBundleManagerTest.class); - - Locale locale; - static URLClassLoader loader; - Integer nbURLs = null; - private I18nBundleManager bundleManager; - static enum BundleTest { + veryDummy(true, false, false, false, false, false), dummy(true, true, true, true, true, true), lutinutil(false, false, true, false, false, true), onlyfr(true, true, false, false, false, false), onylfr2(false, true, false, false, false, false), onlyen(true, false, false, true, false, false); - boolean hasGene; boolean hasFr; boolean hasFrFR; @@ -187,25 +182,25 @@ } @BeforeClass - public static void befireClass() throws MalformedURLException { + public static void beforeClass() throws MalformedURLException { -// loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader(); -// -// URL[] urls = new URL[loader.getURLs().length + 2]; -// -// urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL(); -// urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL(); -// -// int i = 2; -// for (URL url : loader.getURLs()) { -// urls[i++] = url; -// } -// loader = new URLClassLoader(urls, loader); -// -// log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")"); -// for (URL url : loader.getURLs()) { -// log.info("url found in classloader : " + url); -// } + loader = (URLClassLoader) I18nBundleManagerTest.class.getClassLoader(); + + URL[] urls = new URL[loader.getURLs().length + 2]; + + urls[0] = new File("target" + File.separator + "test-classes" + File.separator + "i18n").toURI().toURL(); + urls[1] = new File("target" + File.separator + "classes" + File.separator + "i18n").toURI().toURL(); + + int i = 2; + for (URL url : loader.getURLs()) { + urls[i++] = url; + } + loader = new URLClassLoader(urls, loader); + + log.info("use loader " + loader + " (nb urls : " + loader.getURLs().length + ")"); + for (URL url : loader.getURLs()) { + log.info("url found in classloader : " + url); + } } @After @@ -215,25 +210,23 @@ @Test public void testGetURLs() throws Exception { -// bundleManager = I18n.getBundleManager(); -// Assert.assertEquals(getNbURLs(), bundleManager.getURLs(loader).length); + Assert.assertEquals(getNbURLs(), I18nBundleFactory.getURLs(loader).length); } @Test public void testDetectBundles() throws Exception { -// bundleManager = I18n.getBundleManager(); -// URL[] urls = bundleManager.getURLs(loader); -// Assert.assertEquals(BundleTest.values().length, bundleManager.detectBundles(urls).size()); + URL[] urls = I18nBundleFactory.getURLs(loader); + Assert.assertEquals(BundleTest.values().length, I18nBundleFactory.detectBundles(urls).size()); } @Test public void testGetBundles() throws Exception { -// updateLanguage(null); -// updateLanguage(Locale.FRENCH); -// updateLanguage(Locale.ENGLISH); -// updateLanguage(Locale.FRANCE); -// updateLanguage(Locale.US); -// updateLanguage(Locale.UK); + updateLanguage(null); + updateLanguage(Locale.FRENCH); + updateLanguage(Locale.ENGLISH); + updateLanguage(Locale.FRANCE); + updateLanguage(Locale.US); + updateLanguage(Locale.UK); } protected int getNbURLs() { @@ -250,7 +243,6 @@ protected void updateLanguage(Locale newLocale) { locale = newLocale; I18n.init(locale); - //I18n.init(locale, I18n.DEFAULT_ENCODING); assertBundlesEntries(); } @@ -272,7 +264,6 @@ } if (isFrFR) { - } if (isFrFR || isEnUS || isEnGB) { @@ -280,10 +271,9 @@ } else if (isFr || isEn) { nbEntries += BundleTest.getNbLanguageEntries(isFr, isEn); } -// bundleManager = I18n.getBundleManager(); -// Assert.assertEquals(nbGene + nbLang + nbFull, bundleManager.getBundles(locale).length); + I18nLoader i18nLoader = I18n.getLoader(); + Assert.assertEquals(nbGene + nbLang + nbFull, i18nLoader.getBundles(locale).length); // //TODO make eact match with promute logic ! -// Assert.assertTrue(nbEntries <= bundleManager.getBundleEntries(locale).length); + Assert.assertTrue(nbEntries <= i18nLoader.getBundleEntries(locale).length); } - }