1 15 package org.apache.tapestry.junit; 16 17 import java.io.InputStream ; 18 import java.util.Properties ; 19 20 import org.apache.tapestry.util.text.LocalizedProperties; 21 22 29 public class TestLocalizedProperties extends TapestryTestCase 30 { 31 private void ensureEquivalence(String fileName) 32 { 33 ensureEquivalence(fileName, fileName, "ISO-8859-1"); 34 } 35 36 private void ensureEquivalence(String fileName1, String fileName2, String encoding) 37 { 38 InputStream standardIns = getClass().getResourceAsStream(fileName1); 39 Properties standard = new Properties (); 40 Exception standardException = null; 41 try 42 { 43 standard.load(standardIns); 44 } 45 catch (Exception e) 46 { 47 standardException = e; 48 } 49 50 InputStream localizedIns = getClass().getResourceAsStream(fileName2); 51 Properties localized = new Properties (); 52 LocalizedProperties localizedProperties = new LocalizedProperties(localized); 53 Exception localizedException = null; 54 try 55 { 56 localizedProperties.load(localizedIns, encoding); 57 } 58 catch (Exception e) 59 { 60 localizedException = e; 61 } 62 63 if (standardException == null && localizedException == null) 64 assertEquals("The property content does not match", standard, localized); 65 else if (standardException == null && localizedException != null) 66 fail("Properties did not throw an exception, but LocalizedProperties did: " 67 + localizedException); 68 else if (standardException != null && localizedException == null) 69 fail("LocalizedProperties did not throw an exception, but Properties did: " 70 + localizedException); 71 } 77 78 81 public void testEquivalence() 82 { 83 ensureEquivalence("StandardProperties.properties"); 84 ensureEquivalence("BadQuoting1.properties"); 85 ensureEquivalence("BadQuoting2.properties"); 86 } 87 88 92 public void testEncodings() 93 { 94 ensureEquivalence("StandardUTFProperties.properties", "UTFProperties.properties", "utf-8"); 95 ensureEquivalence( 96 "StandardCyrillicProperties.properties", 97 "CyrillicProperties.properties", 98 "ISO-8859-5"); 99 } 100 } 101 | Popular Tags |