|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SampleBean.java | 50% | 42.1% | 55.6% | 46.7% |
|
1 | /* | |
2 | * Copyright (c) 1998, 2005 Gargoyle Software Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are met: | |
6 | * | |
7 | * 1. Redistributions of source code must retain the above copyright notice, | |
8 | * this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
10 | * this list of conditions and the following disclaimer in the documentation | |
11 | * and/or other materials provided with the distribution. | |
12 | * 3. The end-user documentation included with the redistribution, if any, must | |
13 | * include the following acknowledgment: | |
14 | * | |
15 | * "This product includes software developed by Gargoyle Software Inc. | |
16 | * (http://www.GargoyleSoftware.com/)." | |
17 | * | |
18 | * Alternately, this acknowledgment may appear in the software itself, if | |
19 | * and wherever such third-party acknowledgments normally appear. | |
20 | * 4. The name "Gargoyle Software" must not be used to endorse or promote | |
21 | * products derived from this software without prior written permission. | |
22 | * For written permission, please contact info@GargoyleSoftware.com. | |
23 | * 5. Products derived from this software may not be called "GSBase", nor may | |
24 | * "GSBase" appear in their name, without prior written permission of | |
25 | * Gargoyle Software Inc. | |
26 | * | |
27 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |
28 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
29 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE | |
30 | * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
33 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
36 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | package com.gargoylesoftware.base.testing; | |
39 | ||
40 | import com.gargoylesoftware.base.util.DetailedNullPointerException; | |
41 | import java.beans.PropertyChangeListener; | |
42 | import java.beans.PropertyChangeSupport; | |
43 | import java.io.Serializable; | |
44 | ||
45 | /** | |
46 | * A simple bean class that can be used for testing purposes. All | |
47 | * properties fire PropertyChangeEvents when changed. | |
48 | * | |
49 | * @version $Revision: 1.4 $ | |
50 | * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> | |
51 | */ | |
52 | public class SampleBean implements Serializable { | |
53 | ||
54 | // Required for serialization - do not modify or remove. | |
55 | private static final long serialVersionUID = 2000; | |
56 | ||
57 | private final PropertyChangeSupport propertyChangeSupport_; | |
58 | ||
59 | private String name_; | |
60 | private int age_; | |
61 | ||
62 | /** | |
63 | * Create a new instance. | |
64 | */ | |
65 | 0 | public SampleBean() { |
66 | 0 | this( "", 0 ); |
67 | } | |
68 | ||
69 | /** | |
70 | * Create a new instance. | |
71 | * @param name The name. | |
72 | * @param age The age. | |
73 | */ | |
74 | 4 | public SampleBean( final String name, final int age ) { |
75 | 4 | propertyChangeSupport_ = new PropertyChangeSupport(this); |
76 | 4 | name_ = name; |
77 | 4 | age_ = age; |
78 | } | |
79 | ||
80 | /** | |
81 | * Add a property change listener | |
82 | * @param listener The listener | |
83 | */ | |
84 | 4 | public void addPropertyChangeListener( final PropertyChangeListener listener ) { |
85 | 4 | assertNotNull("listener", listener); |
86 | 4 | propertyChangeSupport_.addPropertyChangeListener(listener); |
87 | } | |
88 | ||
89 | /** | |
90 | * Remove a property change listener | |
91 | * @param listener The listener | |
92 | */ | |
93 | 0 | public void removePropertyChangeListener( final PropertyChangeListener listener ) { |
94 | 0 | assertNotNull("listener", listener); |
95 | 0 | propertyChangeSupport_.removePropertyChangeListener(listener); |
96 | } | |
97 | ||
98 | /** | |
99 | * Return the name. | |
100 | * @return The name | |
101 | */ | |
102 | 4 | public String getName() { |
103 | 4 | return name_; |
104 | } | |
105 | ||
106 | /** | |
107 | * Set the name. | |
108 | * @param name The new name. | |
109 | */ | |
110 | 0 | public void setName( final String name ) { |
111 | 0 | assertNotNull("name", name); |
112 | ||
113 | 0 | final String oldValue = name_; |
114 | 0 | name_ = name; |
115 | 0 | propertyChangeSupport_.firePropertyChange( "name", oldValue, name_ ); |
116 | } | |
117 | ||
118 | /** | |
119 | * Return the age. | |
120 | * @return The age. | |
121 | */ | |
122 | 4 | public int getAge() { |
123 | 4 | return age_; |
124 | } | |
125 | ||
126 | /** | |
127 | * Set the age. | |
128 | * @param age The new age. | |
129 | */ | |
130 | 0 | public void setAge( final int age ) { |
131 | ||
132 | 0 | final int oldValue = age_; |
133 | 0 | age_ = age; |
134 | 0 | propertyChangeSupport_.firePropertyChange( "age", oldValue, age_ ); |
135 | } | |
136 | ||
137 | ||
138 | /** | |
139 | * Verify that the specified value is not null. If it is then throw an exception | |
140 | * | |
141 | * @param fieldName The name of the field to check | |
142 | * @param fieldValue The value of the field to check | |
143 | * @exception DetailedNullPointerException If fieldValue is null | |
144 | */ | |
145 | 4 | protected final void assertNotNull( final String fieldName, final Object fieldValue ) |
146 | throws DetailedNullPointerException { | |
147 | ||
148 | 4 | if( fieldValue == null ) { |
149 | 0 | throw new DetailedNullPointerException(fieldName); |
150 | } | |
151 | } | |
152 | } | |
153 |
|