Fear with conventions and cycles is twofold:
- You may have an error in the TEST code, so the test does not run properly or worse. The statement inside the conditional block is not approved.
- .
. , , .
Invisible Arrow, :
@Test
public void testsTotalPriceAsSumOfProductPrices() {
Products products = new Products();
products.add(new Product("first", 10));
products.add(new Product("second", 20));
products.add(new Product("second", 30));
assertEquals("Sum must be eq to 60", 60, products.getTotalPrice());
}
Product , .
, (, ).
:
@Test
public void testsTotalPriceAsSumOfProductPrices() {
Products products = new Products();
addProductsWithPrices(products, 10,20,30);
assertEquals(60, products.getTotalPrice());
}
private static void addProductsWithPrices(Products products, Double...prices){
for(Double price : prices){
products.add(new Product("name", price));
}
}
, for. , , , ! , .
, , , (name), . , , , , . , , 10 + 20 + 30 == 60.
, - double - Currency, , .
private static void addProductsWithPrices(Products products, Double...prices){
for(Double price : prices){
products.add(new Product("name", Currency.valueOf(price)));
}
}