1 16 17 package org.apache.commons.lang; 18 19 import junit.framework.Test; 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 import junit.textui.TestRunner; 23 24 31 public class CharEncodingTest extends TestCase { 32 33 public static void main(String [] args) { 34 TestRunner.run(suite()); 35 } 36 37 public static Test suite() { 38 TestSuite suite = new TestSuite(CharEncodingTest.class); 39 suite.setName("CharEncoding Tests"); 40 return suite; 41 } 42 43 private void assertSupportedEncoding(String name) { 44 assertTrue("Encoding should be supported: " + name, CharEncoding.isSupported(name)); 45 } 46 47 public void testMustBeSupportedJava1_3_1() { 48 if (SystemUtils.isJavaVersionAtLeast(1.3f)) { 49 this.assertSupportedEncoding(CharEncoding.ISO_8859_1); 50 this.assertSupportedEncoding(CharEncoding.US_ASCII); 51 this.assertSupportedEncoding(CharEncoding.UTF_16); 52 this.assertSupportedEncoding(CharEncoding.UTF_16BE); 53 this.assertSupportedEncoding(CharEncoding.UTF_16LE); 54 this.assertSupportedEncoding(CharEncoding.UTF_8); 55 } else { 56 this.warn("Java 1.3 tests not run since the current version is " + SystemUtils.JAVA_VERSION); 57 } 58 } 59 60 public void testNotSupported() { 61 assertFalse(CharEncoding.isSupported(null)); 62 assertFalse(CharEncoding.isSupported("")); 63 assertFalse(CharEncoding.isSupported(" ")); 64 assertFalse(CharEncoding.isSupported("\t\r\n")); 65 assertFalse(CharEncoding.isSupported("DOESNOTEXIST")); 66 assertFalse(CharEncoding.isSupported("this is not a valid encoding name")); 67 } 68 69 public void testWorksOnJava1_1_8() { 70 if (SystemUtils.isJavaVersionAtLeast(1.1f)) { 75 this.assertSupportedEncoding(CharEncoding.ISO_8859_1); 76 this.assertSupportedEncoding(CharEncoding.US_ASCII); 77 this.assertSupportedEncoding(CharEncoding.UTF_8); 78 } else { 79 this.warn("Java 1.1 tests not run since the current version is " + SystemUtils.JAVA_VERSION); 80 } 81 } 82 83 public void testWorksOnJava1_2_2() { 84 if (SystemUtils.isJavaVersionAtLeast(1.2f)) { 89 this.assertSupportedEncoding(CharEncoding.ISO_8859_1); 90 this.assertSupportedEncoding(CharEncoding.US_ASCII); 91 this.assertSupportedEncoding(CharEncoding.UTF_8); 92 } else { 93 this.warn("Java 1.2 tests not run since the current version is " + SystemUtils.JAVA_VERSION); 94 } 95 } 96 97 void warn(String msg) { 98 System.err.println(msg); 99 } 100 } 101 | Popular Tags |