Coverage Report - org.apache.shiro.samples.aspectj.bank.AccountTransaction
 
Classes in this File Line Coverage Branch Coverage Complexity
AccountTransaction
92%
24/26
N/A
1
AccountTransaction$TransactionType
75%
3/4
N/A
1
 
 1  0
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.shiro.samples.aspectj.bank;
 20  
 
 21  
 import org.apache.commons.lang.builder.ToStringBuilder;
 22  
 import org.apache.commons.lang.builder.ToStringStyle;
 23  
 
 24  
 import java.sql.Timestamp;
 25  
 import java.util.Date;
 26  
 
 27  
 public class AccountTransaction {
 28  
 
 29  
     private static long _SEQUENCE;
 30  
 
 31  6
     public enum TransactionType {
 32  2
         DEPOSIT,
 33  2
         WITHDRAWAL
 34  
     }
 35  
 
 36  
     private long _id;
 37  
 
 38  
     private TransactionType _type;
 39  
 
 40  
     private long _accountId;
 41  
 
 42  
     private double _amount;
 43  
 
 44  
     private String _createdBy;
 45  
     private Date _creationDate;
 46  
 
 47  
     public static AccountTransaction createDepositTx(long anAccountId, double anAmount) {
 48  18
         return new AccountTransaction(TransactionType.DEPOSIT, anAccountId, anAmount);
 49  
     }
 50  
 
 51  
     public static AccountTransaction createWithdrawalTx(long anAccountId, double anAmount) {
 52  20
         return new AccountTransaction(TransactionType.WITHDRAWAL, anAccountId, anAmount);
 53  
     }
 54  
 
 55  38
     private AccountTransaction(TransactionType aType, long anAccountId, double anAmount) {
 56  38
         _id = ++_SEQUENCE;
 57  38
         _type = aType;
 58  38
         _accountId = anAccountId;
 59  38
         _amount = anAmount;
 60  38
         _createdBy = "unknown";
 61  38
         _creationDate = new Date();
 62  38
     }
 63  
 
 64  
     /**
 65  
      * Returns the id attribute.
 66  
      *
 67  
      * @return The id value.
 68  
      */
 69  
     public long getId() {
 70  0
         return _id;
 71  
     }
 72  
 
 73  
     /**
 74  
      * Returns the type attribute.
 75  
      *
 76  
      * @return The type value.
 77  
      */
 78  
     public TransactionType getType() {
 79  160
         return _type;
 80  
     }
 81  
 
 82  
     /**
 83  
      * Returns the accountId attribute.
 84  
      *
 85  
      * @return The accountId value.
 86  
      */
 87  
     public long getAccountId() {
 88  0
         return _accountId;
 89  
     }
 90  
 
 91  
     /**
 92  
      * Returns the amount attribute.
 93  
      *
 94  
      * @return The amount value.
 95  
      */
 96  
     public double getAmount() {
 97  172
         return _amount;
 98  
     }
 99  
 
 100  
     /**
 101  
      * Changes the value of the attributes createdBy.
 102  
      *
 103  
      * @param aCreatedBy The new value of the createdBy attribute.
 104  
      */
 105  
     protected void setCreatedBy(String aCreatedBy) {
 106  38
         _createdBy = aCreatedBy;
 107  38
     }
 108  
 
 109  
     /**
 110  
      * Returns the createdBy attribute.
 111  
      *
 112  
      * @return The createdBy value.
 113  
      */
 114  
     public String getCreatedBy() {
 115  102
         return _createdBy;
 116  
     }
 117  
 
 118  
     /**
 119  
      * Returns the creationDate attribute.
 120  
      *
 121  
      * @return The creationDate value.
 122  
      */
 123  
     public Date getCreationDate() {
 124  102
         return _creationDate;
 125  
     }
 126  
 
 127  
     /* (non-Javadoc)
 128  
     * @see java.lang.Object#toString()
 129  
     */
 130  
 
 131  
     public String toString() {
 132  280
         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
 133  140
                 append("id", _id).
 134  140
                 append("type", _type).
 135  140
                 append("accountId", _accountId).
 136  140
                 append("amount", _amount).
 137  140
                 append("createdBy", _createdBy).
 138  140
                 append("creationDate", new Timestamp(_creationDate.getTime())).
 139  140
                 toString();
 140  
     }
 141  
 
 142  
 }