test/java/util/Locale/LocaleEnhanceTest.java

Print this page
rev 3509 : 7021209: convert lang, math, util to use try-with-resources
Reviewed-by: XXX


1170         for (File testfile : files) {
1171             if (testfile.isDirectory()) {
1172                 continue;
1173             }
1174             String name = testfile.getName();
1175             if (!name.startsWith(TESTFILEPREFIX)) {
1176                 continue;
1177             }
1178             Locale locale;
1179             String locStr = name.substring(TESTFILEPREFIX.length());
1180             if (locStr.equals("ROOT")) {
1181                 locale = Locale.ROOT;
1182             } else {
1183                 String[] fields = locStr.split("_", 3);
1184                 String lang = fields[0];
1185                 String country = (fields.length >= 2) ? fields[1] : "";
1186                 String variant = (fields.length == 3) ? fields[2] : "";
1187                 locale = new Locale(lang, country, variant);
1188             }
1189 
1190             // desrialize
1191             try {
1192                 FileInputStream fis = new FileInputStream(testfile);
1193                 ObjectInputStream ois = new ObjectInputStream(fis);
1194 
1195                 Object o = ois.readObject();
1196                 assertEquals("Deserialize Java 6 Locale " + locale, o, locale);
1197                 ois.close();
1198             } catch (Exception e) {
1199                 errln("Exception while reading " + testfile.getAbsolutePath() + " - " + e.getMessage());
1200             }
1201         }
1202     }
1203 
1204     public void testBug7002320() {
1205         // forLanguageTag() and Builder.setLanguageTag(String)
1206         // should add a location extension for following two cases.
1207         //
1208         // 1. language/country are "ja"/"JP" and the resolved variant (x-lvariant-*)
1209         //    is exactly "JP" and no BCP 47 extensions are available, then add
1210         //    a Unicode locale extension "ca-japanese".
1211         // 2. language/country are "th"/"TH" and the resolved variant is exactly
1212         //    "TH" and no BCP 47 extensions are available, then add a Unicode locale
1213         //    extension "nu-thai".
1214         //
1215         String[][] testdata = {
1216             {"ja-JP-x-lvariant-JP", "ja-JP-u-ca-japanese-x-lvariant-JP"},   // special case 1
1217             {"ja-JP-x-lvariant-JP-XXX"},




1170         for (File testfile : files) {
1171             if (testfile.isDirectory()) {
1172                 continue;
1173             }
1174             String name = testfile.getName();
1175             if (!name.startsWith(TESTFILEPREFIX)) {
1176                 continue;
1177             }
1178             Locale locale;
1179             String locStr = name.substring(TESTFILEPREFIX.length());
1180             if (locStr.equals("ROOT")) {
1181                 locale = Locale.ROOT;
1182             } else {
1183                 String[] fields = locStr.split("_", 3);
1184                 String lang = fields[0];
1185                 String country = (fields.length >= 2) ? fields[1] : "";
1186                 String variant = (fields.length == 3) ? fields[2] : "";
1187                 locale = new Locale(lang, country, variant);
1188             }
1189 
1190             // deserialize
1191             try (FileInputStream fis = new FileInputStream(testfile);
1192                  ObjectInputStream ois = new ObjectInputStream(fis))
1193             {

1194                 Object o = ois.readObject();
1195                 assertEquals("Deserialize Java 6 Locale " + locale, o, locale);

1196             } catch (Exception e) {
1197                 errln("Exception while reading " + testfile.getAbsolutePath() + " - " + e.getMessage());
1198             }
1199         }
1200     }
1201 
1202     public void testBug7002320() {
1203         // forLanguageTag() and Builder.setLanguageTag(String)
1204         // should add a location extension for following two cases.
1205         //
1206         // 1. language/country are "ja"/"JP" and the resolved variant (x-lvariant-*)
1207         //    is exactly "JP" and no BCP 47 extensions are available, then add
1208         //    a Unicode locale extension "ca-japanese".
1209         // 2. language/country are "th"/"TH" and the resolved variant is exactly
1210         //    "TH" and no BCP 47 extensions are available, then add a Unicode locale
1211         //    extension "nu-thai".
1212         //
1213         String[][] testdata = {
1214             {"ja-JP-x-lvariant-JP", "ja-JP-u-ca-japanese-x-lvariant-JP"},   // special case 1
1215             {"ja-JP-x-lvariant-JP-XXX"},