Skip to content

Commit d442757

Browse files
AbstractCodecCharacterTest Cleanup
Adding documentation. Updating static imports.
1 parent c4d77b1 commit d442757

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
package org.owasp.esapi.codecs;
22

3+
import static org.junit.Assert.assertEquals;
4+
35
import java.util.Arrays;
46

5-
import org.junit.Assert;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
89
import org.junit.runners.Parameterized;
9-
import org.owasp.esapi.codecs.Codec;
10-
import org.owasp.esapi.codecs.PushbackString;
1110

1211

1312
/**
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.
1919
*/
2020
@RunWith(Parameterized.class)
2121
public abstract class AbstractCodecCharacterTest {
2222

23+
/** Test Data Tuple.*/
2324
protected static class CodecCharacterTestTuple {
25+
/** Codec reference to be tested.*/
2426
Codec codec;
27+
/** Set of characters that should be considered 'immune' from decoding processes.*/
2528
char[] encodeImmune;
29+
/** A String representing a single encoded character.*/
2630
String input;
31+
/** The single character that input represents.*/
2732
Character decodedValue;
33+
/** Optional field to override the toString value of this tuple. */
2834
String description;
2935
/** {@inheritDoc}*/
3036

@@ -46,27 +52,34 @@ public AbstractCodecCharacterTest(CodecCharacterTestTuple tuple) {
4652
this.decodedValue = tuple.decodedValue;
4753
this.encodeImmune = tuple.encodeImmune;
4854
}
49-
55+
56+
/** Checks that the input value matches the result of the codec encoding the decoded value. */
5057
@Test
5158
public void testEncodeCharacter() {
52-
Assert.assertEquals(input, codec.encodeCharacter(encodeImmune, decodedValue));
59+
assertEquals(input, codec.encodeCharacter(encodeImmune, decodedValue));
5360
}
5461

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+
*/
5567
@Test
5668
public void testEncode() {
5769
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()));
5971
}
6072

73+
/** Checks that decoding the input value yeilds the decodedValue.*/
6174
@Test
6275
public void testDecode() {
63-
Assert.assertEquals(decodedValue.toString(), codec.decode(input));
76+
assertEquals(decodedValue.toString(), codec.decode(input));
6477
}
6578

66-
79+
/** Checks that the encoded input String is correctly decoded to the single decodedValue character reference.*/
6780
@Test
6881
public void testDecodePushbackSequence() {
69-
Assert.assertEquals(decodedValue, codec.decodeCharacter(new PushbackString(input)));
82+
assertEquals(decodedValue, codec.decodeCharacter(new PushbackString(input)));
7083
}
7184

7285
}

0 commit comments

Comments
 (0)