Coverage Report - org.mule.samples.voipservice.to.CustomerTO
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomerTO
0%
0/54
0%
0/5
1.462
 
 1  
 /*
 2  
  * $Id: CustomerTO.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.samples.voipservice.to;
 12  
 
 13  
 import org.mule.samples.voipservice.LocaleMessage;
 14  
 
 15  
 import java.io.Serializable;
 16  
 import java.util.ArrayList;
 17  
 import java.util.List;
 18  
 
 19  
 /**
 20  
  * @author Binildas Christudas
 21  
  */
 22  
 public class CustomerTO implements Serializable, Cloneable
 23  
 {
 24  
     /**
 25  
      * Serial version
 26  
      */
 27  
     private static final long serialVersionUID = -7760891283901332894L;
 28  
 
 29  
     private String firstName;
 30  
     private String lastName;
 31  
     private AddressTO addressTO;
 32  
 
 33  
     private static final List CUSTOMERS;
 34  
 
 35  
     static
 36  
     {
 37  0
         CUSTOMERS = new ArrayList();
 38  
 
 39  0
         CUSTOMERS.add(new CustomerTO("Binil", "Das"));
 40  0
         CUSTOMERS.add(new CustomerTO("Rajesh", "Warrier"));
 41  0
         CUSTOMERS.add(new CustomerTO("Jacob", "Oommen"));
 42  0
         CUSTOMERS.add(new CustomerTO("Shahanas", "Mohammed"));
 43  0
         CUSTOMERS.add(new CustomerTO("Sowmya", "Hubert"));
 44  0
         CUSTOMERS.add(new CustomerTO("Ann", "Binil"));
 45  0
         CUSTOMERS.add(new CustomerTO("Rajesh", "Ravindran"));
 46  0
         CUSTOMERS.add(new CustomerTO("Renjit", "Hubert"));
 47  0
         CUSTOMERS.add(new CustomerTO("Brijesh", "Deb"));
 48  0
         CUSTOMERS.add(new CustomerTO("Rama", "Varma"));
 49  0
     }
 50  
 
 51  
     public CustomerTO()
 52  
     {
 53  0
         super();
 54  0
     }
 55  
 
 56  
     public CustomerTO(String firstName, String lastName)
 57  
     {
 58  0
         this(firstName, lastName, null);
 59  0
     }
 60  
 
 61  
     public CustomerTO(String firstName, String lastName, AddressTO addressTO)
 62  0
     {
 63  0
         this.firstName = firstName;
 64  0
         this.lastName = lastName;
 65  0
         this.addressTO = addressTO;
 66  0
     }
 67  
 
 68  
     public String getName()
 69  
     {
 70  
 
 71  0
         String name = firstName;
 72  0
         String lastName = null;
 73  0
         if (this.lastName == null)
 74  
         {
 75  0
             lastName = "";
 76  
         }
 77  
         else
 78  
         {
 79  0
             lastName = this.lastName;
 80  
         }
 81  0
         return name + " " + lastName;
 82  
     }
 83  
 
 84  
     public void setFirstName(String firstName)
 85  
     {
 86  0
         this.firstName = firstName;
 87  0
     }
 88  
 
 89  
     public String getFirstName()
 90  
     {
 91  0
         return firstName;
 92  
     }
 93  
 
 94  
     public void setLastName(String lastName)
 95  
     {
 96  0
         this.lastName = lastName;
 97  0
     }
 98  
 
 99  
     public String getLastName()
 100  
     {
 101  0
         return lastName;
 102  
     }
 103  
 
 104  
     public void setAddress(AddressTO addressTO)
 105  
     {
 106  0
         this.addressTO = addressTO;
 107  0
     }
 108  
 
 109  
     public AddressTO getAddress()
 110  
     {
 111  0
         return addressTO;
 112  
     }
 113  
 
 114  
     public Object clone()
 115  
     {
 116  0
         Object clone = null;
 117  
         try
 118  
         {
 119  0
             clone = super.clone();
 120  0
             if (null != addressTO)
 121  
             {
 122  0
                 ((CustomerTO)clone).setAddress((AddressTO)addressTO.clone());
 123  
             }
 124  
         }
 125  0
         catch (CloneNotSupportedException cloneNotSupportedException)
 126  
         {
 127  
             // too bad
 128  0
         }
 129  0
         return clone;
 130  
     }
 131  
 
 132  
     public String toString()
 133  
     {
 134  0
         StringBuffer stringBuffer = new StringBuffer();
 135  0
         if (this.firstName != null)
 136  
         {
 137  0
             stringBuffer.append(LocaleMessage.getFirstNameCaption(getName()));
 138  
         }
 139  0
         if (this.addressTO != null)
 140  
         {
 141  0
             stringBuffer.append(LocaleMessage.getAddressCaption(addressTO));
 142  
         }
 143  0
         return stringBuffer.toString();
 144  
     }
 145  
 
 146  
     public static CustomerTO getRandomCustomer()
 147  
     {
 148  
 
 149  0
         int index = new Double(Math.random() * 10).intValue();
 150  
         // AddressTO addressTO = (AddressTO) ADDRESSES.get(index);
 151  0
         CustomerTO customerTO = (CustomerTO)((CustomerTO)CUSTOMERS.get(index)).clone();
 152  0
         if (null == customerTO.getAddress())
 153  
         {
 154  0
             customerTO.setAddress(AddressTO.getRandomAddress());
 155  
         }
 156  0
         return customerTO;
 157  
     }
 158  
 
 159  
 }