1
1
package org .owasp .esapi .codecs ;
2
2
3
+ import static org .junit .Assert .assertEquals ;
4
+
3
5
import java .util .Arrays ;
4
6
5
- import org .junit .Assert ;
6
7
import org .junit .Test ;
7
8
import org .junit .runner .RunWith ;
8
9
import org .junit .runners .Parameterized ;
9
- import org .owasp .esapi .codecs .Codec ;
10
- import org .owasp .esapi .codecs .PushbackString ;
11
10
12
11
13
12
/**
14
- * FIXME: Document intent of class. General Function, purpose of creation, intended feature, etc.
15
- * Why do people care this exists?
16
- * @author Jeremiah
17
- * @since Jan 20, 2018
18
- *
13
+ * Abstract parameterized test case meant to assist with verifying Character api of a Codec implementation.
14
+ * <br/>
15
+ * Sub-classes are expected to provide instances of {@link CodecCharacterTestTuple} to this instance.
16
+ * <br/>
17
+ * For better test naming output specify {@link CodecCharacterTestTuple#description} and use {@code} @Parameters (name="{0}")},
18
+ * where '0' is the index that the CodecCharacterTestTuple reference appears in the constructor.
19
19
*/
20
20
@ RunWith (Parameterized .class )
21
21
public abstract class AbstractCodecCharacterTest {
22
22
23
+ /** Test Data Tuple.*/
23
24
protected static class CodecCharacterTestTuple {
25
+ /** Codec reference to be tested.*/
24
26
Codec codec ;
27
+ /** Set of characters that should be considered 'immune' from decoding processes.*/
25
28
char [] encodeImmune ;
29
+ /** A String representing a single encoded character.*/
26
30
String input ;
31
+ /** The single character that input represents.*/
27
32
Character decodedValue ;
33
+ /** Optional field to override the toString value of this tuple. */
28
34
String description ;
29
35
/** {@inheritDoc}*/
30
36
@@ -46,27 +52,34 @@ public AbstractCodecCharacterTest(CodecCharacterTestTuple tuple) {
46
52
this .decodedValue = tuple .decodedValue ;
47
53
this .encodeImmune = tuple .encodeImmune ;
48
54
}
49
-
55
+
56
+ /** Checks that the input value matches the result of the codec encoding the decoded value. */
50
57
@ Test
51
58
public void testEncodeCharacter () {
52
- Assert . assertEquals (input , codec .encodeCharacter (encodeImmune , decodedValue ));
59
+ assertEquals (input , codec .encodeCharacter (encodeImmune , decodedValue ));
53
60
}
54
61
62
+ /** Checks encoding the character as a String.
63
+ * <br/>
64
+ * If the decoded value is in the immunity list, the the decoded value should be returned from the encode call.
65
+ * Otherwise, input is expected as the return.
66
+ */
55
67
@ Test
56
68
public void testEncode () {
57
69
String expected = Arrays .asList (encodeImmune ).contains (decodedValue ) ? decodedValue .toString () : input ;
58
- Assert . assertEquals (expected , codec .encode (encodeImmune , decodedValue .toString ()));
70
+ assertEquals (expected , codec .encode (encodeImmune , decodedValue .toString ()));
59
71
}
60
72
73
+ /** Checks that decoding the input value yeilds the decodedValue.*/
61
74
@ Test
62
75
public void testDecode () {
63
- Assert . assertEquals (decodedValue .toString (), codec .decode (input ));
76
+ assertEquals (decodedValue .toString (), codec .decode (input ));
64
77
}
65
78
66
-
79
+ /** Checks that the encoded input String is correctly decoded to the single decodedValue character reference.*/
67
80
@ Test
68
81
public void testDecodePushbackSequence () {
69
- Assert . assertEquals (decodedValue , codec .decodeCharacter (new PushbackString (input )));
82
+ assertEquals (decodedValue , codec .decodeCharacter (new PushbackString (input )));
70
83
}
71
84
72
85
}
0 commit comments