1   package test.net.sourceforge.pmd.properties;
2   
3   import net.sourceforge.pmd.PropertyDescriptor;
4   import net.sourceforge.pmd.properties.StringProperty;
5   
6   /**
7    */
8   public class StringPropertyTest extends AbstractPropertyDescriptorTester {
9   
10  	private static final int maxStringLength = 52;
11  	private static final char delimiter = '|';
12  	private static final char[] charSet = filter(allChars.toCharArray(), delimiter);
13  	
14  	public StringPropertyTest() {
15  		super();
16  	}
17  	
18  	/**
19  	 * Method createValue.
20  	 * @param count int
21  	 * @return Object
22  	 */
23  	protected Object createValue(int count) {
24  
25  		if (count == 1) return newString();
26  		
27  		String[] values = new String[count];
28  		for (int i=0; i<count; i++) values[i] = (String)createValue(1);
29  		return values;
30  	}
31  
32  	/**
33  	 * Method newString.
34  	 * @return String
35  	 */
36  	private String newString() {
37  		
38  		int strLength = randomInt(0, maxStringLength);
39  		
40  		char[] chars = new char[strLength];
41  		for (int i=0; i<chars.length; i++) chars[i] = randomCharIn(charSet);
42  		return new String(chars);
43  	}
44  	
45  	/**
46  	 * Method randomCharIn.
47  	 * @param chars char[]
48  	 * @return char
49  	 */
50  	private char randomCharIn(char[] chars) {
51  		return randomChar(chars);
52  	}
53  	
54  	/**
55  	 * Method createProperty.
56  	 * @param maxCount int
57  	 * @return PropertyDescriptor
58  	 */
59  	protected PropertyDescriptor createProperty(int maxCount) {
60  		return maxCount == 1 ?
61  			new StringProperty("testString", "Test string property", "brian", 1.0f) :
62  			new StringProperty("testString", "Test string property", new String[] {"hello", "world"}, 1.0f, delimiter);
63  		}
64  
65  
66      public static junit.framework.Test suite() {
67          return new junit.framework.JUnit4TestAdapter(StringPropertyTest.class);
68      }
69  }