Reputation: 33
I have searched everywhere and I can't find a way to test this type of method on how to write a Junit test on this method
Please
private void AddToTable(String itemName, int itemQuantity){
DefaultTableModel table = (DefaultTableModel)itemTable.getModel();
String expiryDate = ((JTextField)jDateChooser2.getDateEditor().getUiComponent()).getText();
String dateAdded = dtf.format(localDate);
table.addRow(new Object[]{itemName, itemQuantity, dateAdded, "Date", expiryDate});
}
Upvotes: 1
Views: 90
Reputation: 17595
This is a private method, you cannot test it directly and probably won't need to.
You could though test it indirectly by testing the method that calls it and checking the DefaultTableModel
returned by itemTable.getModel()
since it seems to be a field in your class and assuming you have a getter for it.
You should try to write code that is testable, for example having methods that are package protected, so that you can access them in your test class assuming the latter is in the same package and try to have methods return something, void
methods are rather difficult to test, you can only test for their impact.
Upvotes: 1