SSL LocaleEnhanceTest.java
Interaktion und PortierbarkeitJAVA
/* * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Test that locale construction works with 'multiple variants'. * <p> * The string "Newer__Yorker" is treated as three subtags, * "Newer", "", and "Yorker", and concatenated into one * subtag by omitting empty subtags and joining the remainer * with underscores. So the resulting variant tag is "Newer_Yorker". * Note that 'New' and 'York' are invalid BCP47 variant subtags * because they are too short.
*/ publicvoid testCreateLocaleMultipleVariants() {
/** * Ensure that all these invalid formats are not recognized by * forLanguageTag.
*/ publicvoid testCreateLocaleCanonicalInvalidSeparator() {
String[] invalids = { // trailing separator "en_Latn_US_NewYork_", "en_Latn_US_", "en_Latn_", "en_", "_",
// are these OK? // "en_Latn__US_NewYork", // variant is 'US_NewYork' // "_Latn__US_NewYork", // variant is 'US_NewYork' // "en__Latn_US_NewYork", // variant is 'Latn_US_NewYork' // "en__US_NewYork", // variant is 'US_NewYork'
// double separator without language or script "__US", "__NewYork",
for (int i = 0; i < invalids.length; ++i) {
String id = invalids[i];
Locale l = Locale.forLanguageTag(id);
assertEquals(id, "und", l.toLanguageTag());
}
}
/** * Ensure that all current locale ids parse. Use DateFormat as a proxy * for all current locale ids.
*/ publicvoid testCurrentLocales() {
Locale[] locales = java.text.DateFormat.getAvailableLocales();
Builder builder = new Builder();
for (Locale target : locales) {
String tag = target.toLanguageTag();
// the tag recreates the original locale, // except no_NO_NY
Locale tagResult = Locale.forLanguageTag(tag); if (!target.getVariant().equals("NY")) {
assertEquals("tagResult", target, tagResult);
}
// the builder also recreates the original locale, // except ja_JP_JP, th_TH_TH and no_NO_NY
Locale builderResult = builder.setLocale(target).build(); if (target.getVariant().length() != 2) {
assertEquals("builderResult", target, builderResult);
}
}
}
/** * Ensure that all icu locale ids parse.
*/ publicvoid testIcuLocales() throws Exception {
BufferedReader br = new BufferedReader( new InputStreamReader(
LocaleEnhanceTest.class.getResourceAsStream("icuLocales.txt"), "UTF-8"));
String id = null; while (null != (id = br.readLine())) {
Locale result = Locale.forLanguageTag(id);
assertEquals("ulocale", id, result.toLanguageTag());
}
}
/// /// Compatibility tests ///
publicvoid testConstructor() { // all the old weirdness still holds, no new weirdness
String[][] tests = { // language to lower case, region to upper, variant unchanged // short
{ "X", "y", "z", "x", "Y" }, // long
{ "xXxXxXxXxXxX", "yYyYyYyYyYyYyYyY", "zZzZzZzZzZzZzZzZ", "xxxxxxxxxxxx", "YYYYYYYYYYYYYYYY" }, // mapped language ids
{ "he", "IL", "", "he" },
{ "iw", "IL", "", "he" },
{ "yi", "DE", "", "yi" },
{ "ji", "DE", "", "yi" },
{ "id", "ID", "", "id" },
{ "in", "ID", "", "id" }, // special variants
{ "ja", "JP", "JP" },
{ "th", "TH", "TH" },
{ "no", "NO", "NY" },
{ "no", "NO", "NY" }, // no canonicalization of 3-letter language codes
{ "eng", "US", "" }
}; for (int i = 0; i < tests.length; ++ i) {
String[] test = tests[i];
String id = String.valueOf(i);
Locale locale = Locale.of(test[0], test[1], test[2]);
assertEquals(id + " lang", test.length > 3 ? test[3] : test[0], locale.getLanguage());
assertEquals(id + " region", test.length > 4 ? test[4] : test[1], locale.getCountry());
assertEquals(id + " variant", test.length > 5 ? test[5] : test[2], locale.getVariant());
}
}
// Builder normalizes case
locale = new Builder().setScript("LATN").build();
assertEquals("builder", "Latn", locale.getScript());
// empty string is returned, not null, if there is no script
locale = Locale.forLanguageTag("und");
assertEquals("script is empty string", "", locale.getScript());
}
publicvoid testGetExtension() { // forLanguageTag does NOT normalize to hyphen
Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
assertEquals("some_ex-tension", null, locale.getExtension('a'));
// returns null if extension is not present
assertEquals("empty b", null, locale.getExtension('b'));
// throws exception if extension tag is illegal new ExpectIAE() { publicvoid call() { Locale.forLanguageTag("").getExtension('\uD800'); }};
// 'x' is not an extension, it's a private use tag, but it's accessed through this API
locale = Locale.forLanguageTag("x-y-z-blork");
assertEquals("x", "y-z-blork", locale.getExtension('x'));
}
// result is not mutable try {
result.add('x');
errln("expected exception on add to extension key set");
} catch (UnsupportedOperationException e) { // ok
}
// returns empty set if no extensions
locale = Locale.forLanguageTag("und");
assertTrue("empty result", locale.getExtensionKeys().isEmpty());
}
// Unicode locale extension key is case insensitive
assertEquals("key case", "japanese", locale.getUnicodeLocaleType("Co"));
// if keyword is not present, returns null
assertEquals("locale keyword not present", null, locale.getUnicodeLocaleType("xx"));
// if no locale extension is set, returns null
locale = Locale.forLanguageTag("und");
assertEquals("locale extension not present", null, locale.getUnicodeLocaleType("co"));
// result is not modifiable try {
result.add("frobozz");
errln("expected exception when add to locale key set");
} catch (UnsupportedOperationException e) { // ok
}
}
publicvoid testToLanguageTag() { // lots of normalization to test here // test locales created using the constructor
String[][] tests = { // empty locale canonicalizes to 'und'
{ "", "", "", "und" }, // variant alone is not a valid Locale, but has a valid language tag
{ "", "", "NewYork", "und-NewYork" }, // standard valid locales
{ "", "Us", "", "und-US" },
{ "", "US", "NewYork", "und-US-NewYork" },
{ "EN", "", "", "en" },
{ "EN", "", "NewYork", "en-NewYork" },
{ "EN", "US", "", "en-US" },
{ "EN", "US", "NewYork", "en-US-NewYork" }, // underscore in variant will be emitted as multiple variant subtags
{ "en", "US", "Newer_Yorker", "en-US-Newer-Yorker" }, // invalid variant subtags are appended as private use
{ "en", "US", "new_yorker", "en-US-x-lvariant-new-yorker" }, // the first invalid variant subtags and following variant subtags are appended as private use
{ "en", "US", "Windows_XP_Home", "en-US-Windows-x-lvariant-XP-Home" }, // too long variant and following variant subtags disappear
{ "en", "US", "WindowsVista_SP2", "en-US" }, // invalid region subtag disappears
{ "en", "USA", "", "en" }, // invalid language tag disappears
{ "e", "US", "", "und-US" }, // three-letter language tags are not canonicalized
{ "Eng", "", "", "eng" }, // legacy languages canonicalize to modern equivalents
{ "he", "IL", "", "he-IL" },
{ "iw", "IL", "", "he-IL" },
{ "yi", "DE", "", "yi-DE" },
{ "ji", "DE", "", "yi-DE" },
{ "id", "ID", "", "id-ID" },
{ "in", "ID", "", "id-ID" }, // special values are converted on output
{ "ja", "JP", "JP", "ja-JP-u-ca-japanese-x-lvariant-JP" },
{ "th", "TH", "TH", "th-TH-u-nu-thai-x-lvariant-TH" },
{ "no", "NO", "NY", "nn-NO" }
}; for (int i = 0; i < tests.length; ++i) {
String[] test = tests[i];
Locale locale = Locale.of(test[0], test[1], test[2]);
assertEquals("case " + i, test[3], locale.toLanguageTag());
}
// test locales created from forLanguageTag
String[][] tests1 = { // case is normalized during the round trip
{ "EN-us", "en-US" },
{ "en-Latn-US", "en-Latn-US" }, // reordering Unicode locale extensions
{ "de-u-co-phonebk-ca-gregory", "de-u-ca-gregory-co-phonebk" }, // private use only language tag is preserved (no extra "und")
{ "x-elmer", "x-elmer" },
{ "x-lvariant-JP", "x-lvariant-JP" },
}; for (String[] test : tests1) {
Locale locale = Locale.forLanguageTag(test[0]);
assertEquals("case " + test[0], test[1], locale.toLanguageTag());
}
}
publicvoid testForLanguageTag() { // forLanguageTag implements the 'Language-Tag' production of // BCP47, so it handles private use and legacy language tags, // unlike locale builder. Tags listed below (except for the // sample private use tags) come from 4646bis Feb 29, 2009.
// irregular legacy language tags, no preferred mappings, drop illegal fields // from end. If no subtag is mappable, fallback to 'und'
{ "i-default", "en-x-i-default" },
{ "i-enochian", "x-i-enochian" },
{ "i-mingo", "see-x-i-mingo" },
{ "en-GB-oed", "en-GB-x-oed" },
{ "zh-min", "nan-x-zh-min" },
{ "cel-gaulish", "xtg-x-cel-gaulish" },
}; for (int i = 0; i < tests.length; ++i) {
String[] test = tests[i];
Locale locale = Locale.forLanguageTag(test[0]);
assertEquals("legacy language tag case " + i, test[1], locale.toLanguageTag());
}
// forLanguageTag ignores everything past the first place it encounters // a syntax error
tests = new String[][] {
{ "valid", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-12345678-z" },
{ "segment of private use tag too long", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y-123456789-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y" },
{ "segment of private use tag is empty", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y--12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x-y" },
{ "first segment of private use tag is empty", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-x--y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def" },
{ "illegal extension tag", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def-\uD800-y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-def" },
{ "locale subtag with no value", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-x-y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-bb-x-y-12345678-z" },
{ "locale key subtag invalid", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc-123456789-def-x-y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd-u-aa-abc" }, // locale key subtag invalid in earlier position, all following subtags // dropped (and so the locale extension dropped as well)
{ "locale key subtag invalid in earlier position", "en-US-Newer-Yorker-a-bb-cc-dd-u-123456789-abc-bb-def-x-y-12345678-z", "en-US-Newer-Yorker-a-bb-cc-dd" },
}; for (int i = 0; i < tests.length; ++i) {
String[] test = tests[i];
String msg = "syntax error case " + i + " " + test[0]; try {
Locale locale = Locale.forLanguageTag(test[1]);
assertEquals(msg, test[2], locale.toLanguageTag());
} catch (IllegalArgumentException e) {
errln(msg + " caught exception: " + e);
}
}
// duplicated extension are just ignored
Locale locale = Locale.forLanguageTag("und-d-aa-00-bb-01-D-AA-10-cc-11-c-1234");
assertEquals("extension", "aa-00-bb-01", locale.getExtension('d'));
assertEquals("extension c", "1234", locale.getExtension('c'));
// redundant Unicode locale keys in an extension are ignored
locale = Locale.forLanguageTag("und-u-aa-000-bb-001-bB-002-cc-003-c-1234");
assertEquals("Unicode keywords", "aa-000-bb-001-cc-003", locale.getExtension(Locale.UNICODE_LOCALE_EXTENSION));
assertEquals("Duplicated Unicode locake key followed by an extension", "1234", locale.getExtension('c'));
}
for (int i = 0; i < testLocales.length; i++) {
Locale loc = testLocales[i];
assertEquals("English display name for " + loc.toLanguageTag(),
displayNameEnglish[i], loc.getDisplayName(Locale.ENGLISH));
assertEquals("Simplified Chinese display name for " + loc.toLanguageTag(),
displayNameSimplifiedChinese[i], loc.getDisplayName(Locale.CHINA));
}
}
/// /// Builder tests ///
publicvoid testBuilderSetLocale() {
Builder builder = new Builder();
Builder lenientBuilder = new Builder();
// redundant extensions cause a failure new BuilderILE() { publicvoid call() { b.setLanguageTag("und-a-xx-yy-b-ww-A-00-11-c-vv"); }};
// redundant Unicode locale extension keys within an Unicode locale extension cause a failure new BuilderILE() { publicvoid call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
publicvoid testBuilderSetLanguage() { // language is normalized to lower case
String source = "eN";
String target = "en";
String defaulted = "";
Builder builder = new Builder();
String result = builder
.setLanguage(source)
.build()
.getLanguage();
assertEquals("en", target, result);
// setting with empty resets
result = builder
.setLanguage(target)
.setLanguage("")
.build()
.getLanguage();
assertEquals("empty", defaulted, result);
// setting with null resets too
result = builder
.setLanguage(target)
.setLanguage(null)
.build()
.getLanguage();
assertEquals("null", defaulted, result);
// language codes must be 2-8 alpha // for forwards compatibility, 4-alpha and 5-8 alpha (registered) // languages are accepted syntax new BuilderILE("q", "abcdefghi", "13") { publicvoid call() { b.setLanguage(arg); }};
// language code validation is NOT performed, any 2-8-alpha passes
assertNotNull("2alpha", builder.setLanguage("zz").build());
assertNotNull("8alpha", builder.setLanguage("abcdefgh").build());
// three-letter language codes are NOT canonicalized to two-letter
result = builder
.setLanguage("eng")
.build()
.getLanguage();
assertEquals("eng", "eng", result);
}
publicvoid testBuilderSetScript() { // script is normalized to title case
String source = "lAtN";
String target = "Latn";
String defaulted = "";
Builder builder = new Builder();
String result = builder
.setScript(source)
.build()
.getScript();
assertEquals("script", target, result);
// setting with empty resets
result = builder
.setScript(target)
.setScript("")
.build()
.getScript();
assertEquals("empty", defaulted, result);
// settting with null also resets
result = builder
.setScript(target)
.setScript(null)
.build()
.getScript();
assertEquals("null", defaulted, result);
// ill-formed script codes throw IAE // must be 4alpha new BuilderILE("abc", "abcde", "l3tn") { publicvoid call() { b.setScript(arg); }};
// script code validation is NOT performed, any 4-alpha passes
assertEquals("4alpha", "Wxyz", builder.setScript("wxyz").build().getScript());
}
publicvoid testBuilderSetRegion() { // region is normalized to upper case
String source = "uS";
String target = "US";
String defaulted = "";
Builder builder = new Builder();
String result = builder
.setRegion(source)
.build()
.getCountry();
assertEquals("us", target, result);
// setting with empty resets
result = builder
.setRegion(target)
.setRegion("")
.build()
.getCountry();
assertEquals("empty", defaulted, result);
// setting with null also resets
result = builder
.setRegion(target)
.setRegion(null)
.build()
.getCountry();
assertEquals("null", defaulted, result);
// ill-formed region codes throw IAE // 2 alpha or 3 numeric new BuilderILE("q", "abc", "12", "1234", "a3", "12a") { publicvoid call() { b.setRegion(arg); }};
// region code validation is NOT performed, any 2-alpha or 3-digit passes
assertEquals("2alpha", "ZZ", builder.setRegion("ZZ").build().getCountry());
assertEquals("3digit", "000", builder.setRegion("000").build().getCountry());
}
publicvoid testBuilderSetVariant() { // Variant case is not normalized in lenient variant mode
String source = "NewYork";
String target = source;
String defaulted = "";
Builder builder = new Builder();
String result = builder
.setVariant(source)
.build()
.getVariant();
assertEquals("NewYork", target, result);
result = builder
.setVariant("NeWeR_YoRkEr")
.build()
.toLanguageTag();
assertEquals("newer yorker", "und-NeWeR-YoRkEr", result);
// subtags of variant are NOT reordered
result = builder
.setVariant("zzzzz_yyyyy_xxxxx")
.build()
.getVariant();
assertEquals("zyx", "zzzzz_yyyyy_xxxxx", result);
// setting to empty resets
result = builder
.setVariant(target)
.setVariant("")
.build()
.getVariant();
assertEquals("empty", defaulted, result);
// setting to null also resets
result = builder
.setVariant(target)
.setVariant(null)
.build()
.getVariant();
assertEquals("null", defaulted, result);
// ill-formed variants throw IAE // digit followed by 3-7 characters, or alpha followed by 4-8 characters. new BuilderILE("abcd", "abcdefghi", "1ab", "1abcdefgh") { publicvoid call() { b.setVariant(arg); }};
// 4 characters is ok as long as the first is a digit
assertEquals("digit+3alpha", "1abc", builder.setVariant("1abc").build().getVariant());
// all subfields must conform new BuilderILE("abcde-fg") { publicvoid call() { b.setVariant(arg); }};
}
publicvoid testBuilderSetExtension() { // upper case characters are normalized to lower case finalchar sourceKey = 'a'; final String sourceValue = "aB-aBcdefgh-12-12345678";
String target = "ab-abcdefgh-12-12345678";
Builder builder = new Builder();
String result = builder
.setExtension(sourceKey, sourceValue)
.build()
.getExtension(sourceKey);
assertEquals("extension", target, result);
// setting with empty resets
result = builder
.setExtension(sourceKey, sourceValue)
.setExtension(sourceKey, "")
.build()
.getExtension(sourceKey);
assertEquals("empty", null, result);
// setting with null also resets
result = builder
.setExtension(sourceKey, sourceValue)
.setExtension(sourceKey, null)
.build()
.getExtension(sourceKey);
assertEquals("null", null, result);
// ill-formed extension keys throw IAE // must be in [0-9a-ZA-Z] new BuilderILE("$") { publicvoid call() { b.setExtension('$', sourceValue); }};
// each segment of value must be 2-8 alphanum new BuilderILE("ab-cd-123456789") { publicvoid call() { b.setExtension(sourceKey, arg); }};
// no multiple hyphens. new BuilderILE("ab--cd") { publicvoid call() { b.setExtension(sourceKey, arg); }};
// locale extension key has special handling
Locale locale = builder
.setExtension('u', "co-japanese")
.build();
assertEquals("locale extension", "japanese", locale.getUnicodeLocaleType("co"));
// locale extension has same behavior with set locale keyword
Locale locale2 = builder
.setUnicodeLocaleKeyword("co", "japanese")
.build();
assertEquals("locales with extension", locale, locale2);
publicvoid testBuildersetUnicodeLocaleKeyword() { // Note: most behavior is tested in testBuilderSetExtension
Builder builder = new Builder();
Locale locale = builder
.setUnicodeLocaleKeyword("co", "japanese")
.setUnicodeLocaleKeyword("nu", "thai")
.build();
assertEquals("co", "japanese", locale.getUnicodeLocaleType("co"));
assertEquals("nu", "thai", locale.getUnicodeLocaleType("nu"));
assertEquals("keys", 2, locale.getUnicodeLocaleKeys().size());
// can clear a keyword by setting to null, others remain
String result = builder
.setUnicodeLocaleKeyword("co", null)
.build()
.toLanguageTag();
assertEquals("empty co", "und-u-nu-thai", result);
// locale keyword extension goes when all keywords are gone
result = builder
.setUnicodeLocaleKeyword("nu", null)
.build()
.toLanguageTag();
assertEquals("empty nu", "und", result);
// locale keywords are ordered independent of order of addition
result = builder
.setUnicodeLocaleKeyword("zz", "012")
.setUnicodeLocaleKeyword("aa", "345")
.build()
.toLanguageTag();
assertEquals("reordered", "und-u-aa-345-zz-012", result);
for (Locale locale : testLocales) { try { // write
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(locale);
// read
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
Object o = ois.readObject();
if (dataDir == null) {
errln("'dataDir' is null. serialized.data.dir Property value is "+dataDirName); return;
} elseif (!dataDir.isDirectory()) {
errln("'dataDir' is not a directory. dataDir: "+dataDir.toString()); return;
}
// deserialize try (FileInputStream fis = new FileInputStream(testfile);
ObjectInputStream ois = new ObjectInputStream(fis))
{
Object o = ois.readObject();
assertEquals("Deserialize Java 6 Locale " + locale, o, locale);
} catch (Exception e) {
errln("Exception while reading " + testfile.getAbsolutePath() + " - " + e.getMessage());
}
}
}
publicvoid testBug7002320() { // forLanguageTag() and Builder.setLanguageTag(String) // should add a location extension for following two cases. // // 1. language/country are "ja"/"JP" and the resolved variant (x-lvariant-*) // is exactly "JP" and no BCP 47 extensions are available, then add // a Unicode locale extension "ca-japanese". // 2. language/country are "th"/"TH" and the resolved variant is exactly // "TH" and no BCP 47 extensions are available, then add a Unicode locale // extension "nu-thai". //
String[][] testdata = {
{"ja-JP-x-lvariant-JP", "ja-JP-u-ca-japanese-x-lvariant-JP"}, // special case 1
{"ja-JP-x-lvariant-JP-XXX"},
{"ja-JP-u-ca-japanese-x-lvariant-JP"},
{"ja-JP-u-ca-gregory-x-lvariant-JP"},
{"ja-JP-u-cu-jpy-x-lvariant-JP"},
{"ja-x-lvariant-JP"},
{"th-TH-x-lvariant-TH", "th-TH-u-nu-thai-x-lvariant-TH"}, // special case 2
{"th-TH-u-nu-thai-x-lvariant-TH"},
{"en-US-x-lvariant-JP"},
};
Builder bldr = new Builder();
for (String[] data : testdata) {
String in = data[0];
String expected = (data.length == 1) ? data[0] : data[1];
// forLanguageTag
Locale loc = Locale.forLanguageTag(in);
String out = loc.toLanguageTag();
assertEquals("Language tag roundtrip by forLanguageTag with input: " + in, expected, out);
// setLanguageTag
bldr.clear();
bldr.setLanguageTag(in);
loc = bldr.build();
out = loc.toLanguageTag();
assertEquals("Language tag roundtrip by Builder.setLanguageTag with input: " + in, expected, out);
}
}
for (String[] data : testdata) {
String in = data[0];
String expected = (data.length == 1) ? data[0] : data[1];
Locale loc = Locale.forLanguageTag(in);
String out = loc.toString();
assertEquals("Empty country field with non-empty script/extension with input: " + in, expected, out);
}
}
privatevoid assertEquals(String msg, Object e, Object v) { if (e == null ? v != null : !e.equals(v)) { if (e != null) {
e = "'" + e + "'";
} if (v != null) {
v = "'" + v + "'";
}
errln(msg + ": expected " + e + " but got " + v);
}
}
privatevoid assertNotEquals(String msg, Object e, Object v) { if (e == null ? v == null : e.equals(v)) { if (e != null) {
e = "'" + e + "'";
}
errln(msg + ": expected not equal " + e);
}
}
privatevoid assertNull(String msg, Object o) { if (o != null) {
errln(msg + ": expected null but got '" + o + "'");
}
}
privatevoid assertNotNull(String msg, Object o) { if (o == null) {
errln(msg + ": expected non null");
}
}
// not currently used, might get rid of exceptions from the API privateabstractclass ExceptionTest { privatefinalClass<? extends Exception> exceptionClass;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.