Java Code Examples for java.util.Locale#CANADA

The following examples show how to use java.util.Locale#CANADA . 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: RangeFormatTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the parsing method on ranges of numbers. This test fixes the type to
 * {@code Integer.class}.  A different test will let the parser determine the
 * type itself.
 */
@Test
public void testParseIntegers() {
    format   = new RangeFormat(Locale.CANADA, Integer.class);
    parsePos = new ParsePosition(0);

    assertEquals(NumberRange.create(-10, true,   20, true ), parse("[-10 … 20]" ));
    assertEquals(NumberRange.create( -3, false,   4, false), parse("( -3 …  4) "));
    assertEquals(NumberRange.create(  2, true,    8, false), parse("  [2 …  8) "));
    assertEquals(NumberRange.create( 40, false,  90, true ), parse(" (40 … 90]"));
    assertEquals(NumberRange.create(300, true,  300, true ), parse(" 300 "));
    assertEquals(NumberRange.create(300, true,  300, true ), parse("[300]"));
    assertEquals(NumberRange.create(300, false, 300, false), parse("(300)"));
    assertEquals(NumberRange.create(300, true,  300, true ), parse("{300}"));
    assertEquals(NumberRange.create(  0, true,    0, false), parse("[]"));
    assertEquals(NumberRange.create(  0, true,    0, false), parse("{}"));
}
 
Example 2
Source File: DecimalFormatTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_setCurrency() {
    Locale locale = Locale.CANADA;
    DecimalFormat df = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale));

    try {
        df.setCurrency(null);
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    }

    Currency currency = Currency.getInstance("AED");
    df.setCurrency(currency);
    assertTrue("Returned incorrect currency", currency == df.getCurrency());
    assertEquals("Returned incorrect currency symbol", currency.getSymbol(locale),
            df.getDecimalFormatSymbols().getCurrencySymbol());
    assertEquals("Returned incorrect international currency symbol", currency.getCurrencyCode(),
            df.getDecimalFormatSymbols().getInternationalCurrencySymbol());
}
 
Example 3
Source File: DecimalFormatSymbolsTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @tests java.text.DecimalFormatSymbols#setCurrency(java.util.Currency)
 */
public void test_setCurrencyLjava_util_Currency() {
    Locale locale = Locale.CANADA;
    DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat
            .getCurrencyInstance(locale)).getDecimalFormatSymbols();

    try {
        dfs.setCurrency(null);
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    }

    Currency currency = Currency.getInstance("JPY");
    dfs.setCurrency(currency);

    assertTrue("Returned incorrect currency", currency == dfs.getCurrency());
    assertEquals("Returned incorrect currency symbol", currency.getSymbol(
            locale), dfs.getCurrencySymbol());
    assertTrue("Returned incorrect international currency symbol", currency
            .getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));
}
 
Example 4
Source File: AngleFormatTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the field position while formatting an angle.
 */
@Test
public void testFieldPosition() {
    final Latitude latitude = new Latitude(FormattedCharacterIteratorTest.LATITUDE_VALUE);
    final AngleFormat f = new AngleFormat("DD°MM′SS.s″", Locale.CANADA);
    final StringBuffer buffer = new StringBuffer();
    for (int i=AngleFormat.DEGREES_FIELD; i<=AngleFormat.HEMISPHERE_FIELD; i++) {
        final AngleFormat.Field field;
        final int start, limit;
        switch (i) {
            case AngleFormat.DEGREES_FIELD:    field = AngleFormat.Field.DEGREES;    start= 0; limit= 3;  break;
            case AngleFormat.MINUTES_FIELD:    field = AngleFormat.Field.MINUTES;    start= 3; limit= 6;  break;
            case AngleFormat.SECONDS_FIELD:    field = AngleFormat.Field.SECONDS;    start= 6; limit=11; break;
            case AngleFormat.HEMISPHERE_FIELD: field = AngleFormat.Field.HEMISPHERE; start=11; limit=12; break;
            default: continue; // Skip the fraction field.
        }
        final FieldPosition pos = new FieldPosition(field);
        assertEquals(FormattedCharacterIteratorTest.LATITUDE_STRING, f.format(latitude, buffer, pos).toString());
        assertSame  ("getFieldAttribute", field, pos.getFieldAttribute());
        assertEquals("getBeginIndex",     start, pos.getBeginIndex());
        assertEquals("getEndIndex",       limit, pos.getEndIndex());
        buffer.setLength(0);
    }
}
 
Example 5
Source File: LocaleKeyValueItemTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void equalsAndHashCodes() {
    LocaleKeyValueItem eq1 = new LocaleKeyValueItem(Locale.CANADA);
    LocaleKeyValueItem eq2 = new LocaleKeyValueItem(Locale.CANADA);
    LocaleKeyValueItem eq3 = new LocaleKeyValueItem(Locale.CANADA);
    LocaleKeyValueItem diff = new LocaleKeyValueItem(Locale.CHINA);
    TestUtils.testEqualsAndHashCodes(eq1, eq2, eq3, diff);
}
 
Example 6
Source File: RangeFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the parsing method on ranges of numbers where the type is inferred automatically.
 */
@Test
@SuppressWarnings("cast")
public void testParseAuto() {
    format   = new RangeFormat(Locale.CANADA);
    parsePos = new ParsePosition(0);

    assertEquals(NumberRange.create((byte)    -10, true, (byte)    20, true), parse("[  -10 …    20]" ));
    assertEquals(NumberRange.create((short) -1000, true, (short) 2000, true), parse("[-1000 …  2000]" ));
    assertEquals(NumberRange.create((int)      10, true, (int)  40000, true), parse("[   10 … 40000]" ));
    assertEquals(NumberRange.create((int)       1, true, (int)  50000, true), parse("[ 1.00 … 50000]" ));
    assertEquals(NumberRange.create((float)   8.5, true, (float)    4, true), parse("[ 8.50 …     4]" ));
}
 
Example 7
Source File: AngleFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests with no decimal separator.
 */
@Test
public void testNoSeparator() {
    final AngleFormat f = new AngleFormat("DDddd", Locale.CANADA);
    assertEquals(3, f.getMinimumFractionDigits());
    assertEquals(3, f.getMaximumFractionDigits());
    assertEquals( "DDddd",  f.toPattern());
    assertEquals( "19457E", formatAndParse(f, new Longitude( 19.457)));
    assertEquals( "78124S", formatAndParse(f, new Latitude (-78.124)));
    assertEquals("-00010",  formatAndParse(f, new Angle    (-0.01)));
}
 
