TDD in Cart application
So I have an academic problem of simulating a Cart service.
A Cart supports addition of an OrderItem and another responsibility of
calculating the total price of the particular cart. This is done via
composition and delegation to IPricingCalculator as
public class Cart
{
private List<OrderItem> _items;
private IPricingCalculator;
public Cart(IPricingCalculator pricingCalculator);
public double totalPrice();
}
IPricingCalculator supports the getPrice method as
public interface IPricingCalculator
{
double getPrice(OrderItem item);
}
CustomPriceCalculator implements the IPricingCalculator interface
public class CustomCalculator implements IPricingCalculator
{
private List<IPriceRule> _priceRules;
public double getPrice(OrderItem item); // return the price according to
the first rule that matches
}
Now I have implemented CustomCalculator in TDD way, these are some of my
tests:
@Test
public void FreeItemCostNothing();
public void SpecialItemCostHalf();
public void BulkPurchaseCostsQuater();
and so on.
And I am pretty sure that CustomCalculator is working fine.
But I do not understand what according to TDD should be my next step for
implementing Cart, all Cart is supposed to do is manage a collection of
OrderItem and fold the getPrice method on the collection. Should I have
same exhaustive test suite for both the classes?
Thanks :)
No comments:
Post a Comment