jeudi 19 février 2015

Java: How do I unit test a method that creates and manipulates a file within the scope of the method?

I'm using JUnit and JMockit to create a unit test method that tests the creation and manipulation of a CSV file. How do I intercept the file that is being created to ensure that is created correctly?



@Test
public void testPersistResultsAsCSV() throws IOException {
final Long id = new Long(1234l);

TableRow row = new TableRow();
row.setValue(317l);
row.setId(1234l);

final List<TableRow> rows = new ArrayList<TableRow>();
rows.add(row);

final List<TableRow> empty = new ArrayList<TableRow>();

new Expectations() {
{
tableService.findTableRowsById(id, (TableQueryOptions)any);
result = rows;

tableService.findTableRowsById(id, (TableQueryOptions)any);
result = empty;

fileDataService.saveResultsFile((ResultsFile) any);

}
};

resultsToCsvService.persistResultsAsCSV(id);

}

Aucun commentaire:

Enregistrer un commentaire