Example 8
Source File: AngleFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests using {@link Locale#CANADA}.
 */
@Test
public void testCanadaLocale() {
    final AngleFormat f = new AngleFormat("DD.ddd°", Locale.CANADA);
    assertEquals(3, f.getMinimumFractionDigits());
    assertEquals(3, f.getMaximumFractionDigits());
    assertEquals( "DD.ddd°",  f.toPattern());
    assertEquals( "20.000°",  formatAndParse(f, new Angle   ( 20.000)));
    assertEquals( "20.749°",  formatAndParse(f, new Angle   ( 20.749)));
    assertEquals("-12.247°",  formatAndParse(f, new Angle   (-12.247)));
    assertEquals( "13.214°N", formatAndParse(f, new Latitude( 13.214)));
    assertEquals( "12.782°S", formatAndParse(f, new Latitude(-12.782)));
    assertEquals("-00.010°",  formatAndParse(f, new Angle   (-0.01)));
}
 
Example 9
Source File: CoordinateFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link CoordinateFormat#clone()}, then verifies that the clone has the same configuration
 * than the original object.
 */
@Test
public void testClone() {
    CoordinateFormat format = new CoordinateFormat(Locale.CANADA, null);
    CoordinateFormat clone  = format.clone();
    assertNotSame("clone()", clone, format);
    assertEquals("getSeparator()",  format.getSeparator(),  clone.getSeparator());
    assertEquals("getDefaultCRS()", format.getDefaultCRS(), clone.getDefaultCRS());
}
 
Example 10
Source File: CoordinateFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests parsing from a position different then the beginning of the string.
 *
 * @throws ParseException if the parsing failed.
 */
@Test
public void testParseFromOffset() throws ParseException {
    CoordinateFormat coordinateFormat = new CoordinateFormat(Locale.CANADA, null);
    coordinateFormat.setDefaultCRS(VerticalCRSMock.BAROMETRIC_HEIGHT);
    ParsePosition  charPos  = new ParsePosition(7);
    DirectPosition position = coordinateFormat.parse("[skip] 12", charPos);
    assertEquals("Should have parsed the whole text.", 9, charPos.getIndex());
    assertEquals("DirectPosition.getDimension()", 1, position.getDimension());
    assertArrayEquals(new double[] {12}, position.getCoordinate(), STRICT);
}
 
Example 11
Source File: AngleFormatTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests values that have to be rounded, especially the values near zero.
 */
@Test
@DependsOnMethod("testDegreeMinutesSeconds")
public void testRounding() {
    final AngleFormat f = new AngleFormat("DD°MM′SS.sss″", Locale.CANADA);
    assertEquals( "01°00′00.000″", f.format(new Angle(+(59 + (59.9999 / 60)) / 60)));
    assertEquals("-01°00′00.000″", f.format(new Angle(-(59 + (59.9999 / 60)) / 60)));
    assertEquals("-00°59′59.999″", f.format(new Angle(-(59 + (59.9988 / 60)) / 60)));
}
 
Example 12
Source File: FormatterTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Formatter#Formatter(Appendable, Locale)
 */
public void test_ConstructorLjava_lang_AppendableLjava_util_Locale() {
    MockAppendable ma = new MockAppendable();
    Formatter f1 = new Formatter(ma, Locale.CANADA);
    assertEquals(ma, f1.out());
    assertEquals(f1.locale(), Locale.CANADA);

    Formatter f2 = new Formatter(ma, null);
    assertNull(f2.locale());
    assertEquals(ma, f1.out());

    Formatter f3 = new Formatter(null, Locale.GERMAN);
    assertEquals(f3.locale(), Locale.GERMAN);
    assertTrue(f3.out() instanceof StringBuilder);
}
 
Example 13
Source File: AlphabeticIndexTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddLabels_Locale() {
    AlphabeticIndex<?> ulocaleIndex = new AlphabeticIndex<String>(ULocale.CANADA);
    AlphabeticIndex<?> localeIndex = new AlphabeticIndex<String>(Locale.CANADA);
    ulocaleIndex.addLabels(ULocale.SIMPLIFIED_CHINESE);
    localeIndex.addLabels(Locale.SIMPLIFIED_CHINESE);
    assertEquals("getBucketLables() results of ulocaleIndex and localeIndex differ",
            ulocaleIndex.getBucketLabels(), localeIndex.getBucketLabels());
}
 
Example 14
Source File: SimpleEntity.java    From spring-data-crate with Apache License 2.0 5 votes vote down vote up
public static SimpleEntity simpleEntity() {
	
	SimpleEntity entity = new SimpleEntity();
	entity.boolField = true;
   	entity.dateField = new Date();
   	entity.localeField = Locale.CANADA;
   	entity.stringField= "CRATE";
   	
   	return entity;
}
 
Example 15
Source File: ValueContextTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasValue3() {
    setLocale(Locale.getDefault());
    ValueContext fromComponent = new ValueContext(new TestDatePicker(),
            textField, Locale.CANADA);
    Assert.assertEquals(textField, fromComponent.getHasValue().get());
    Assert.assertEquals(Locale.CANADA, fromComponent.getLocale().get());
}
 
Example 16
Source File: WrapLocale.java    From jphp with Apache License 2.0 4 votes vote down vote up
@Signature
public static Memory CANADA(Environment env, Memory... args) {
    return new ObjectMemory(new WrapLocale(env, Locale.CANADA));
}
 
Example 17
Source File: AngleFormatTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests a pattern with illegal usage of D, M and S symbols.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalPattern() {
    final AngleFormat f = new AngleFormat(Locale.CANADA);
    f.applyPattern("DD°SS′MM″");
}
 
Example 18
Source File: AngleFormatTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests an illegal pattern with illegal symbols for the fraction part.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalFractionPattern() {
    final AngleFormat f = new AngleFormat(Locale.CANADA);
    f.applyPattern("DD°MM′SS.m″");
}
 
Example 19
Source File: AngleFormatTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests a {@code '?'} symbol without suffix.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalOptionalField() {
    final AngleFormat f = new AngleFormat(Locale.CANADA);
    f.applyPattern("DD°MM?SS.m″");
}
 
Example 20
Source File: AngleFormatTest.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Tests a {@code '?'} symbol without suffix.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalOptionalLastField() {
    final AngleFormat f = new AngleFormat(Locale.CANADA);
    f.applyPattern("DD°MM?");
}