Author: jerome
Date: 2009-02-27 14:13:05 +0100 (Fri, 27 Feb 2009)
New Revision: 3774

Modified:
   
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
   
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
Log:
* Added unit tests.

Modified: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
===================================================================
--- 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
       2009-02-27 11:18:56 UTC (rev 3773)
+++ 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
       2009-02-27 13:13:05 UTC (rev 3774)
@@ -2,5 +2,6 @@
 <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="con" 
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>

Modified: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
===================================================================
--- 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
       2009-02-27 11:18:56 UTC (rev 3773)
+++ 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
       2009-02-27 13:13:05 UTC (rev 3774)
@@ -22,34 +22,42 @@
 
 import java.util.Locale;
 
+import junit.framework.TestCase;
+
 import com.tuxdroid.I18N.I18N;
 import com.tuxdroid.I18N.error.I18NFileNotFoundException;
 import com.tuxdroid.I18N.error.I18NTranslationTypeException;
 
-public class I18NTests {
+public class I18NTests extends TestCase{
 
        /**
-        * Main tests of the I18N object.
-        * @param args
+        * Test constructor.
         */
-       public static void main(String[] args)
+       public I18NTests()
        {
-               //Tests with po files located on the system.
-               I18NTests.I18NPoFilesTests();
-               //Test with po files as resources.
-               I18NTests.I18NPoResourcesTests();
-               //Test with properties files.
-               I18NTests.I18NPropertiesTests();
+               super();
+               this.startAll();
        }
        
        
        /**
+        * Start the test case.
+        */
+       public void startAll()
+       {
+               this.testI18NPoFiles();
+               this.testI18NPoResources();
+               this.testI18NProperties();
+       }
+       
+       
+       /**
         * Main tests for located in system po files.
         */
-       public static void I18NPoFilesTests()
+       public void testI18NPoFiles()
        {
                I18N i18n = null;
-               
+               String base = "Current weather at {0} is \"unknown\" with a 
temperature of {1} degrees {2}; Humidity level is {3} percent.";
                //Test with external po files.
                try 
                {
@@ -57,87 +65,84 @@
                } 
                catch (I18NFileNotFoundException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                } 
                catch (I18NTranslationTypeException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                }
                if(i18n != null)
                {
-                       System.out.println(i18n.getString("Current weather at 
{0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} 
percent."));
+                       super.assertEquals(i18n.getString(base), base);
                }
+               super.assertNotNull("i18n can't be null", i18n);
                
-               I18NTests.reload(i18n, "Weather Gadget", I18N.PO);
+               testReload(i18n, "Weather Gadget", I18N.PO);
        }
        
        
        /**
         * Main tests for located into jar resources po files.
         */
-       public static void I18NPoResourcesTests()
+       public void testI18NPoResources()
        {
                I18N i18n = null;
+               String base = "Current weather at {0} is \"unknown\" with a 
temperature of {1} degrees {2}; Humidity level is {3} percent.";
                //Test with internal po resources ( compressed into the jar 
file ).
                try 
                {
                        i18n = new I18N("/resourcesTest", "fr", 
I18NTests.class);
-                       System.out.println(i18n.getString("Current weather at 
{0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} 
percent."));
+                       super.assertFalse(i18n.getString(base).equals(base));
                } 
                catch (I18NTranslationTypeException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                } 
                catch (I18NFileNotFoundException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                }
                
-               I18NTests.reload(i18n, "Weather Gadget", I18N.PO);
+               testReload(i18n, "Weather Gadget", I18N.PO);
        }
        
        
        /**
         * Main tests for properties files bundle.
         */
-       public static void I18NPropertiesTests()
+       public void testI18NProperties()
        {
                I18N i18n = null;
                //Sets the bunle base name.
                try 
                {
                        i18n = new I18N("/resourcesTest", new Locale("nl", 
"NL"), "languages");
-                       System.out.println(i18n.getString("welcomeMessage"));
+                       super.assertEquals(i18n.getString("welcomeMessage"), 
"Welkom bij Tuks Control Center");
                } 
                catch (I18NFileNotFoundException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                }
-                       
                
-               //Test with internal properties resources.
-               
                /**
                 * Functions calls.
                 */
-               I18NTests.reload(i18n, "welcomeMessage", I18N.PROPERTIES);
+               testReload(i18n, "welcomeMessage", I18N.PROPERTIES);
        }
        
        
        /**
         * Reload given i18n and display given string value.
         */
-       public static void reload(I18N i18n, String key, byte type)
+       public void testReload(I18N i18n, String key, byte type)
        {
                try 
                {
-                       if(i18n == null)
-                       {
-                               return;
-                       }
+                       super.assertNotNull(i18n);
                        //Simple reload.
+                       String value = i18n.getString(key);
                        i18n.reload();
-                       System.out.println(i18n.getString(key));
+                       super.assertEquals(i18n.getString(key), value);
                        //reload specifying new language.
                        if(type == I18N.PROPERTIES)
                        {
@@ -147,11 +152,21 @@
                        {
                                i18n.reloadPO("nl");
                        }
-                       System.out.println(i18n.getString(key));
+                       super.assertFalse(i18n.getString(key).equals(key));
                } 
                catch (I18NFileNotFoundException e) 
                {
-                       System.out.println(e.getLocalizedMessage());
+                       super.fail(e.getLocalizedMessage());
                }
        }
+       
+       
+       /**
+        * Main tests of the I18N object.
+        * @param args
+        */
+       public static void main(String[] args)
+       {
+               new I18NTests();
+       }
 }


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to