Xls To Xlsx Converter需要junit测试类

时间:2013-07-29 15:27:54

标签: java excel apache-poi junit4

我已经为xls编写了xlsx转换器的java代码,但是我不擅长编写Junit测试用例,所以你能帮我解决下面代码编写测试类的问题吗,谢谢你。

import java.io.File;

public class XlsToXlsxConverter
{
    public static void main(String[] args)
    {
        String basePath = "C:\\Users\\peramm1\\Documents\\IDX\\";

        File baseFile = new File(basePath);

        if (baseFile.isDirectory())
        {
            File[] filesList = baseFile.listFiles();

            try
            {
                for (File eachFile: filesList)
                {
                    String fileName = eachFile.getName();
                    if (fileName.endsWith(".xls"))
                    {
                        String[][] excelData = AdvancedApachePOI.readXls(eachFile.getAbsolutePath());
                        String writeFileName = eachFile.getAbsolutePath().replaceAll(".xls", ".xlsx");
                        AdvancedApachePOI.writeXlsx(excelData, writeFileName);
                    }
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }
}

0 个答案:

没有答案