@Test public void discountBasedOnVolumeOfPastPurchases3() throws Exception { Account account = new MockAccount(); Product product = new Product("PROD001", 10000); DiscountService discountService = createMock(DiscountService.class); expect(discountService.getDiscountPercentage(account)) .andReturn(25); replay(discountService); PricingServiceBean bean = new PricingServiceBean(); injectField(bean, "discountService", discountService); Price price = bean.discountedPrice(product, account); verify(discountService); assertEquals(new Price(7500), price); }
public Price discountedPrice(Product product, Account account) { try { DiscountService discounts = getDiscountService(); int discount = discounts.getDiscountPercentage(account); float discountMultiplier = ((100 - discount) / 100.0f); return new Price((int) (product.getPrice() * discountMultiplier)); } catch (Exception e) { throw new RuntimeException(e); } }
PricingServiceBean implements PricingService { public Price discountedPrice(Product product, Account account) { try { DiscountService discounts = getDiscountService(); int discount = discounts.getDiscountPercentage(account); float discountMultiplier = ((100 - discount) / 100.0f); return new Price((int) (product.getPrice() * discountMultiplier)); } catch (Exception e) { throw new RuntimeException(e); } } }
PricingServiceBean implements PricingService { public Price discountedPrice(Product product, Account account) { try { DiscountService discounts = getDiscountService(); int discount = discounts.getDiscountPercentage(account); float discountMultiplier = ((100 - discount) / 100.0f); return new Price((int) (product.getPrice() * discountMultiplier)); } catch (Exception e) { throw new RuntimeException(e); } }  }
PricingServiceBean implements PricingService { public Price discountedPrice(Product product, Account account) { try { DiscountService discounts = getDiscountService(); int discount = discounts.getDiscountPercentage(account); float discountMultiplier = ((100 - discount) / 100.0f); return new Price((int) (product.getPrice() * discountMultiplier)); } catch (Exception e) { throw new RuntimeException(e); } }  @EJB(beanInterface = DiscountService.class) void setDiscountService(DiscountService impl); @PostConstruct void ejbCreate(); Price discountedPrice(Product product, Account account); }
PricingServiceBean implements PricingService { public Price discountedPrice(Product product, Account account) { try { DiscountService discounts = getDiscountService(); int discount = discounts.getDiscountPercentage(account); float discountMultiplier = ((100 - discount) / 100.0f); return new Price((int) (product.getPrice() * discountMultiplier)); } catch (Exception e) { throw new RuntimeException(e); } }  @EJB(beanInterface = DiscountService.class) void setDiscountService(DiscountService impl); @PostConstruct void ejbCreate(); Price discountedPrice(Product product, Account account);  }