java.util.Locale.Builder Java Examples

The following examples show how to use java.util.Locale.Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocaleEnhanceTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #2
Source File: LocaleEnhanceTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #3
Source File: LocaleEnhanceTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #4
Source File: LocaleEnhanceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #5
Source File: LocaleEnhanceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #6
Source File: LocaleEnhanceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #7
Source File: LocaleEnhanceTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #8
Source File: LocaleEnhanceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testGetExtension() {
    // forLanguageTag does NOT normalize to hyphen
    Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
    assertEquals("some_ex-tension", null, locale.getExtension('a'));

    // regular extension
    locale = new Builder().setExtension('a', "some-ex-tension").build();
    assertEquals("builder", "some-ex-tension", 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() { public void 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'));
}
 
Example #9
Source File: LocaleEnhanceTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testGetExtension() {
    // forLanguageTag does NOT normalize to hyphen
    Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
    assertEquals("some_ex-tension", null, locale.getExtension('a'));

    // regular extension
    locale = new Builder().setExtension('a', "some-ex-tension").build();
    assertEquals("builder", "some-ex-tension", 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() { public void 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'));
}
 
Example #10
Source File: LocaleEnhanceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testGetExtension() {
    // forLanguageTag does NOT normalize to hyphen
    Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
    assertEquals("some_ex-tension", null, locale.getExtension('a'));

    // regular extension
    locale = new Builder().setExtension('a', "some-ex-tension").build();
    assertEquals("builder", "some-ex-tension", 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() { public void 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'));
}
 
Example #11
Source File: LocaleEnhanceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #12
Source File: LocaleEnhanceTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void testBuilderSetLanguageTag() {
    String source = "eN-LaTn-Us-NewYork-A-Xx-B-Yy-X-1-2-3";
    String target = "en-Latn-US-NewYork-a-xx-b-yy-x-1-2-3";
    Builder builder = new Builder();
    String result = builder
        .setLanguageTag(source)
        .build()
        .toLanguageTag();
    assertEquals("language", target, result);

    // redundant extensions cause a failure
    new BuilderILE() { public void 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() { public void call() { b.setLanguageTag("und-u-nu-thai-NU-chinese-xx-1234"); }};
}
 
Example #13
Source File: LocaleEnhanceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void testGetExtension() {
    // forLanguageTag does NOT normalize to hyphen
    Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
    assertEquals("some_ex-tension", null, locale.getExtension('a'));

    // regular extension
    locale = new Builder().setExtension('a', "some-ex-tension").build();
    assertEquals("builder", "some-ex-tension", 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() { public void 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'));
}
 
Example #14
Source File: LocaleEnhanceTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void testGetExtension() {
    // forLanguageTag does NOT normalize to hyphen
    Locale locale = Locale.forLanguageTag("und-a-some_ex-tension");
    assertEquals("some_ex-tension", null, locale.getExtension('a'));

    // regular extension
    locale = new Builder().setExtension('a', "some-ex-tension").build();
    assertEquals("builder", "some-ex-tension", 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() { public void 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'));
}
 
Example #15
Source File: LocaleEnhanceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #16
Source File: LocaleEnhanceTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #17
Source File: LocaleEnhanceTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #18
Source File: LocaleEnhanceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #19
Source File: LocaleEnhanceTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that all current locale ids parse.  Use DateFormat as a proxy
 * for all current locale ids.
 */
public void 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);
        }
    }
}
 
Example #20
Source File: LocaleEnhanceTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderClear() {
    String monster = "en-latn-US-NewYork-a-bb-cc-u-co-japanese-x-z-y-x-x";
    Builder builder = new Builder();
    Locale locale = Locale.forLanguageTag(monster);
    String result = builder
        .setLocale(locale)
        .clear()
        .build()
        .toLanguageTag();
    assertEquals("clear", "und", result);
}
 
Example #21
Source File: LocaleEnhanceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testGetScript() {
    // forLanguageTag normalizes case
    Locale locale = Locale.forLanguageTag("und-latn");
    assertEquals("forLanguageTag", "Latn", locale.getScript());

    // 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());
}
 
Example #22
Source File: LocaleEnhanceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderClear() {
    String monster = "en-latn-US-NewYork-a-bb-cc-u-co-japanese-x-z-y-x-x";
    Builder builder = new Builder();
    Locale locale = Locale.forLanguageTag(monster);
    String result = builder
        .setLocale(locale)
        .clear()
        .build()
        .toLanguageTag();
    assertEquals("clear", "und", result);
}
 
Example #23
Source File: LocaleEnhanceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void 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") { public void call() { b.setScript(arg); }};

    // script code validation is NOT performed, any 4-alpha passes
    assertEquals("4alpha", "Wxyz", builder.setScript("wxyz").build().getScript());
}
 
Example #24
Source File: LocaleEnhanceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testGetScript() {
    // forLanguageTag normalizes case
    Locale locale = Locale.forLanguageTag("und-latn");
    assertEquals("forLanguageTag", "Latn", locale.getScript());

    // 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());
}
 
Example #25
Source File: LocaleEnhanceTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderPrivateUseExtension() {
    // normalizes hyphens to underscore, case to lower
    String source = "c-B-a";
    String target = "c-b-a";
    Builder builder = new Builder();
    String result = builder
        .setExtension(Locale.PRIVATE_USE_EXTENSION, source)
        .build()
        .getExtension(Locale.PRIVATE_USE_EXTENSION);
    assertEquals("abc", target, result);

    // multiple hyphens are ill-formed
    new BuilderILE("a--b") { public void call() { b.setExtension(Locale.PRIVATE_USE_EXTENSION, arg); }};
}
 
Example #26
Source File: LocaleEnhanceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderPrivateUseExtension() {
    // normalizes hyphens to underscore, case to lower
    String source = "c-B-a";
    String target = "c-b-a";
    Builder builder = new Builder();
    String result = builder
        .setExtension(Locale.PRIVATE_USE_EXTENSION, source)
        .build()
        .getExtension(Locale.PRIVATE_USE_EXTENSION);
    assertEquals("abc", target, result);

    // multiple hyphens are ill-formed
    new BuilderILE("a--b") { public void call() { b.setExtension(Locale.PRIVATE_USE_EXTENSION, arg); }};
}
 
Example #27
Source File: LocaleEnhanceTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderAddUnicodeLocaleAttribute() {
    Builder builder = new Builder();
    Locale locale = builder
        .addUnicodeLocaleAttribute("def")
        .addUnicodeLocaleAttribute("abc")
        .build();

    Set<String> uattrs = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, uattrs.size());
    assertTrue("attribute abc", uattrs.contains("abc"));
    assertTrue("attribute def", uattrs.contains("def"));

    // remove attribute
    locale = builder.removeUnicodeLocaleAttribute("xxx")
        .build();

    assertEquals("remove bogus", 2, uattrs.size());

    // add duplicate
    locale = builder.addUnicodeLocaleAttribute("abc")
        .build();
    assertEquals("add duplicate", 2, uattrs.size());

    // null attribute throws NPE
    new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};

    // illformed attribute throws IllformedLocaleException
    new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
}
 
Example #28
Source File: LocaleEnhanceTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderAddUnicodeLocaleAttribute() {
    Builder builder = new Builder();
    Locale locale = builder
        .addUnicodeLocaleAttribute("def")
        .addUnicodeLocaleAttribute("abc")
        .build();

    Set<String> uattrs = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, uattrs.size());
    assertTrue("attribute abc", uattrs.contains("abc"));
    assertTrue("attribute def", uattrs.contains("def"));

    // remove attribute
    locale = builder.removeUnicodeLocaleAttribute("xxx")
        .build();

    assertEquals("remove bogus", 2, uattrs.size());

    // add duplicate
    locale = builder.addUnicodeLocaleAttribute("abc")
        .build();
    assertEquals("add duplicate", 2, uattrs.size());

    // null attribute throws NPE
    new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};

    // illformed attribute throws IllformedLocaleException
    new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
}
 
Example #29
Source File: LocaleEnhanceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void testBuilderPrivateUseExtension() {
    // normalizes hyphens to underscore, case to lower
    String source = "c-B-a";
    String target = "c-b-a";
    Builder builder = new Builder();
    String result = builder
        .setExtension(Locale.PRIVATE_USE_EXTENSION, source)
        .build()
        .getExtension(Locale.PRIVATE_USE_EXTENSION);
    assertEquals("abc", target, result);

    // multiple hyphens are ill-formed
    new BuilderILE("a--b") { public void call() { b.setExtension(Locale.PRIVATE_USE_EXTENSION, arg); }};
}
 
Example #30
Source File: LocaleEnhanceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void testGetScript() {
    // forLanguageTag normalizes case
    Locale locale = Locale.forLanguageTag("und-latn");
    assertEquals("forLanguageTag", "Latn", locale.getScript());

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