PriceBuilder { public BigMoney build() { validateState(); BigMoney price = startingPrice; for (PricingRule pricingRule : pricingRules) { pricingRule.setCustomer(customer); pricingRule.setSupplier(supplier); pricingRule.setQuantity(quantity); if (pricingRule.skip()) { continue; } if (pricingRule.halt()) { break; } price = pricingRule.applyTo(price); } isBuilt = true; return price; } PriceBuilder(); static PriceBuilder newInstance(); BigMoney build(); PriceBuilder withPricingRule(PricingRule pricingRule); PriceBuilder withCustomer(Customer customer); PriceBuilder withSupplier(Supplier supplier); PriceBuilder withStartingPrice(BigMoney startingPrice);  }
@Test public void testBuild() throws Exception { Role supplierRole = DatabaseLoader.buildSupplierRole(); User steveUser = DatabaseLoader.buildSteveSupplier(supplierRole); BigMoney unitPrice = MoneyUtils.parse("GBP 1.23"); PricingRule pricingRule = DatabaseLoader.buildPresetMarginPricingRule(); BigMoney price = PriceBuilder .newInstance() .withSupplier(steveUser.getSupplier()) .withPricingRule(pricingRule) .withStartingPrice(unitPrice) .build(); assertEquals("GBP 1.476",price.toString()); }