View Javadoc
1   package net.sourceforge.pmd.properties;
2   
3   import net.sourceforge.pmd.PropertyDescriptor;
4   import net.sourceforge.pmd.lang.rule.properties.CharacterMultiProperty;
5   import net.sourceforge.pmd.lang.rule.properties.CharacterProperty;
6   
7   import org.junit.Test;
8   
9   /**
10   * Evaluates the functionality of the CharacterProperty descriptor by testing
11   * its ability to catch creation errors (illegal args), flag invalid characters,
12   * and serialize/deserialize any default values.
13   * 
14   * @author Brian Remedios
15   */
16  public class CharacterPropertyTest extends AbstractPropertyDescriptorTester {
17  
18      private static final char delimiter = '|';
19      private static final char[] charSet = filter(allChars.toCharArray(), delimiter);
20  
21      public CharacterPropertyTest() {
22          super("Character");
23      }
24  
25      /**
26       * Method createValue.
27       * 
28       * @param count int
29       * @return Object
30       */
31      protected Object createValue(int count) {
32  
33          if (count == 1)
34              return new Character(randomChar(charSet));
35  
36          Character[] values = new Character[count];
37          for (int i = 0; i < values.length; i++)
38              values[i] = (Character) createValue(1);
39          return values;
40      }
41  
42      /**
43       * Method createBadValue.
44       * 
45       * @param count int
46       * @return Object
47       */
48      protected Object createBadValue(int count) {
49  
50          if (count == 1)
51              return null;
52  
53          Character[] values = new Character[count];
54          for (int i = 0; i < values.length; i++)
55              values[i] = (Character) createBadValue(1);
56          return values;
57      }
58  
59      @Test
60      public void testErrorForBad() {
61      } // not until char properties use illegal chars
62  
63      /**
64       * Method createProperty.
65       * 
66       * @param multiValue boolean
67       * @return PropertyDescriptor
68       */
69      protected PropertyDescriptor createProperty(boolean multiValue) {
70  
71          return multiValue ? new CharacterMultiProperty("testCharacter", "Test character property", new Character[] {
72                  'a', 'b', 'c' }, 1.0f, delimiter) : new CharacterProperty("testCharacter", "Test character property",
73                  'a', 1.0f);
74      }
75  
76      /**
77       * Creates a bad property that is missing either its name or description or
78       * includes a delimiter in the set of legal values.
79       * 
80       * @param multiValue boolean
81       * @return PropertyDescriptor
82       */
83      protected PropertyDescriptor createBadProperty(boolean multiValue) {
84  
85          return multiValue ? new CharacterMultiProperty("testCharacter", "Test character property", new Character[] {
86                  'a', 'b', 'c' }, 1.0f, delimiter) : new CharacterProperty("", "Test character property", 'a', 1.0f);
87      }
88  }