implements Testlet
{
public void test(TestHarness harness)
{
MaskFormatter formatter = null;
try
{
formatter = new MaskFormatter("RE'*B**KS");
// Default value checks
harness.checkPoint("defaults");
harness.check (formatter.getValueContainsLiteralCharacters());
harness.check (!formatter.getAllowsInvalid());
harness.check (formatter.getPlaceholder() == null);
harness.check (formatter.getPlaceholderCharacter() == ' ');
harness.check (formatter.getValidCharacters() == null);
harness.check (formatter.getInvalidCharacters() == null);
// Checks to see whether the appropriate characters are being used to pad
harness.checkPoint("padding");
formatter.setPlaceholder("MMMMMMMMM");
formatter.setPlaceholderCharacter('$');
harness.check (formatter.valueToString("RE"),"RE*BMMKS");
formatter.setPlaceholder("8");
harness.check (formatter.valueToString("RE"),"RE*B$$KS");
formatter.setPlaceholder("12345");
harness.check (formatter.valueToString("RE"),"RE*B5$KS");
// Checks to see if valid output is produced
harness.checkPoint("valid output");
formatter.setMask("(###) ###-####");
harness.check (formatter.valueToString("(555) 807-9090"),"(555) 807-9090");
harness.check (formatter.stringToValue("(555) 807-9090"),"(555) 807-9090");
formatter.setValueContainsLiteralCharacters(false);
harness.check (formatter.stringToValue("(555) 807-9090"),"5558079090");
boolean exception = false;
try
{
harness.check (formatter.valueToString("(555) 807-9090"),"(555) 807-9090");
}
catch (ParseException pe)
{
exception = true;
}
harness.check (exception);
// Checks to see if valid/invalid character sets work
formatter = new MaskFormatter("T##'FA");
formatter.setInvalidCharacters("T");
formatter.setValidCharacters("4");
harness.check(formatter.valueToString("T44F4"), "T44F4");
harness.check(formatter.stringToValue("T44F4"), "T44F4");
exception = false;
try
{
formatter.valueToString("T33F3");
}
catch (ParseException pe2)
{
exception = true;
}