I have the following function which accept an InputStream object, and should read this stream and parse it's content into list<Transaction>
public void importTransactions(InputStream is) {
}
On TDD, the test function gives me a case like this:
@Test
public void givenValidXmlStream_WhenImport_ThenReturnTheExpectedTransactions() {
InputStream is = asStream("<TransactionList>\n" +
" <Transaction type=\"C\" amount=\"1000\" narration=\"salary\" />\n" +
" <Transaction type=\"D\" amount=\"200\" narration=\"rent\" />\n" +
" <Transaction type=\"D\" amount=\"800\" narration=\"other\" />\n" +
"</TransactionList>");
xmlTransactionProcessor.importTransactions(is);
List<Transaction> transactions = xmlTransactionProcessor.getImportedTransactions();
assertThat(transactions, containsInAnyOrder(
newTransaction("D", new BigDecimal(200), "rent"),
newTransaction("C", new BigDecimal(1000), "salary"),
newTransaction("D", new BigDecimal(800), "other")
));
}
How should I implement this function? and how to read XML data from inputStream object?