mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
locale tests
This commit is contained in:
parent
df9c27c53f
commit
928179a1f3
4 changed files with 67 additions and 0 deletions
|
@ -2,6 +2,12 @@ apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'jacoco'
|
apply plugin: 'jacoco'
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
// this subproject requires -parameters option
|
||||||
|
options.compilerArgs << '-parameters'
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
// Uncomment main if you have merged JSON-Java and JSON-Java-unit-test code
|
// Uncomment main if you have merged JSON-Java and JSON-Java-unit-test code
|
||||||
main
|
main
|
||||||
|
|
48
src/test/java/org/json/junit/JSONObjectLocaleTest.java
Executable file
48
src/test/java/org/json/junit/JSONObjectLocaleTest.java
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
package org.json.junit;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.json.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: This file is saved as UTF-8. Do not save as ASCII or the tests will
|
||||||
|
* fail.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class JSONObjectLocaleTest {
|
||||||
|
/**
|
||||||
|
* JSONObject built from a bean with locale-specific keys - that is, the key
|
||||||
|
* fields are not LANG_ENGLISH.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void jsonObjectByLocaleBean() {
|
||||||
|
|
||||||
|
MyLocaleBean myLocaleBean = new MyLocaleBean();
|
||||||
|
|
||||||
|
Locale.setDefault(new Locale("en"));
|
||||||
|
JSONObject jsonen = new JSONObject(myLocaleBean);
|
||||||
|
System.out.println("jsonen " + jsonen);
|
||||||
|
|
||||||
|
Locale.setDefault(new Locale("tr"));
|
||||||
|
JSONObject jsontr = new JSONObject(myLocaleBean);
|
||||||
|
System.out.println("jsontr " + jsontr);
|
||||||
|
/**
|
||||||
|
* In this test we exercise code that handles keys of 1-char and
|
||||||
|
* multi-char length that include text from a non-English locale.
|
||||||
|
* Turkish in this case. The JSONObject code should correctly retain the
|
||||||
|
* non-EN_LANG chars in the key.
|
||||||
|
*/
|
||||||
|
assertTrue("expected beanId",
|
||||||
|
"Tlocaleüx".equals(jsonObject.getString("")));
|
||||||
|
assertTrue("expected Tlocalü",
|
||||||
|
"Tlocaleü".equals(jsonObject.getString("ü")));
|
||||||
|
assertTrue("expected Tlocaleüx",
|
||||||
|
"Tlocaleüx".equals((String)(jsonObject.query("/üx"))));
|
||||||
|
assertTrue("expected Tlocalü",
|
||||||
|
"Tlocaleü".equals((String)(jsonObject.query("/ü"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import org.junit.runners.Suite;
|
||||||
HTTPTest.class,
|
HTTPTest.class,
|
||||||
JSONStringerTest.class,
|
JSONStringerTest.class,
|
||||||
JSONObjectTest.class,
|
JSONObjectTest.class,
|
||||||
|
JSONObjectLocaleTest.class,
|
||||||
JSONArrayTest.class,
|
JSONArrayTest.class,
|
||||||
EnumTest.class,
|
EnumTest.class,
|
||||||
JSONPointerTest.class,
|
JSONPointerTest.class,
|
||||||
|
|
12
src/test/java/org/json/junit/MyLocaleBean.java
Executable file
12
src/test/java/org/json/junit/MyLocaleBean.java
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
package org.json.junit;
|
||||||
|
|
||||||
|
public class MyLocaleBean {
|
||||||
|
private final String id = "beanId";
|
||||||
|
private final String i = "beanI";
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public String getI() {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue