~ubuntu-branches/ubuntu/trusty/commons-beanutils/trusty

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/beanutils/TestBean.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2002-02-16 23:17:39 UTC
  • Revision ID: james.westby@ubuntu.com-20020216231739-eha35b05fam940p6
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v 1.4 2001/09/03 17:34:36 craigmcc Exp $
 
3
 * $Revision: 1.4 $
 
4
 * $Date: 2001/09/03 17:34:36 $
 
5
 *
 
6
 * ====================================================================
 
7
 *
 
8
 * The Apache Software License, Version 1.1
 
9
 *
 
10
 * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
 
11
 * reserved.
 
12
 *
 
13
 * Redistribution and use in source and binary forms, with or without
 
14
 * modification, are permitted provided that the following conditions
 
15
 * are met:
 
16
 *
 
17
 * 1. Redistributions of source code must retain the above copyright
 
18
 *    notice, this list of conditions and the following disclaimer.
 
19
 *
 
20
 * 2. Redistributions in binary form must reproduce the above copyright
 
21
 *    notice, this list of conditions and the following disclaimer in
 
22
 *    the documentation and/or other materials provided with the
 
23
 *    distribution.
 
24
 *
 
25
 * 3. The end-user documentation included with the redistribution, if
 
26
 *    any, must include the following acknowlegement:
 
27
 *       "This product includes software developed by the
 
