Example #1
0
  @Test
  public void read_separator_tab() throws Throwable {
    // ## Arrange ##
    final MapCsvLayout<String> layout = new MapCsvLayout<String>();
    layout.setElementSeparator(CsvSetting.TAB);

    // ## Act ##
    final RecordReader<Map<String, String>> csvReader =
        layout.build().openReader(new StringReader(BeanCsvWriterTest.V_WRITE_SEPARATOR_TAB));

    // ## Assert ##
    _assert(csvReader);
  }
Example #2
0
  @Test
  public void read_quotechar_single() throws Throwable {
    // ## Arrange ##
    final MapCsvLayout<String> layout = new MapCsvLayout<String>();
    layout.setElementSeparator(CsvSetting.COMMA);
    layout.setQuoteMark('\'');

    // ## Act ##
    final RecordReader<Map<String, String>> csvReader =
        layout.build().openReader(new StringReader(BeanCsvWriterTest.V_WRITE_QUOTECHAR_SINGLE));

    // ## Assert ##
    _assert(csvReader);
  }
Example #3
0
  @Test
  public void readCsv() throws Throwable {
    // ## Arrange ##
    final Reader reader =
        BeanCsvReaderTest.getResourceAsReader("-8", "csv", Charset.forName("UTF-8"));

    final MapCsvLayout<String> layout = new MapCsvLayout<String>();
    layout.setElementSeparator(CsvSetting.COMMA);

    // ## Act ##
    final RecordReader<Map<String, String>> csvReader = layout.build().openReader(reader);

    // ## Assert ##
    final Map<String, String> bean = CollectionsUtil.newHashMap();
    assertReadCsv(csvReader, bean);
  }
Example #4
0
  /** デフォルトではtrimしない。 */
  @Test
  public void read_trim_off() throws Throwable {
    // ## Arrange ##
    final MapCsvLayout<String> layout = new MapCsvLayout<String>();
    layout.setElementSeparator(CsvSetting.COMMA);

    // ## Act ##
    final RecordReader<Map<String, String>> csvReader =
        layout.build().openReader(new StringReader("aaa,bbb,ccc\n" + "  , b , \n"));

    // ## Assert ##
    final Map<String, String> bean = CollectionsUtil.newHashMap();
    assertEquals(true, csvReader.hasNext());
    csvReader.read(bean);
    assertEquals("  ", bean.get("aaa"));
    assertEquals(" b ", bean.get("bbb"));
    assertEquals(" ", bean.get("ccc"));

    assertEquals(false, csvReader.hasNext());
    csvReader.close();
  }