();
validators.add(nameValidator);
table.setValidators(validators);
transformer.output(table);
BufferedReader reader = new BufferedReader(new StringReader(writer.toString()));
dumpOutput();
assertHasPreamble(reader);
assertEquals("", reader.readLine());
assertEquals(" ", reader.readLine());
skipUntilEnd(" {column}", reader);
skipUntilEnd(" {column}", reader);
assertEquals(" ", reader.readLine());
skipUntilEnd(" {primarykey}", reader);
assertEquals(" ", reader.readLine());
skipUntilEnd(" {foreignkey}", reader);
skipUntilEnd(" {foreignkey}", reader);
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
skipUntilEnd(" {index}", reader);
skipUntilEnd(" {index}", reader);
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals(" match_me_if_you_can", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals(" ", reader.readLine());
assertEquals("
", reader.readLine());
}
/**
* Ignore lines that are tested elsewhere, e.g. ignore serialized Column objects
* in the context of a Table since we only need to know that there was text for a
* Column object in the right place - the actual Column text being tested in its own test.
*
* Leading and trailing spaces are ignored in the comparison.
*
* @param textToFind
* @param reader
*/
private void skipUntilEnd(String textToFind, BufferedReader reader, boolean emptyTag)
{
// To aid test code clarity, and distinguish between text we're actually
// testing for and text that needs to be ignored...
// {mytag} becomes
// or if an empty tag is expected
// {mytag} becomes
if (emptyTag)
{
textToFind = textToFind.trim().
replace("{", "<").
replace("}", "\\s+.*/>");
}
else
{
textToFind = textToFind.trim().
replace("{", "").
replace("}", ">");
}
try
{
String line;
while ((line = reader.readLine()) != null)
{
if (line.trim().matches(textToFind))
{
return;
}
}
fail("Unable to find text: " + textToFind);
}
catch (IOException error)
{
throw new RuntimeException("Unable to skip text whilst looking for: " + textToFind, error);
}
}
private void skipUntilEnd(String textToFind, BufferedReader reader)
{
skipUntilEnd(textToFind, reader, false);
}
private void assertHasPreamble(BufferedReader reader) throws IOException
{
assertEquals("", reader.readLine());
}
private void dumpOutput()
{
if (outputDumpEnabled)
{
System.out.println(writer.toString());
}
}
}