KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > openwire > tool > TestDataGenerator


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.openwire.tool;
19
20 /**
21  * A simple helper class to help auto-generate test data when code generating test cases
22  *
23  * @version $Revision: 1.1 $
24  */

25 public class TestDataGenerator {
26     private int stringCounter;
27
28     private boolean boolCounter;
29     private byte byteCounter;
30     private char charCounter = 'a';
31     private short shortCounter;
32     private int intCounter;
33     private long longCounter;
34     
35     public String JavaDoc createByte() {
36         return "(byte) " + (++byteCounter);
37     }
38     
39     public String JavaDoc createChar() {
40         return "'" + (charCounter++) + "'";
41     }
42     
43     public String JavaDoc createShort() {
44         return "(short) " + (++shortCounter);
45     }
46
47     public int createInt() {
48         return ++intCounter;
49     }
50
51     public long createLong() {
52         return ++longCounter;
53     }
54
55     public String JavaDoc createString(String JavaDoc property) {
56         return property + ":" + (++stringCounter);
57     }
58
59     public boolean createBool() {
60         boolCounter = !boolCounter;
61         return boolCounter;
62     }
63     
64     public String JavaDoc createByteArray(String JavaDoc property) {
65         return "\"" + createString(property) + "\".getBytes()";
66     }
67 }
68
Popular Tags