1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ********************************************************************** 6 * Copyright (c) 2011-2016, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 ********************************************************************** 9 * Author: John Emmons 10 * Created: April 8 - 2011 11 * Since: ICU 4.8 12 ********************************************************************** 13 */ 14 15 package ohos.global.icu.dev.test.util; 16 17 import java.util.List; 18 import java.util.Set; 19 20 import org.junit.Test; 21 import org.junit.runner.RunWith; 22 import org.junit.runners.JUnit4; 23 24 import ohos.global.icu.dev.test.TestFmwk; 25 import ohos.global.icu.util.Region; 26 import ohos.global.icu.util.Region.RegionType; 27 28 29 /** 30 * @test 31 * @summary General test of Regions 32 */ 33 34 35 @RunWith(JUnit4.class) 36 public class RegionTest extends TestFmwk { 37 String[][] knownRegions = { 38 // Code , Numeric , Parent, Type, Containing Continent 39 { "001", "001", null , "WORLD", null }, 40 { "002", "002", "001", "CONTINENT", null }, 41 { "003", "003", null, "GROUPING", null }, 42 { "005", "005", "019", "SUBCONTINENT", "019" }, 43 { "009", "009", "001", "CONTINENT", null}, 44 { "011", "011", "002", "SUBCONTINENT", "002" }, 45 { "013", "013", "019", "SUBCONTINENT", "019" }, 46 { "014", "014", "002", "SUBCONTINENT", "002" }, 47 { "015", "015", "002", "SUBCONTINENT", "002" }, 48 { "017", "017", "002", "SUBCONTINENT", "002" }, 49 { "018", "018", "002", "SUBCONTINENT", "002" }, 50 { "019", "019", "001", "CONTINENT", null }, 51 { "021", "021", "019", "SUBCONTINENT", "019" }, 52 { "029", "029", "019", "SUBCONTINENT", "019" }, 53 { "030", "030", "142", "SUBCONTINENT", "142" }, 54 { "034", "034", "142", "SUBCONTINENT", "142" }, 55 { "035", "035", "142", "SUBCONTINENT", "142" }, 56 { "039", "039", "150", "SUBCONTINENT", "150"}, 57 { "053", "053", "009", "SUBCONTINENT", "009" }, 58 { "054", "054", "009", "SUBCONTINENT", "009" }, 59 { "057", "057", "009", "SUBCONTINENT", "009" }, 60 { "061", "061", "009", "SUBCONTINENT", "009" }, 61 { "142", "142", "001", "CONTINENT", null }, 62 { "143", "143", "142", "SUBCONTINENT", "142" }, 63 { "145", "145", "142", "SUBCONTINENT", "142" }, 64 { "150", "150", "001", "CONTINENT", null }, 65 { "151", "151", "150", "SUBCONTINENT", "150" }, 66 { "154", "154", "150", "SUBCONTINENT", "150" }, 67 { "155", "155", "150", "SUBCONTINENT", "150" }, 68 { "419", "419", null, "GROUPING" , null}, 69 { "AC" , "-1" , "QO" , "TERRITORY", "009" }, 70 { "AD" , "020", "039", "TERRITORY", "150" }, 71 { "AE" , "784", "145", "TERRITORY", "142" }, 72 { "AF" , "004", "034", "TERRITORY", "142" }, 73 { "AG" , "028", "029", "TERRITORY", "019" }, 74 { "AI" , "660", "029", "TERRITORY", "019" }, 75 { "AL" , "008", "039", "TERRITORY", "150" }, 76 { "AM" , "051", "145", "TERRITORY", "142" }, 77 { "AN" , "530", null, "DEPRECATED", null }, 78 { "AO" , "024", "017", "TERRITORY", "002" }, 79 { "AQ" , "010", "QO" , "TERRITORY", "009" }, 80 { "AR" , "032", "005", "TERRITORY", "019" }, 81 { "AS" , "016", "061", "TERRITORY", "009" }, 82 { "AT" , "040", "155", "TERRITORY", "150" }, 83 { "AU" , "036", "053", "TERRITORY", "009" }, 84 { "AW" , "533", "029", "TERRITORY", "019" }, 85 { "AX" , "248", "154", "TERRITORY", "150" }, 86 { "AZ" , "031", "145", "TERRITORY", "142" }, 87 { "BA" , "070", "039", "TERRITORY", "150" }, 88 { "BB" , "052", "029", "TERRITORY", "019" }, 89 { "BD" , "050", "034", "TERRITORY", "142" }, 90 { "BE" , "056", "155", "TERRITORY", "150" }, 91 { "BF" , "854", "011", "TERRITORY", "002" }, 92 { "BG" , "100", "151", "TERRITORY", "150" }, 93 { "BH" , "048", "145", "TERRITORY", "142" }, 94 { "BI" , "108", "014", "TERRITORY", "002" }, 95 { "BJ" , "204", "011", "TERRITORY", "002" }, 96 { "BL" , "652", "029", "TERRITORY", "019" }, 97 { "BM" , "060", "021", "TERRITORY", "019" }, 98 { "BN" , "096", "035", "TERRITORY", "142" }, 99 { "BO" , "068", "005", "TERRITORY", "019" }, 100 { "BQ" , "535", "029", "TERRITORY", "019" }, 101 { "BR" , "076", "005", "TERRITORY", "019" }, 102 { "BS" , "044", "029", "TERRITORY", "019" }, 103 { "BT" , "064", "034", "TERRITORY", "142" }, 104 { "BU" , "104", "035", "TERRITORY", "142" }, 105 { "BV" , "074", "005", "TERRITORY", "019" }, 106 { "BW" , "072", "018", "TERRITORY", "002" }, 107 { "BY" , "112", "151", "TERRITORY", "150" }, 108 { "BZ" , "084", "013", "TERRITORY", "019" }, 109 { "CA" , "124", "021", "TERRITORY", "019" }, 110 { "CC" , "166", "053", "TERRITORY", "009" }, 111 { "CD" , "180", "017", "TERRITORY", "002" }, 112 { "CF" , "140", "017", "TERRITORY", "002" }, 113 { "CG" , "178", "017", "TERRITORY", "002" }, 114 { "CH" , "756", "155", "TERRITORY", "150" }, 115 { "CI" , "384", "011", "TERRITORY", "002" }, 116 { "CK" , "184", "061", "TERRITORY", "009" }, 117 { "CL" , "152", "005", "TERRITORY", "019" }, 118 { "CM" , "120", "017", "TERRITORY", "002" }, 119 { "CN" , "156", "030", "TERRITORY", "142" }, 120 { "CO" , "170", "005", "TERRITORY", "019" }, 121 { "CP" , "-1" , "QO" , "TERRITORY", "009" }, 122 { "CR" , "188", "013", "TERRITORY", "019" }, 123 { "CU" , "192", "029", "TERRITORY", "019" }, 124 { "CV" , "132", "011", "TERRITORY", "002" }, 125 { "CW" , "531", "029", "TERRITORY", "019" }, 126 { "CX" , "162", "053", "TERRITORY", "009" }, 127 { "CY" , "196", "145", "TERRITORY", "142" }, 128 { "CZ" , "203", "151", "TERRITORY", "150" }, 129 { "DD" , "276", "155", "TERRITORY", "150" }, 130 { "DE" , "276", "155", "TERRITORY", "150" }, 131 { "DG" , "-1" , "QO" , "TERRITORY", "009" }, 132 { "DJ" , "262", "014", "TERRITORY", "002" }, 133 { "DK" , "208", "154", "TERRITORY", "150" }, 134 { "DM" , "212", "029", "TERRITORY", "019" }, 135 { "DO" , "214", "029", "TERRITORY", "019" }, 136 { "DZ" , "012", "015", "TERRITORY", "002" }, 137 { "EA" , "-1" , "015", "TERRITORY", "002" }, 138 { "EC" , "218", "005", "TERRITORY", "019" }, 139 { "EE" , "233", "154", "TERRITORY", "150" }, 140 { "EG" , "818", "015", "TERRITORY", "002" }, 141 { "EH" , "732", "015", "TERRITORY", "002" }, 142 { "ER" , "232", "014", "TERRITORY", "002" }, 143 { "ES" , "724", "039", "TERRITORY", "150" }, 144 { "ET" , "231", "014", "TERRITORY", "002" }, 145 { "EU" , "967", null, "GROUPING", null }, 146 { "FI" , "246", "154", "TERRITORY", "150" }, 147 { "FJ" , "242", "054", "TERRITORY", "009" }, 148 { "FK" , "238", "005", "TERRITORY", "019" }, 149 { "FM" , "583", "057", "TERRITORY", "009" }, 150 { "FO" , "234", "154", "TERRITORY", "150" }, 151 { "FR" , "250", "155", "TERRITORY", "150" }, 152 { "FX" , "250", "155", "TERRITORY", "150" }, 153 { "GA" , "266", "017", "TERRITORY", "002" }, 154 { "GB" , "826", "154", "TERRITORY", "150" }, 155 { "GD" , "308", "029", "TERRITORY", "019" }, 156 { "GE" , "268", "145", "TERRITORY", "142" }, 157 { "GF" , "254", "005", "TERRITORY", "019" }, 158 { "GG" , "831", "154", "TERRITORY", "150" }, 159 { "GH" , "288", "011", "TERRITORY", "002" }, 160 { "GI" , "292", "039", "TERRITORY", "150" }, 161 { "GL" , "304", "021", "TERRITORY", "019" }, 162 { "GM" , "270", "011", "TERRITORY", "002" }, 163 { "GN" , "324", "011", "TERRITORY", "002" }, 164 { "GP" , "312", "029", "TERRITORY", "019" }, 165 { "GQ" , "226", "017", "TERRITORY", "002" }, 166 { "GR" , "300", "039", "TERRITORY", "150" }, 167 { "GS" , "239", "005", "TERRITORY", "019" }, 168 { "GT" , "320", "013", "TERRITORY", "019" }, 169 { "GU" , "316", "057", "TERRITORY", "009" }, 170 { "GW" , "624", "011", "TERRITORY", "002" }, 171 { "GY" , "328", "005", "TERRITORY", "019" }, 172 { "HK" , "344", "030", "TERRITORY", "142" }, 173 { "HM" , "334", "053", "TERRITORY", "009" }, 174 { "HN" , "340", "013", "TERRITORY", "019" }, 175 { "HR" , "191", "039", "TERRITORY", "150" }, 176 { "HT" , "332", "029", "TERRITORY", "019" }, 177 { "HU" , "348", "151", "TERRITORY", "150" }, 178 { "IC" , "-1" , "015", "TERRITORY", "002" }, 179 { "ID" , "360", "035", "TERRITORY", "142" }, 180 { "IE" , "372", "154", "TERRITORY", "150" }, 181 { "IL" , "376", "145", "TERRITORY", "142" }, 182 { "IM" , "833", "154", "TERRITORY", "150" }, 183 { "IN" , "356", "034", "TERRITORY", "142" }, 184 { "IO" , "086", "014", "TERRITORY", "002" }, 185 { "IQ" , "368", "145", "TERRITORY", "142" }, 186 { "IR" , "364", "034", "TERRITORY", "142" }, 187 { "IS" , "352", "154", "TERRITORY", "150" }, 188 { "IT" , "380", "039", "TERRITORY", "150" }, 189 { "JE" , "832", "154", "TERRITORY", "150" }, 190 { "JM" , "388", "029", "TERRITORY", "019" }, 191 { "JO" , "400", "145", "TERRITORY", "142" }, 192 { "JP" , "392", "030", "TERRITORY", "142" }, 193 { "KE" , "404", "014", "TERRITORY", "002" }, 194 { "KG" , "417", "143", "TERRITORY", "142" }, 195 { "KH" , "116", "035", "TERRITORY", "142" }, 196 { "KI" , "296", "057", "TERRITORY", "009" }, 197 { "KM" , "174", "014", "TERRITORY", "002" }, 198 { "KN" , "659", "029", "TERRITORY", "019" }, 199 { "KP" , "408", "030", "TERRITORY", "142" }, 200 { "KR" , "410", "030", "TERRITORY", "142" }, 201 { "KW" , "414", "145", "TERRITORY", "142" }, 202 { "KY" , "136", "029", "TERRITORY", "019" }, 203 { "KZ" , "398", "143", "TERRITORY", "142" }, 204 { "LA" , "418", "035", "TERRITORY", "142" }, 205 { "LB" , "422", "145", "TERRITORY", "142" }, 206 { "LC" , "662", "029", "TERRITORY", "019" }, 207 { "LI" , "438", "155", "TERRITORY", "150" }, 208 { "LK" , "144", "034", "TERRITORY", "142" }, 209 { "LR" , "430", "011", "TERRITORY", "002" }, 210 { "LS" , "426", "018", "TERRITORY", "002" }, 211 { "LT" , "440", "154", "TERRITORY", "150" }, 212 { "LU" , "442", "155", "TERRITORY", "150" }, 213 { "LV" , "428", "154", "TERRITORY", "150" }, 214 { "LY" , "434", "015", "TERRITORY", "002" }, 215 { "MA" , "504", "015", "TERRITORY", "002" }, 216 { "MC" , "492", "155", "TERRITORY", "150" }, 217 { "MD" , "498", "151", "TERRITORY", "150" }, 218 { "ME" , "499", "039", "TERRITORY", "150" }, 219 { "MF" , "663", "029", "TERRITORY", "019" }, 220 { "MG" , "450", "014", "TERRITORY", "002" }, 221 { "MH" , "584", "057", "TERRITORY", "009" }, 222 { "MK" , "807", "039", "TERRITORY", "150" }, 223 { "ML" , "466", "011", "TERRITORY", "002" }, 224 { "MM" , "104", "035", "TERRITORY", "142" }, 225 { "MN" , "496", "030", "TERRITORY", "142" }, 226 { "MO" , "446", "030", "TERRITORY", "142" }, 227 { "MP" , "580", "057", "TERRITORY", "009" }, 228 { "MQ" , "474", "029", "TERRITORY", "019" }, 229 { "MR" , "478", "011", "TERRITORY", "002" }, 230 { "MS" , "500", "029", "TERRITORY", "019" }, 231 { "MT" , "470", "039", "TERRITORY", "150" }, 232 { "MU" , "480", "014", "TERRITORY", "002" }, 233 { "MV" , "462", "034", "TERRITORY", "142" }, 234 { "MW" , "454", "014", "TERRITORY", "002" }, 235 { "MX" , "484", "013", "TERRITORY", "019"}, 236 { "MY" , "458", "035", "TERRITORY", "142" }, 237 { "MZ" , "508", "014", "TERRITORY", "002" }, 238 { "NA" , "516", "018", "TERRITORY", "002" }, 239 { "NC" , "540", "054", "TERRITORY", "009" }, 240 { "NE" , "562", "011", "TERRITORY", "002" }, 241 { "NF" , "574", "053", "TERRITORY", "009" }, 242 { "NG" , "566", "011", "TERRITORY", "002" }, 243 { "NI" , "558", "013", "TERRITORY", "019" }, 244 { "NL" , "528", "155", "TERRITORY", "150" }, 245 { "NO" , "578", "154", "TERRITORY", "150" }, 246 { "NP" , "524", "034", "TERRITORY", "142" }, 247 { "NR" , "520", "057", "TERRITORY", "009" }, 248 { "NT" , "536", null , "DEPRECATED", null }, 249 { "NU" , "570", "061", "TERRITORY", "009" }, 250 { "NZ" , "554", "053", "TERRITORY", "009" }, 251 { "OM" , "512", "145", "TERRITORY", "142" }, 252 { "PA" , "591", "013", "TERRITORY", "019" }, 253 { "PE" , "604", "005", "TERRITORY", "019" }, 254 { "PF" , "258", "061", "TERRITORY", "009" }, 255 { "PG" , "598", "054", "TERRITORY", "009" }, 256 { "PH" , "608", "035", "TERRITORY", "142" }, 257 { "PK" , "586", "034", "TERRITORY", "142" }, 258 { "PL" , "616", "151", "TERRITORY", "150" }, 259 { "PM" , "666", "021", "TERRITORY", "019" }, 260 { "PN" , "612", "061", "TERRITORY", "009" }, 261 { "PR" , "630", "029", "TERRITORY", "019" }, 262 { "PS" , "275", "145", "TERRITORY", "142" }, 263 { "PT" , "620", "039", "TERRITORY", "150" }, 264 { "PW" , "585", "057", "TERRITORY", "009" }, 265 { "PY" , "600", "005", "TERRITORY", "019" }, 266 { "QA" , "634", "145", "TERRITORY", "142" }, 267 { "QO" , "961", "009", "SUBCONTINENT", "009" }, 268 { "QU" , "967", null, "GROUPING", null }, 269 { "RE" , "638", "014", "TERRITORY", "002" }, 270 { "RO" , "642", "151", "TERRITORY", "150" }, 271 { "RS" , "688", "039", "TERRITORY", "150" }, 272 { "RU" , "643", "151", "TERRITORY", "150" }, 273 { "RW" , "646", "014", "TERRITORY", "002" }, 274 { "SA" , "682", "145", "TERRITORY", "142" }, 275 { "SB" , "090", "054", "TERRITORY", "009" }, 276 { "SC" , "690", "014", "TERRITORY", "002" }, 277 { "SD" , "729", "015", "TERRITORY", "002" }, 278 { "SE" , "752", "154", "TERRITORY", "150" }, 279 { "SG" , "702", "035", "TERRITORY", "142" }, 280 { "SH" , "654", "011", "TERRITORY", "002" }, 281 { "SI" , "705", "039", "TERRITORY", "150" }, 282 { "SJ" , "744", "154", "TERRITORY", "150" }, 283 { "SK" , "703", "151", "TERRITORY", "150" }, 284 { "SL" , "694", "011", "TERRITORY", "002" }, 285 { "SM" , "674", "039", "TERRITORY", "150" }, 286 { "SN" , "686", "011", "TERRITORY", "002" }, 287 { "SO" , "706", "014", "TERRITORY", "002" }, 288 { "SR" , "740", "005", "TERRITORY", "019" }, 289 { "SS" , "728", "014", "TERRITORY", "002" }, 290 { "ST" , "678", "017", "TERRITORY", "002" }, 291 { "SU" , "810", null , "DEPRECATED" , null}, 292 { "SV" , "222", "013", "TERRITORY", "019" }, 293 { "SX" , "534", "029", "TERRITORY", "019" }, 294 { "SY" , "760", "145", "TERRITORY", "142" }, 295 { "SZ" , "748", "018", "TERRITORY", "002" }, 296 { "TA" , "-1" , "QO", "TERRITORY", "009" }, 297 { "TC" , "796", "029", "TERRITORY", "019" }, 298 { "TD" , "148", "017", "TERRITORY", "002" }, 299 { "TF" , "260", "014", "TERRITORY", "002" }, 300 { "TG" , "768", "011", "TERRITORY", "002" }, 301 { "TH" , "764", "035", "TERRITORY", "142" }, 302 { "TJ" , "762", "143", "TERRITORY", "142" }, 303 { "TK" , "772", "061", "TERRITORY", "009" }, 304 { "TL" , "626", "035", "TERRITORY", "142" }, 305 { "TM" , "795", "143", "TERRITORY", "142" }, 306 { "TN" , "788", "015", "TERRITORY", "002" }, 307 { "TO" , "776", "061", "TERRITORY", "009" }, 308 { "TP" , "626", "035", "TERRITORY", "142" }, 309 { "TR" , "792", "145", "TERRITORY", "142" }, 310 { "TT" , "780", "029", "TERRITORY", "019" }, 311 { "TV" , "798", "061", "TERRITORY", "009" }, 312 { "TW" , "158", "030", "TERRITORY", "142" }, 313 { "TZ" , "834", "014", "TERRITORY", "002" }, 314 { "UA" , "804", "151", "TERRITORY", "150" }, 315 { "UG" , "800", "014", "TERRITORY", "002" }, 316 { "UM" , "581", "057", "TERRITORY", "009" }, 317 { "US" , "840", "021", "TERRITORY", "019" }, 318 { "UY" , "858", "005", "TERRITORY", "019" }, 319 { "UZ" , "860", "143", "TERRITORY", "142" }, 320 { "VA" , "336", "039", "TERRITORY", "150" }, 321 { "VC" , "670", "029", "TERRITORY", "019" }, 322 { "VE" , "862", "005", "TERRITORY", "019" }, 323 { "VG" , "092", "029", "TERRITORY", "019" }, 324 { "VI" , "850", "029", "TERRITORY", "019" }, 325 { "VN" , "704", "035", "TERRITORY", "142" }, 326 { "VU" , "548", "054", "TERRITORY", "009" }, 327 { "WF" , "876", "061", "TERRITORY", "009" }, 328 { "WS" , "882", "061", "TERRITORY", "009" }, 329 { "YD" , "887", "145", "TERRITORY", "142" }, 330 { "YE" , "887", "145", "TERRITORY", "142" }, 331 { "YT" , "175", "014", "TERRITORY", "002" }, 332 { "ZA" , "710", "018", "TERRITORY", "002" }, 333 { "ZM" , "894", "014", "TERRITORY", "002" }, 334 { "ZR" , "180", "017", "TERRITORY", "002" }, 335 { "ZW" , "716", "014", "TERRITORY", "002" }, 336 { "ZZ" , "999", null , "UNKNOWN", null } 337 }; 338 339 /** 340 * Test for known regions. 341 */ 342 @Test TestKnownRegions()343 public void TestKnownRegions() { 344 345 for (String [] rd : knownRegions ) { 346 try { 347 Region r = Region.getInstance(rd[0]); 348 int n = r.getNumericCode(); 349 int e = Integer.valueOf(rd[1]).intValue(); 350 if ( n != e ) { 351 errln("Numeric code mismatch for region " + r.toString() + ". Expected: " + e + " Got:" + n); 352 } 353 if (r.getType() != Region.RegionType.valueOf(rd[3])) { 354 errln("Expected region " + r.toString() + " to be of type " + rd[3] + ". Got:" + r.getType().toString()); 355 } 356 int nc = Integer.valueOf(rd[1]).intValue(); 357 if ( nc > 0 ) { 358 Region ncRegion = Region.getInstance(nc); 359 if ( !ncRegion.equals(r) && nc != 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891 360 errln("Creating region " + r.toString() + " by its numeric code returned a different region. Got: " + ncRegion.toString()); 361 } 362 } 363 } catch (IllegalArgumentException ex ) { 364 errln("Known region " + rd[0] + " was not recognized."); 365 } 366 } 367 } 368 369 @Test TestGetInstanceString()370 public void TestGetInstanceString() { 371 String[][] testData = { 372 // Input ID, Expected ID, Expected Type 373 { "DE", "DE", "TERRITORY" }, // Normal region 374 { "QU", "EU", "GROUPING" }, // Alias to a grouping 375 { "DD", "DE", "TERRITORY" }, // Alias to a deprecated region (East Germany) with single preferred value 376 { "276", "DE", "TERRITORY" }, // Numeric code for Germany 377 { "278", "DE", "TERRITORY" }, // Numeric code for East Germany (Deprecated) 378 { "SU", "SU", "DEPRECATED" }, // Alias to a deprecated region with multiple preferred values 379 { "AN", "AN", "DEPRECATED" }, // Deprecated region with multiple preferred values 380 { "SVK", "SK", "TERRITORY" } // 3-letter code - Slovakia 381 }; 382 383 try { 384 Region.getInstance(null); 385 errln("Calling Region.get(null) should have thrown a NullPointerException, but didn't."); 386 } catch ( NullPointerException ex ) { 387 // Do nothing - we're supposed to get here. 388 } 389 390 try { 391 Region.getInstance("BOGUS"); 392 errln("Calling Region.get(BOGUS) should have thrown a IllegalArgumentException, but didn't."); 393 } catch ( IllegalArgumentException ex ) { 394 // Do nothing - we're supposed to get here. 395 } 396 397 for (String [] data : testData) { 398 String inputID = data[0]; 399 String expectedID = data[1]; 400 Region.RegionType expectedType = Region.RegionType.valueOf(data[2]); 401 Region r = Region.getInstance(inputID); 402 if ( !expectedID.equals(r.toString())) { 403 errln("Unexpected region ID for Region.getInstance(\"" + inputID + "\"); Expected: " + expectedID + " Got: " + r.toString()); 404 } 405 if ( !expectedType.equals(r.getType())) { 406 errln("Unexpected region type for Region.getInstance(\"" + inputID + "\"); Expected: " + expectedType + " Got: " + r.getType()); 407 } 408 } 409 } 410 411 @Test TestGetInstanceInt()412 public void TestGetInstanceInt() { 413 String[][] testData = { 414 // Input ID, Expected ID, Expected Type 415 { "276", "DE", "TERRITORY" }, // Numeric code for Germany 416 { "278", "DE", "TERRITORY" }, // Numeric code for East Germany (Deprecated) 417 { "419", "419", "GROUPING" }, // Latin America 418 { "736", "SD", "TERRITORY" }, // Sudan (pre-2011) - changed numeric code after South Sudan split off 419 { "729", "SD", "TERRITORY" }, // Sudan (post-2011) - changed numeric code after South Sudan split off 420 }; 421 422 try { 423 Region.getInstance(-123); 424 errln("Calling Region.get(-123) should have thrown a IllegalArgumentException, but didn't."); 425 } catch ( IllegalArgumentException ex ) { 426 // Do nothing - we're supposed to get here. 427 } 428 for (String [] data : testData) { 429 String inputID = data[0]; 430 String expectedID = data[1]; 431 Region.RegionType expectedType = Region.RegionType.valueOf(data[2]); 432 Region r = Region.getInstance(Integer.valueOf(inputID)); 433 if ( !expectedID.equals(r.toString())) { 434 errln("Unexpected region ID for Region.getInstance(" + inputID + "); Expected: " + expectedID + " Got: " + r.toString()); 435 } 436 if ( !expectedType.equals(r.getType())) { 437 errln("Unexpected region type for Region.getInstance(" + inputID + "); Expected: " + expectedType + " Got: " + r.getType()); 438 } 439 } 440 441 } 442 443 @Test TestGetContainedRegions()444 public void TestGetContainedRegions() { 445 for (String [] rd : knownRegions ) { 446 try { 447 Region r = Region.getInstance(rd[0]); 448 if (r.getType() == Region.RegionType.GROUPING) { 449 continue; 450 } 451 Set<Region> containedRegions = r.getContainedRegions(); 452 for (Region cr : containedRegions ) { 453 if ( cr.getContainingRegion() != r) { 454 errln("Region: " + r.toString() + " contains region: " + cr.toString() + ". Expected containing region of this region to be the original region, but got: " + 455 ( cr.getContainingRegion() == null ? "NULL" : cr.getContainingRegion().toString())); 456 } 457 } 458 } catch (IllegalArgumentException ex ) { 459 errln("Known region " + rd[0] + " was not recognized."); 460 } 461 } 462 } 463 464 @Test TestGetContainedRegionsWithType()465 public void TestGetContainedRegionsWithType() { 466 for (String [] rd : knownRegions ) { 467 try { 468 Region r = Region.getInstance(rd[0]); 469 if ( r.getType() != Region.RegionType.CONTINENT ) { 470 continue; 471 } 472 Set<Region> containedRegions = r.getContainedRegions(Region.RegionType.TERRITORY); 473 for (Region cr : containedRegions ) { 474 if ( cr.getContainingRegion(Region.RegionType.CONTINENT) != r) { 475 errln("Continent: " + r.toString() + " contains territory: " + cr.toString() + ". Expected containing continent of this region to be the original continent, but got: " + 476 ( cr.getContainingRegion() == null ? "NULL" : cr.getContainingRegion().toString())); 477 } 478 } 479 } catch (IllegalArgumentException ex ) { 480 errln("Known region " + rd[0] + " was not recognized."); 481 } 482 } 483 } 484 485 @Test TestGetContainingRegionWithType()486 public void TestGetContainingRegionWithType() { 487 for (String [] rd : knownRegions ) { 488 try { 489 Region r = Region.getInstance(rd[0]); 490 Region c = r.getContainingRegion(Region.RegionType.CONTINENT); 491 if (rd[4] == null) { 492 if ( c != null) { 493 errln("Containing continent for " + r.toString() + " should have been NULL. Got: " + c.toString()); 494 } 495 } else { 496 Region p = Region.getInstance(rd[4]); 497 if ( !p.equals(c)) { 498 errln("Expected containing continent of region " + r.toString() + " to be " + p.toString() + ". Got: " + ( c == null ? "NULL" : c.toString()) ); 499 } 500 } 501 } catch (IllegalArgumentException ex ) { 502 errln("Known region " + rd[0] + " was not recognized."); 503 } 504 } 505 } 506 507 @Test TestGetContainingRegion()508 public void TestGetContainingRegion() { 509 for (String [] rd : knownRegions ) { 510 try { 511 Region r = Region.getInstance(rd[0]); 512 Region c = r.getContainingRegion(); 513 if (rd[2] == null) { 514 if ( c != null) { 515 errln("Containing region for " + r.toString() + " should have been NULL. Got: " + c.toString()); 516 } 517 } else { 518 Region p = Region.getInstance(rd[2]); 519 if ( !p.equals(c)) { 520 errln("Expected containing region of region " + r.toString() + " to be " + p.toString() + ". Got: " + ( c == null ? "NULL" : c.toString()) ); 521 } 522 } 523 } catch (IllegalArgumentException ex ) { 524 errln("Known region " + rd[0] + " was not recognized."); 525 } 526 } 527 } 528 529 @Test TestGetPreferredValues()530 public void TestGetPreferredValues() { 531 String[][] testData = { 532 // Input ID, Expected Preferred Values... 533 { "AN", "CW", "SX", "BQ" }, // Netherlands Antilles 534 { "CS", "RS", "ME" }, // Serbia & Montenegro 535 { "FQ", "AQ", "TF" }, // French Southern and Antarctic Territories 536 { "NT", "IQ", "SA" }, // Neutral Zone 537 { "PC", "FM", "MH", "MP", "PW" }, // Pacific Islands Trust Territory 538 { "SU", "RU", "AM", "AZ", "BY", "EE", "GE", "KZ", "KG", "LV", "LT", "MD", "TJ", "TM", "UA", "UZ" } // Soviet Union 539 }; 540 541 for (String [] data : testData) { 542 String inputID = data[0]; 543 try { 544 Region r = Region.getInstance(inputID); 545 List<Region> preferredValues = r.getPreferredValues(); 546 for ( int i = 1 ; i < data.length ; i++ ) { 547 try { 548 Region pvr = Region.getInstance(data[i]); 549 if ( !preferredValues.contains(pvr)) { 550 errln("Region.getPreferredValues() for region:" + inputID + "should have contained: " + pvr.toString() + "but it didn't."); 551 } 552 } catch (IllegalArgumentException ex ) { 553 errln("Known region " + data[i] + " was not recognized."); 554 } 555 } 556 } catch (IllegalArgumentException ex ) { 557 errln("Known region " + inputID + " was not recognized."); 558 } 559 } 560 } 561 562 @Test TestContains()563 public void TestContains() { 564 for (String [] rd : knownRegions ) { 565 try { 566 Region r = Region.getInstance(rd[0]); 567 Region c = r.getContainingRegion(); 568 while ( c != null ) { 569 if ( !c.contains(r)) { 570 errln("Region " + c.toString() + "should have contained: " + r.toString() + "but it didn't."); 571 } 572 c = c.getContainingRegion(); 573 } 574 } catch (IllegalArgumentException ex ) { 575 errln("Known region " + rd[0] + " was not recognized."); 576 } 577 } 578 } 579 580 @Test TestAvailableTerritories()581 public void TestAvailableTerritories() { 582 // Test to make sure that the set of territories contained in World and the set of all available 583 // territories are one and the same. 584 Set<Region> availableTerritories = Region.getAvailable(RegionType.TERRITORY); 585 Region world = Region.getInstance("001"); 586 Set<Region> containedInWorld = world.getContainedRegions(RegionType.TERRITORY); 587 if ( !availableTerritories.equals(containedInWorld) ) { 588 errln("Available territories and all territories contained in world should be the same set.\n" + 589 "Available = " + availableTerritories.toString() + "\n" + 590 "Contained in World = " + containedInWorld.toString()); 591 } 592 } 593 } 594