Search in sources :

Example 56 with FieldPosition

use of java.text.FieldPosition in project j2objc by google.

the class FieldPositionTest method test_hashCode.

public void test_hashCode() {
    // Test for method int java.text.FieldPosition.hashCode()
    FieldPosition fpos1 = new FieldPosition(1);
    FieldPosition fpos2 = new FieldPosition(1);
    assertTrue("test 1: hash codes are not equal for equal objects.", fpos1.hashCode() == fpos2.hashCode());
    fpos1.setBeginIndex(5);
    fpos1.setEndIndex(110);
    assertTrue("test 2: hash codes are equal for non equal objects.", fpos1.hashCode() != fpos2.hashCode());
    fpos2.setBeginIndex(5);
    fpos2.setEndIndex(110);
    assertTrue("test 3: hash codes are not equal for equal objects.", fpos1.hashCode() == fpos2.hashCode());
    FieldPosition fpos3 = new FieldPosition(DateFormat.Field.DAY_OF_WEEK_IN_MONTH);
    assertTrue("test 4: hash codes are equal for non equal objects.", fpos2.hashCode() != fpos3.hashCode());
}
Also used : FieldPosition(java.text.FieldPosition)

Example 57 with FieldPosition

use of java.text.FieldPosition in project j2objc by google.

the class FieldPositionTest method test_getField.

/**
	 * @tests java.text.FieldPosition#getField()
	 */
public void test_getField() {
    // Test for method int java.text.FieldPosition.getField()
    FieldPosition fpos = new FieldPosition(65);
    assertEquals("FieldPosition(65) should have caused getField to return 65", 65, fpos.getField());
    FieldPosition fpos2 = new FieldPosition(DateFormat.Field.MINUTE);
    assertEquals("FieldPosition(DateFormat.Field.MINUTE) should have caused getField to return -1", -1, fpos2.getField());
}
Also used : FieldPosition(java.text.FieldPosition)

Example 58 with FieldPosition

use of java.text.FieldPosition in project j2objc by google.

the class FieldPositionTest method test_getFieldAttribute.

/**
	 * @tests java.text.FieldPosition#getFieldAttribute()
	 */
public void test_getFieldAttribute() {
    // Test for method int java.text.FieldPosition.getFieldAttribute()
    FieldPosition fpos = new FieldPosition(DateFormat.Field.TIME_ZONE);
    assertTrue("FieldPosition(DateFormat.Field.TIME_ZONE) should have caused getFieldAttribute to return DateFormat.Field.TIME_ZONE", fpos.getFieldAttribute() == DateFormat.Field.TIME_ZONE);
    FieldPosition fpos2 = new FieldPosition(DateFormat.TIMEZONE_FIELD);
    assertNull("FieldPosition(DateFormat.TIMEZONE_FIELD) should have caused getFieldAttribute to return null", fpos2.getFieldAttribute());
}
Also used : FieldPosition(java.text.FieldPosition)

Example 59 with FieldPosition

use of java.text.FieldPosition in project j2objc by google.

the class MessageFormatTest method test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.

/* J2ObjC: String hash codes are not consistent with Java.
  public void test_hashCode() {
      assertEquals("Should be equal", 3648, new MessageFormat("rr", null).hashCode());
  }*/
public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
    MessageFormat format = new MessageFormat("{1,number,integer}");
    StringBuffer buffer = new StringBuffer();
    format.format(new Object[] { "0", new Double(53.863) }, buffer, new FieldPosition(0));
    assertEquals("Wrong result", "54", buffer.toString());
    format.format(new Object[] { "0", new Double(53.863) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
    assertEquals("Wrong result", "5454", buffer.toString());
    buffer = new StringBuffer();
    format.applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}");
    Date date = new Date();
    String expectedText = "one two " + DateFormat.getTimeInstance().format(date);
    format.format(new Object[] { new Double(1.6), new Integer(3), date }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
    assertEquals("Choice not recursive:\n" + expectedText + "\n" + buffer, expectedText, buffer.toString());
    StringBuffer str = format.format(new Object[] { new Double(0.6), new Integer(3) }, buffer, null);
    assertEquals(expectedText + "zero", str.toString());
    assertEquals(expectedText + "zero", buffer.toString());
    try {
        format.format(new Object[] { "0", new Double(1), "" }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        format.format(new Object[] { "", new Integer(3) }, buffer, new FieldPosition(MessageFormat.Field.ARGUMENT));
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : MessageFormat(java.text.MessageFormat) FieldPosition(java.text.FieldPosition) Date(java.util.Date)

Example 60 with FieldPosition

use of java.text.FieldPosition in project j2objc by google.

the class NumberFormatTest method test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition.

/**
     * @tests java.text.NumberFormat#format(java.lang.Object,
     *        java.lang.StringBuffer, java.text.FieldPosition)
     */
public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
    FieldPosition pos;
    StringBuffer out;
    DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    pos = new FieldPosition(0);
    out = format.format(new Long(Long.MAX_VALUE), new StringBuffer(), pos);
    assertEquals("Wrong result L1: " + out, "9,223,372,036,854,775,807", out.toString());
    pos = new FieldPosition(0);
    out = format.format(new Long(Long.MIN_VALUE), new StringBuffer(), pos);
    assertEquals("Wrong result L2: " + out, "-9,223,372,036,854,775,808", out.toString());
    pos = new FieldPosition(0);
    out = format.format(new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)), new StringBuffer(), pos);
    assertEquals("Wrong result BI1: " + out, "9,223,372,036,854,775,807", out.toString());
    pos = new FieldPosition(0);
    out = format.format(new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)), new StringBuffer(), pos);
    assertEquals("Wrong result BI2: " + out, "-9,223,372,036,854,775,808", out.toString());
    java.math.BigInteger big;
    pos = new FieldPosition(0);
    big = new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)).add(new java.math.BigInteger("1"));
    out = format.format(big, new StringBuffer(), pos);
    assertEquals("Wrong result BI3: " + out, "9,223,372,036,854,775,808", out.toString());
    pos = new FieldPosition(0);
    big = new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)).add(new java.math.BigInteger("-1"));
    out = format.format(big, new StringBuffer(), pos);
    assertEquals("Wrong result BI4: " + out, "-9,223,372,036,854,775,809", out.toString());
    pos = new FieldPosition(0);
    out = format.format(new java.math.BigDecimal("51.348"), new StringBuffer(), pos);
    assertEquals("Wrong result BD1: " + out, "51.348", out.toString());
    pos = new FieldPosition(0);
    out = format.format(new java.math.BigDecimal("51"), new StringBuffer(), pos);
    assertEquals("Wrong result BD2: " + out, "51", out.toString());
    try {
        format.format(this, new StringBuffer(), pos);
        fail("Should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        format.format(null, new StringBuffer(), pos);
        fail("Should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        format.format(new Long(0), null, pos);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
    try {
        format.format(new Long(0), new StringBuffer(), null);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) FieldPosition(java.text.FieldPosition)

Aggregations

FieldPosition (java.text.FieldPosition)100 Date (java.util.Date)31 SimpleDateFormat (java.text.SimpleDateFormat)28 DecimalFormat (java.text.DecimalFormat)12 NumberFormat (java.text.NumberFormat)12 ParsePosition (java.text.ParsePosition)12 IsoDateFormat (alma.acs.util.IsoDateFormat)9 Test (org.junit.Test)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Format (java.text.Format)8 MessageFormat (java.text.MessageFormat)8 DateFormat (java.text.DateFormat)6 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Vector (java.util.Vector)3 ExtendedDateFormat (org.jkiss.utils.time.ExtendedDateFormat)3 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2