CsvProcessor implements FileProcessor { @Override public <T> T exportBean(Class<T> clazz, String filePath) throws IOException { List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); List<String> lines = ReaderUtil.readLinesAndClose(filePath, Charset.forName(GBK)); List<String> titles = processeCache.getTitles(clazz); int size = lines.size(); if (CollectionUtil.isEmpty(titles)) { Assert.assertTrue(size == 1, "record size wrong"); } else { Assert.assertTrue(size == 2, "record size wrong"); } String[] strings = CsvUtil.toStringArray(lines.get(size - 1)); Assert.assertTrue(list.size() == strings.length, "read record error"); return stringsToBean(clazz, list, strings); }  @Override void importBean(Object bean, String filePath); @Override void importBeans(Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(String[] contents, String filePath); @Override void importBeans(List<String> contents, String filePath); @Override T exportBean(Class<T> clazz, String filePath); @Override List<T> exportBeans(Class<T> clazz, String filePath); @Override void importBeans(String[] headers, Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(ListMap<String, String> headers, Class<?> clazz, Object[] beans, String filePath); @Override List<String> collectData(FileBeanInfo beanInfo); @Override void importBeans(FileBeanInfo beanInfo, String filePath); @Override ByteArray toByteArray(FileBeanInfo beanInfo); @Override ByteArray toByteArray(List<String> contents);  }
@Test public void exportBean() throws IOException { importBean(); CsvBean bean = processor.exportBean(CsvBean.class, testBeanPath); assertEquals(bean, createBean("小明", 25, "自由", "某某小区")); }