• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xls To Xlsx Converter need junit test class

 
Mahesh Perumandala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mahesh Perumandala
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post seems like it would fit better in the testing forum, moving.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic