@Test public void testRewardForDining() { // create a new dining of 100.00 charged to credit card '1234123412341234' by merchant // '123457890' as test input Dining dining = Dining.createDining("100.00", "1234123412341234", "1234567890"); // TODO: replace 'null' below with a call to the 'rewardNetwork' to test its // rewardAccountFor(Dining) method RewardConfirmation confirmation = rewardNetwork.rewardAccountFor(dining); // assert the expected reward confirmation results assertNotNull(confirmation); assertNotNull(confirmation.getConfirmationNumber()); // assert an account contribution was made AccountContribution contribution = confirmation.getAccountContribution(); assertNotNull(contribution); // the account number should be '123456789' assertEquals("123456789", contribution.getAccountNumber()); // the total contribution amount should be 8.00 (8% of 100.00) assertEquals(MonetaryAmount.valueOf("8.00"), contribution.getAmount()); // the total contribution amount should have been split into 2 distributions assertEquals(2, contribution.getDistributions().size()); // each distribution should be 4.00 (as both have a 50% allocation) assertEquals( MonetaryAmount.valueOf("4.00"), contribution.getDistribution("Annabelle").getAmount()); assertEquals( MonetaryAmount.valueOf("4.00"), contribution.getDistribution("Corgan").getAmount()); }
/** * Maps the beneficiary columns in a single row to an AllocatedBeneficiary object. * * @param rs the result set with its cursor positioned at the current row * @return an allocated beneficiary * @throws SQLException an exception occurred extracting data from the result set */ private Beneficiary mapBeneficiary(ResultSet rs) throws SQLException { String name = rs.getString("BENEFICIARY_NAME"); MonetaryAmount savings = MonetaryAmount.valueOf(rs.getString("BENEFICIARY_SAVINGS")); Percentage allocationPercentage = Percentage.valueOf(rs.getString("BENEFICIARY_ALLOCATION_PERCENTAGE")); return new Beneficiary(name, allocationPercentage, savings); }
private void verifyRewardInserted(RewardConfirmation confirmation, Dining dining) throws SQLException { assertEquals(1, getRewardCount()); Statement stmt = dataSource.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( "select REWARD_AMOUNT from T_REWARD where CONFIRMATION_NUMBER = '" + confirmation.getConfirmationNumber() + "'"); rs.next(); assertEquals( confirmation.getAccountContribution().getAmount(), MonetaryAmount.valueOf(rs.getString(1))); }
public void testFindByCreditCard() { Account account = repository.findByCreditCard("1234123412341234"); // assert the returned account contains what you expect given the state of the database // and the Account Hibernate mapping configuration assertNotNull("account should never be null", account); assertEquals("wrong entity id", Long.valueOf(0), account.getEntityId()); assertEquals("wrong account number", "123456789", account.getNumber()); assertEquals("wrong name", "Keith and Keri Donald", account.getName()); assertEquals("wrong beneficiary collection size", 2, account.getBeneficiaries().size()); Beneficiary b1 = account.getBeneficiary("Annabelle"); assertNotNull("Annabelle should be a beneficiary", b1); assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b1.getSavings()); assertEquals( "wrong allocation percentage", Percentage.valueOf("50%"), b1.getAllocationPercentage()); Beneficiary b2 = account.getBeneficiary("Corgan"); assertNotNull("Corgan should be a beneficiary", b2); assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b2.getSavings()); assertEquals( "wrong allocation percentage", Percentage.valueOf("50%"), b2.getAllocationPercentage()); }
@Test public void testCreateReward() throws SQLException { Dining dining = Dining.createDining("100.00", "1234123412341234", "0123456789"); Account account = new Account("1", "Keith and Keri Donald"); account.setEntityId(0L); account.addBeneficiary("Annabelle", Percentage.valueOf("50%")); account.addBeneficiary("Corgan", Percentage.valueOf("50%")); AccountContribution contribution = account.makeContribution(MonetaryAmount.valueOf("8.00")); RewardConfirmation confirmation = repository.confirmReward(contribution, dining); assertNotNull("confirmation should not be null", confirmation); assertNotNull("confirmation number should not be null", confirmation.getConfirmationNumber()); assertEquals("wrong contribution object", contribution, confirmation.getAccountContribution()); verifyRewardInserted(confirmation, dining); }