1
0
Fork 0
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:
stleary 2017-02-14 08:30:22 -06:00
parent df9c27c53f
commit 928179a1f3
4 changed files with 67 additions and 0 deletions

View file

@ -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

View 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(""))));
}
}

View file

@ -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,

View 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;
}
}