Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 242   Methods: 24
NCLOC: 177   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Person.java 47.4% 62.7% 87.5% 62.8%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.pojo.test;
 8   
 9    import java.util.ArrayList;
 10    import java.util.Iterator;
 11    import java.util.List;
 12    import java.util.Map;
 13    import java.util.Set;
 14   
 15   
 16    /**
 17    * Test class for PojoCache.
 18    * Person is a POJO that will be instrumented with CacheFieldInterceptor
 19    *
 20    * @version $Revision: 1.3 $
 21    * <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
 22    * conjunction with a special jboss-aop.xml (supplied by PojoCache). In addition, this is JDK1.4 style,
 23    * so a annoc Ant build target is needed to pre-compile it.</p>
 24    * <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
 25    */
 26    // We are using JDK1.5 annotation.
 27    @org.jboss.cache.pojo.annotation.Replicable
 28    public class Person
 29    {
 30    private String name = null;
 31    private int age = 0;
 32    private Map<String, String> hobbies = null;
 33    private Address address = null;
 34    private Set<String> skills;
 35    private List<String> languages;
 36    // Test for transient field non-replication
 37    private transient String currentStatus = "Active";
 38    // Test swapping out the Collection ref with proxy one
 39    // medication will be different when age limit is exceeded.
 40    private List<String> medication = null;
 41    private static final int AGE1 = 50;
 42    private static final int AGE2 = 60;
 43   
 44  1489 public Person()
 45    {
 46   
 47    }
 48   
 49  92 public String getName()
 50    {
 51  92 return name;
 52    }
 53   
 54  1427 public void setName(String name)
 55    {
 56  1427 this.name = name;
 57    }
 58   
 59  3 public void setCurrentStatus(String status)
 60    {
 61  3 currentStatus = status;
 62    }
 63   
 64  6 public String getCurrentStatus()
 65    {
 66  6 return currentStatus;
 67    }
 68   
 69  0 public void setName(Object obj)
 70    {
 71  0 this.name = (String) obj;
 72    }
 73   
 74  47 public int getAge()
 75    {
 76  47 return age;
 77    }
 78   
 79  1422 public void setAge(int age)
 80    {
 81   
 82  1422 this.age = age;
 83   
 84    // This will swap out the reference dynamically
 85  1421 if (age < AGE1)
 86    {
 87  981 if (medication != null)
 88    {
 89  0 medication.clear();
 90  0 medication = null;
 91    }
 92    } else
 93    {
 94  440 if (age >= AGE1)
 95    {
 96  440 addMedication("Lipitor");
 97    }
 98   
 99  440 if (age >= AGE2)
 100    {
 101  12 addMedication("Vioxx");
 102    }
 103    }
 104   
 105   
 106    }
 107   
 108  452 void addMedication(String name)
 109    {
 110  452 if (medication == null)
 111  437 medication = new ArrayList();
 112  452 if (!medication.contains(name))
 113  446 medication.add(name);
 114    }
 115   
 116  33 public Map<String, String> getHobbies()
 117    {
 118  33 return hobbies;
 119    }
 120   
 121  13 public void setHobbies(Map hobbies)
 122    {
 123  13 this.hobbies = hobbies;
 124    }
 125   
 126  116 public Address getAddress()
 127    {
 128  116 return address;
 129    }
 130   
 131  922 public void setAddress(Address address)
 132    {
 133  922 this.address = address;
 134    }
 135   
 136  15 public Set<String> getSkills()
 137    {
 138  15 return skills;
 139    }
 140   
 141  35 public void setSkills(Set skills)
 142    {
 143  35 this.skills = skills;
 144    }
 145   
 146  16 public List<String> getMedication()
 147    {
 148  16 return medication;
 149    }
 150   
 151  0 public void setMedication(List medication)
 152    {
 153  0 this.medication = medication;
 154    }
 155   
 156  62 public List<String> getLanguages()
 157    {
 158  62 return languages;
 159    }
 160   
 161  1034 public void setLanguages(List<String> languages)
 162    {
 163  1034 this.languages = languages;
 164    }
 165   
 166  4 public String toString()
 167    {
 168  4 StringBuffer sb = new StringBuffer();
 169  4 sb.append("name=").append(getName()).append(", age=").append(getAge()).append(", hobbies=")
 170    .append(print(getHobbies())).append(", address=").append(getAddress()).append(", skills=")
 171    .append(skills).append(", languages=").append(languages).toString();
 172  4 if (medication != null)
 173  0 sb.append(", medication=" + medication);
 174  4 return sb.toString();
 175    }
 176   
 177  28 private static boolean equals(Object o1, Object o2)
 178    {
 179  28 if (o1 == o2)
 180  20 return true;
 181   
 182  8 if (o1 == null || o2 == null)
 183  0 return false;
 184   
 185  8 return o1.equals(o2);
 186    }
 187   
 188  38 public boolean equals(Object o)
 189    {
 190  38 if (! (o instanceof Person))
 191  0 return false;
 192   
 193  38 if (o == this)
 194  34 return true;
 195   
 196  4 Person other = (Person) o;
 197  4 return other.age == age && equals(other.name, name) && equals(other.hobbies, hobbies) && equals(other.address, address)
 198    && equals(other.skills, skills) && equals(other.languages, languages) && equals(other.currentStatus, currentStatus)
 199    && equals(other.medication, medication);
 200    }
 201   
 202  0 public int hashCode()
 203    {
 204  0 int result = 629 * name.hashCode() * 37 * age;
 205   
 206  0 if (hobbies != null)
 207  0 result = 37 * result + hobbies.hashCode();
 208   
 209  0 if (address != null)
 210  0 result = 37 * result + address.hashCode();
 211   
 212  0 if (skills != null)
 213  0 result = 37 * result + skills.hashCode();
 214   
 215  0 if (languages != null)
 216  0 result = 37 * result + languages.hashCode();
 217   
 218  0 if (currentStatus != null)
 219  0 result = 37 * result + currentStatus.hashCode();
 220   
 221  0 if (medication != null)
 222  0 result = 37 * medication.hashCode();
 223   
 224  0 return result;
 225    }
 226   
 227  4 public String print(Map m)
 228    {
 229  4 StringBuffer sb = new StringBuffer();
 230  4 Map.Entry entry;
 231  4 if (m != null)
 232    {
 233  0 for (Iterator it = m.entrySet().iterator(); it.hasNext();)
 234    {
 235  0 entry = (Map.Entry) it.next();
 236  0 sb.append(entry.getKey()).append(": ").append(entry.getValue());
 237  0 sb.append("\n");
 238    }
 239    }
 240  4 return sb.toString();
 241    }
 242    }