File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Xls To Xlsx Converter need junit test class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Xls To Xlsx Converter need junit test class" Watch "Xls To Xlsx Converter need junit test class" New topic
Author

Xls To Xlsx Converter need junit test class

Mahesh Perumandala
Greenhorn

Joined: Jul 29, 2013
Posts: 2
I have written the java code for xls to xlsx converter, but i'm not good at writing the Junit test cases, so can you help me out how to write a test class for below code , thanks you.

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();
}
}
}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
Sure. What ideas have you had so far? How would you veryify that two files - which are in different file formats- have in fact the same content?


Ping & DNS - my free Android networking tools app
Mahesh Perumandala
Greenhorn

Joined: Jul 29, 2013
Posts: 2
No nothing i don't have anything yet, i need to write a test class for that java class, i mean we can take the basepath and check with Directory like this

" Assert.assertEquals(basePath, baseFile.isDirectory()); " , so can you write a test class.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
That doesn't make sense to me - that would mean the conversion is deemed successful if it produces a file in the same directory as the original file. For a start, that doesn't prove anything about the resulting file, and it also is extremely superficial. If this writing of test is to be meaningful, surely you need to come up with much more finegrained test? Tests that actually look into the newly created file to ascertain whether its content is identical to the original file?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

This post seems like it would fit better in the testing forum, moving.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Xls To Xlsx Converter need junit test class