|
| 1 | +package org.json.junit; |
| 2 | + |
| 3 | +import static org.junit.Assert.*; |
| 4 | + |
| 5 | +import java.util.*; |
| 6 | + |
| 7 | +import org.json.*; |
| 8 | +import org.junit.*; |
| 9 | + |
| 10 | +/** |
| 11 | + * Note: This file is saved as UTF-8. Do not save as ASCII or the tests will |
| 12 | + * fail. |
| 13 | + * |
| 14 | + */ |
| 15 | +public class JSONObjectLocaleTest { |
| 16 | + /** |
| 17 | + * JSONObject built from a bean with locale-specific keys - that is, the key |
| 18 | + * fields are not LANG_ENGLISH. |
| 19 | + */ |
| 20 | + @Test |
| 21 | + public void jsonObjectByLocaleBean() { |
| 22 | + |
| 23 | + MyLocaleBean myLocaleBean = new MyLocaleBean(); |
| 24 | + |
| 25 | + Locale.setDefault(new Locale("en")); |
| 26 | + JSONObject jsonen = new JSONObject(myLocaleBean); |
| 27 | + System.out.println("jsonen " + jsonen); |
| 28 | + |
| 29 | + Locale.setDefault(new Locale("tr")); |
| 30 | + JSONObject jsontr = new JSONObject(myLocaleBean); |
| 31 | + System.out.println("jsontr " + jsontr); |
| 32 | + /** |
| 33 | + * In this test we exercise code that handles keys of 1-char and |
| 34 | + * multi-char length that include text from a non-English locale. |
| 35 | + * Turkish in this case. The JSONObject code should correctly retain the |
| 36 | + * non-EN_LANG chars in the key. |
| 37 | + */ |
| 38 | + assertTrue("expected beanId", |
| 39 | + "Tlocaleüx".equals(jsonObject.getString(""))); |
| 40 | + assertTrue("expected Tlocalü", |
| 41 | + "Tlocaleü".equals(jsonObject.getString("ü"))); |
| 42 | + assertTrue("expected Tlocaleüx", |
| 43 | + "Tlocaleüx".equals((String)(jsonObject.query("/üx")))); |
| 44 | + assertTrue("expected Tlocalü", |
| 45 | + "Tlocaleü".equals((String)(jsonObject.query("/ü")))); |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments