コード例 #1
0
 // Break the line at commas, return a map of the resulting strings
 // broken at equals sign.  (<i>Ie</i>, name value pairs.)
 Map getRow(String line) {
   Map map = new HashMap();
   for (Iterator iter = StringUtil.breakAt(line, ',').iterator(); iter.hasNext(); ) {
     String item = (String) iter.next();
     List pair = StringUtil.breakAt(item, '=');
     map.put(pair.get(0), pair.get(1));
   }
   return map;
 }
コード例 #2
0
 protected void assertEqualTables(Object[][] a1, List lines) {
   assertEquals("numrows", a1.length, lines.size() - NUM_HEADER_LINES);
   for (int irow = 0; irow <= a1.length - 1; irow++) {
     Object expRow[] = a1[irow];
     List row = StringUtil.breakAt((String) lines.get(irow + NUM_HEADER_LINES), ',');
     assertEquals("numcols", expRow.length, row.size());
     assertEquals(("row " + irow), SetUtil.fromArray(expRow), new HashSet(row));
   }
 }
コード例 #3
0
  // Tests that don't need a servlet environment
  public void testConvertDisplayString() throws Exception {
    // test null
    Object testObj = null;
    assertEquals("", format(testObj, ColumnDescriptor.TYPE_STRING));

    // test standard numbers
    testObj = new Integer(123);
    assertEquals("123", format(testObj, ColumnDescriptor.TYPE_INT));
    testObj = new Float(123321);
    assertEquals(testObj.toString(), format(testObj, ColumnDescriptor.TYPE_FLOAT));

    // check proper 'big int' formatting
    testObj = new Long(12345678);
    assertEquals("12,345,678", format(testObj, ColumnDescriptor.TYPE_INT));

    // test string
    testObj = "test string";
    assertEquals("test string", format(testObj, ColumnDescriptor.TYPE_STRING));

    // Issue 1901: verify that there is no encoding bias
    testObj = "<>&'\"\n";
    String res = format(testObj, ColumnDescriptor.TYPE_STRING);
    assertEquals(
        "Expected \""
            + StringEscapeUtils.escapeJava(testObj.toString())
            + "\" but got \""
            + StringEscapeUtils.escapeJava(res)
            + "\"; encoding bias?",
        "<>&'\"\n",
        res);

    // test percentage
    testObj = new Double(.453);
    assertEquals("45%", format(testObj, ColumnDescriptor.TYPE_PERCENT));

    // test agreement
    testObj = new Double(.453);
    assertEquals("45.30%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT));
    testObj = new Double(.999999);
    assertEquals("99.99%", format(testObj, ColumnDescriptor.TYPE_AGREEMENT));

    // test date
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2004);
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    cal.set(Calendar.DATE, 1);
    cal.set(Calendar.HOUR_OF_DAY, 15);
    cal.set(Calendar.MINUTE, 15);
    testObj = cal.getTime();
    assertEquals(
        new DisplayConverter().getTableDateFormat().format(testObj),
        format(testObj, ColumnDescriptor.TYPE_DATE));

    // test IPAddr
    testObj = IPAddr.getLocalHost();
    assertEquals(
        IPAddr.getLocalHost().getHostAddress(), format(testObj, ColumnDescriptor.TYPE_IP_ADDRESS));

    // test time interval
    long timeInt = Constants.HOUR + Constants.MINUTE;
    testObj = new Long(timeInt);
    assertEquals(
        StringUtil.timeIntervalToString(timeInt),
        format(testObj, ColumnDescriptor.TYPE_TIME_INTERVAL));

    // test unknown
    testObj = "unknown string";
    assertEquals("unknown string", format(testObj, -1));
  }