Beispiel #1
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);
  }
Beispiel #2
0
  /** CSV側の列がsetupした列より少ない場合、 CSV側に無い項目はnullセットされること。 */
  @Test
  public void read_smallColumns() throws Throwable {
    // ## Arrange ##
    final Reader r = BeanCsvReaderTest.getResourceAsReader("-9", "tsv", Charset.forName("UTF-8"));

    final MapCsvLayout<String> layout = new MapCsvLayout<String>();
    layout.setupColumns(
        new SetupBlock<CsvColumnSetup>() {
          @Override
          public void setup(final CsvColumnSetup setup) {
            setup.column("aaa");
            setup.column("bbb");
            setup.column("ccc");
          }
        });

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

    // ## Assert ##
    final Map<String, String> bean = CollectionsUtil.newHashMap();
    assertReadSmallColumns(csvReader, bean);
  }
Beispiel #3
0
 static Reader getResourceAsReader(final String suffix, final String ext) {
   final Reader reader = BeanCsvReaderTest.getResourceAsReader(suffix, ext);
   return reader;
 }