DiscountManagerBean implements DiscountManager { @Override public double findDiscount(Member member) { double discount = 0.0; MembershipLevel ml = membershipLevelManager.findByMemberId(member.getId()); if (ml != null) { switch (ml.getType()) { case SILVER: discount = 0.05; break; case GOLD: discount = 0.10; break; case PLATINUM: discount = 0.12; break; } } return discount; } DiscountManagerBean();  DiscountManagerBean(MembershipLevelManager membershipLevelManagerMock); @Override double findDiscount(Member member);  }
@Test public void userGetsGoldDiscount() { membershipLevel.setType(MembershipLevelType.GOLD); double discount = bean.findDiscount(member); assertEquals(0.10, discount, 0.0); }
@Test public void userGetsSilverDiscount() { membershipLevel.setType(MembershipLevelType.SILVER); double discount = bean.findDiscount(member); assertEquals(0.05, discount, 0.0); }
@Test public void userGetsPlatinumDiscount() { membershipLevel.setType(MembershipLevelType.PLATINUM); double discount = bean.findDiscount(member); assertEquals(0.12, discount, 0.0); }
@Test public void userGetsNoDiscountBecauseNotGoldSilverOrPlatinum() { membershipLevel.setType(MembershipLevelType.BRONZE); double discount = bean.findDiscount(member); assertEquals(0.0, discount, 0.0); }
@Test public void userGetsNoDiscountBecauseNotAMember() { when(membershipLevelManagerMock.findByMemberId(member.getId())).thenReturn(null); double discount = bean.findDiscount(member); assertEquals(0.0, discount, 0.0); }