28
 *        Apache Software Foundation (http://www.apache.org/)."
 
29
 *    Alternately, this acknowlegement may appear in the software itself,
 
30
 *    if and wherever such third-party acknowlegements normally appear.
 
31
 *
 
32
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 
33
 *    Foundation" must not be used to endorse or promote products derived
 
34
 *    from this software without prior written permission. For written
 
35
 *    permission, please contact apache@apache.org.
 
36
 *
 
37
 * 5. Products derived from this software may not be called "Apache"
 
38
 *    nor may "Apache" appear in their names without prior written
 
39
 *    permission of the Apache Group.
 
40
 *
 
41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 
42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
52
 * SUCH DAMAGE.
 
53
 * ====================================================================
 
54
 *
 
55
 * This software consists of voluntary contributions made by many
 
56
 * individuals on behalf of the Apache Software Foundation.  For more
 
57
 * information on the Apache Software Foundation, please see
 
58
 * <http://www.apache.org/>.
 
59
 *
 
60
 */
 
61
 
 
62
 
 
63
package org.apache.commons.beanutils;
 
64
 
 
65
 
 
66
import java.util.HashMap;
 
67
 
 
68
 
 
69
/**
 
70
 * General purpose test bean for JUnit tests for the "beanutils" component.
 
71
 *
 
72
 * @author Craig R. McClanahan
 
73
 * @version $Revision: 1.4 $ $Date: 2001/09/03 17:34:36 $
 
74
 */
 
75
 
 
76
public class TestBean {
 
77
 
 
78
 
 
79
    // ------------------------------------------------------------- Properties
 
80
 
 
81
 
 
82
    /**
 
83
     * A boolean property.
 
84
     */
 
85
    private boolean booleanProperty = true;
 
86
 
 
87
    public boolean getBooleanProperty() {
 
88
        return (booleanProperty);
 
89
    }
 
90
 
 
91
    public void setBooleanProperty(boolean booleanProperty) {
 
92
        this.booleanProperty = booleanProperty;
 
93
    }
 
94
 
 
95
 
 
96
    /**
 
97
     * A boolean property that uses an "is" method for the getter.
 
98
     */
 
99
    private boolean booleanSecond = true;
 
100
 
 
101
    public boolean isBooleanSecond() {
 
102
        return (booleanSecond);
 
103
    }
 
104
 
 
105
    public void setBooleanSecond(boolean booleanSecond) {
 
106
        this.booleanSecond = booleanSecond;
 
107
    }
 
108
 
 
109
 
 
110
    /**
 
111
     * A double property.
 
112
     */
 
113
    private double doubleProperty = 321.0;
 
114
 
 
115
    public double getDoubleProperty() {
 
116
        return (this.doubleProperty);
 
117
    }
 
118
 
 
119
    public void setDoubleProperty(double doubleProperty) {
 
120
        this.doubleProperty = doubleProperty;
 
121
    }
 
122
 
 
123
 
 
124
    /**
 
125
     * A float property.
 
126
     */
 
127
    private float floatProperty = (float) 123.0;
 
128
 
 
129
    public float getFloatProperty() {
 
130
        return (this.floatProperty);
 
131
    }
 
132
 
 
133
    public void setFloatProperty(float floatProperty) {
 
134
        this.floatProperty = floatProperty;
 
135
    }
 
136
 
 
137
 
 
138
    /**
 
139
     * An integer array property accessed as an array.
 
140
     */
 
141
    private int intArray[] = { 0, 10, 20, 30, 40 };
 
142
 
 
143
    public int[] getIntArray() {
 
144
        return (this.intArray);
 
145
    }
 
146
 
 
147
    public void setIntArray(int intArray[]) {
 
148
        this.intArray = intArray;
 
149
    }
 
150
 
 
151
 
 
152
    /**
 
153
     * An integer array property accessed as an indexed property.
 
154
     */
 
155
    private int intIndexed[] = { 0, 10, 20, 30, 40 };
 
156
 
 
157
    public int getIntIndexed(int index) {
 
158
        return (intIndexed[index]);
 
159
    }
 
160
 
 
161
    public void setIntIndexed(int index, int value) {
 
162
        intIndexed[index] = value;
 
163
    }
 
164
 
 
165
 
 
166
    /**
 
167
     * An integer property.
 
168
     */
 
169
    private int intProperty = 123;
 
170
 
 
171
    public int getIntProperty() {
 
172
        return (this.intProperty);
 
173
    }
 
174
 
 
175
    public void setIntProperty(int intProperty) {
 
176
        this.intProperty = intProperty;
 
177
    }
 
178
 
 
179
 
 
180
    /**
 
181
     * A long property.
 
182
     */
 
183
    private long longProperty = 321;
 
184
 
 
185
    public long getLongProperty() {
 
186
        return (this.longProperty);
 
187
    }
 
188
 
 
189
    public void setLongProperty(long longProperty) {
 
190
        this.longProperty = longProperty;
 
191
    }
 
192
 
 
193
 
 
194
    /**
 
195
     * A mapped property that has String keys and String values.
 
196
     */
 
197
    private HashMap mappedProperty = null;
 
198
 
 
199
    public String getMappedProperty(String key) {
 
200
        // Create the map the very first time
 
201
        if (mappedProperty == null) {
 
202
            mappedProperty = new HashMap();
 
203
            mappedProperty.put("First Key", "First Value");
 
204
            mappedProperty.put("Second Key", "Second Value");
 
205
        }
 
206
        return ((String) mappedProperty.get(key));
 
207
    }
 
208
 
 
209
    public void setMappedProperty(String key, String value) {
 
210
        mappedProperty.put(key, value);
 
211
    }
 
212
 
 
213
 
 
214
    /**
 
215
     * A mapped property that has String keys and int values.
 
216
     */
 
217
    private HashMap mappedIntProperty = null;
 
218
 
 
219
    public int getMappedIntProperty(String key) {
 
220
        // Create the map the very first time
 
221
        if (mappedProperty == null) {
 
222
            mappedProperty = new HashMap();
 
223
            mappedProperty.put("One", new Integer(1));
 
224
            mappedProperty.put("Two", new Integer(2));
 
225
        }
 
226
        Integer x = (Integer) mappedIntProperty.get(key);
 
227
        return ((x == null) ? 0 : x.intValue());
 
228
    }
 
229
 
 
230
    public void setMappedIntProperty(String key, int value) {
 
231
        mappedIntProperty.put(key, new Integer(value));
 
232
    }
 
233
 
 
234
 
 
235
    /**
 
236
     * A nested reference to another test bean (populated as needed).
 
237
     */
 
238
    private TestBean nested = null;
 
239
 
 
240
    public TestBean getNested() {
 
241
        if (nested == null)
 
242
            nested = new TestBean();
 
243
        return (nested);
 
244
    }
 
245
 
 
246
 
 
247
    /**
 
248
     * A String property with an initial value of null.
 
249
     */
 
250
    private String nullProperty = null;
 
251
 
 
252
    public String getNullProperty() {
 
253
        return (this.nullProperty);
 
254
    }
 
255
 
 
256
    public void setNullProperty(String nullProperty) {
 
257
        this.nullProperty = nullProperty;
 
258
    }
 
259
 
 
260
 
 
261
    /**
 
262
     * A read-only String property.
 
263
     */
 
264
    private String readOnlyProperty = "Read Only String Property";
 
265
 
 
266
    public String getReadOnlyProperty() {
 
267
        return (this.readOnlyProperty);
 
268
    }
 
269
 
 
270
 
 
271
    /**
 
272
     * A short property.
 
273
     */
 
274
    private short shortProperty = (short) 987;
 
275
 
 
276
    public short getShortProperty() {
 
277
        return (this.shortProperty);
 
278
    }
 
279
 
 
280
    public void setShortProperty(short shortProperty) {
 
281
        this.shortProperty = shortProperty;
 
282
    }
 
283
 
 
284
 
 
285
    /**
 
286
     * A String array property accessed as a String.
 
287
     */
 
288
    private String stringArray[] =
 
289
    { "String 0", "String 1", "String 2", "String 3", "String 4" };
 
290
 
 
291
    public String[] getStringArray() {
 
292
        return (this.stringArray);
 
293
    }
 
294
 
 
295
    public void setStringArray(String stringArray[]) {
 
296
        this.stringArray = stringArray;
 
297
    }
 
298
 
 
299
 
 
300
    /**
 
301
     * A String array property accessed as an indexed property.
 
302
     */
 
303
    private String stringIndexed[] =
 
304
    { "String 0", "String 1", "String 2", "String 3", "String 4" };
 
305
 
 
306
    public String getStringIndexed(int index) {
 
307
        return (stringIndexed[index]);
 
308
    }
 
309
 
 
310
    public void setStringIndexed(int index, String value) {
 
311
        stringIndexed[index] = value;
 
312
    }
 
313
 
 
314
 
 
315
    /**
 
316
     * A String property.
 
317
     */
 
318
    private String stringProperty = "This is a string";
 
319
 
 
320
    public String getStringProperty() {
 
321
        return (this.stringProperty);
 
322
    }
 
323
 
 
324
    public void setStringProperty(String stringProperty) {
 
325
        this.stringProperty = stringProperty;
 
326
    }
 
327
 
 
328
 
 
329
    /**
 
330
     * A write-only String property.
 
331
     */
 
332
    private String writeOnlyProperty = "Write Only String Property";
 
333
 
 
334
    public String getWriteOnlyPropertyValue() {
 
335
        return (this.writeOnlyProperty);
 
336
    }
 
337
 
 
338
    public void setWriteOnlyProperty(String writeOnlyProperty) {
 
339
        this.writeOnlyProperty = writeOnlyProperty;
 
340
    }
 
341
 
 
342
 
 
343
}