FileDocCategorySizeDatePackage
MakeWithdrawal.javaAPI DocExample1980Thu Nov 08 00:22:50 GMT 2001com.ora.rmibook.chapter13.bank.applications.tests

MakeWithdrawal

public class MakeWithdrawal extends Test

Fields Summary
Constructors Summary
public MakeWithdrawal(NameRepository nameRepository)

        super (nameRepository);
    
Methods Summary
protected java.lang.StringdescribeOperation()

        return "make a widthdrawal from ";
    
protected java.lang.StringperformActualTest(java.lang.String idNumber, Account3 account)

        Money balance = null;
        Money amountToWithdraw = getRandomMoney();
        Money correctResult;
        Money actualResultingBalance;

        try {
            balance = account.getBalance(idNumber);
            correctResult = balance.subtract(amountToWithdraw);
            account.makeWithdrawal(idNumber, amountToWithdraw);
            actualResultingBalance = account.getBalance(idNumber);
        } catch (RemoteException remoteException) {
            return REMOTE_EXCEPTION_THROWN;
        } catch (OverdraftException overdraftException) {
            if (amountToWithdraw.greaterThan(balance)) {
                return SUCCESS;
            } else {
                return FAILURE;
            }
        } catch (LockedAccountException lockedAccountException) {
            return ACCOUNT_WAS_LOCKED;
        } catch (NegativeAmountException negativeAmountException) {
            if (amountToWithdraw.isNegative()) {
                return SUCCESS;
            } else {
                return FAILURE;
            }
        }
        if (amountToWithdraw.greaterThan(balance)) {
            return FAILURE;
        }
        if (amountToWithdraw.isNegative()) {
            return FAILURE;
        }
        if (correctResult.equals(actualResultingBalance)) {
            return SUCCESS;
        } else {
            return FAILURE;
        }