title: How to match text against templates in unit tests
body: <p>I have a class that consume an XML file and produce text output based on the input. Both the input and output are rather complex and the output can also include things <em>not</em> in the input: e.g. include timestamps and the results from live data that are not controlled by the input - with other words: the class is not a pure input-output transformation.</p>
  
  <p>I would like to test the resulting text output using JUnit. As the produced text can vary in many different ways based on the input, I would like to be able to match specific parts of the output against some sort of template in each test. Each template should allow for some simple text substitutions and also for ranges in the text that should <em>not</em> be matched.</p>
  
  <p>The question is whether any such frameworks already exists?</p>
  
  <p>One very low-level possibility would be to use some fancy regular expressions to match the text, but I think these will be a bit too limited for our use as you don't have enough context in regular expressions...</p>
  
  <p><strong>EDIT</strong>: Two comments:</p>
  
  <ul>
  <li>One of the functions of the class is the ability to do certain simple types of aggregation of data and calculations (e.g. sums) based on the input. This I would like to test, without testing the rest of the generated text output as well.</li>
  <li>I wish it was possible to make changes to the existing code base, but it is a very large chuck of legacy code that I really don't want to refactor. So introduction of mock services or testing of smaller pieces will not be possible.</li>
  </ul>