I wrote the program that simulates the basket in the shop. The user is able to add and remove items from the basket. Now, I am wondering, how the unit test for my (void) methods should look like. I am using the JUnit 4.
I have tried to change my addItem method to return the boolean type, instead of returning nothing. With that I am able to write simple Assert.assertTrue(basket.add...). But I do not know, how the unit test for the void method should be written.
public boolean addItem(Item item) {
if (orderedItems.containsKey(item)) {
Integer currItemCount = orderedItems.get(item);
orderedItems.replace(item, currItemCount, currItemCount + 1);
return true;
} else {
orderedItems.put(item, 1);
return true;
}
}
public void addItem(Item item) {
if (orderedItems.containsKey(item)) {
Integer currItemCount = orderedItems.get(item);
orderedItems.replace(item, currItemCount, currItemCount + 1);
} else {
orderedItems.put(item, 1);
}
}
Aucun commentaire:
Enregistrer un commentaire