Java Code Examples for org.apache.commons.lang3.StringUtils.difference()

The following are Jave code examples for showing how to use difference() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: myfaces-trinidad   File: ClirrRunnerTest.java   View Source Code Vote up 6 votes
public void testBinaryCompatibility()
{
  
  try
  {
    String golden = System.getProperty("trinidad.clirr.golden");
    String clirrRunResult = System.getProperty("trinidad.clirr.compare");

    String goldenFileContent = FileUtils.readFileToString(new File(golden));
    String clirrRunFileContent = FileUtils.readFileToString(new File(clirrRunResult));
    
    String binaryIssue = StringUtils.difference(goldenFileContent, clirrRunFileContent);
    
    if (binaryIssue.length() > 0)
    {
      fail("Check your binary compatibility! - See output in file: "  + clirrRunResult);
    }
  }
  catch (IOException e)
  {
    e.printStackTrace();
    fail(e.getMessage());
  }
}
 
Example 2
Project: myfaces-trinidad   File: RenderKitTestCase.java   View Source Code Vote up 4 votes
private void _throwAssertionFailure(String golden, String results, boolean forceGolden)
{
  if (golden == null)
  {
    // Don't report "no golden file" as an error when
    // forceGolden is on; but do report diffs as errors
    if (!forceGolden)
    {
      throw new AssertionFailedError("No golden file for test " +
                                     _scriptName);
    }
  } else
  {
    int index = StringUtils.indexOfDifference(golden, results);
    String difference = StringUtils.difference(golden, results);
    int diffLength = difference.length();
    if (diffLength > 50)
      difference = StringUtils.abbreviate(difference, 50);
    /*
    int resultsLength = results.length();
    int goldenLength = golden.length();
    
    if (resultsLength != goldenLength)
    {
      if (resultsLength < goldenLength)
      {
        throw new AssertionFailedError("golden file longer by:" + (goldenLength - resultsLength) + " char='" + ((int)golden.charAt(index)) + "'");
      }
      else
      {
        throw new AssertionFailedError("results file longer by:" + (resultsLength - goldenLength));            
      }
    }
    
    if (index >= resultsLength)
      throw new AssertionFailedError("golden file longer by:" + (goldenLength - resultsLength));
      
    if (results.length() < 50)
    {
      throw new AssertionFailedError(
           "Golden file for test "+ _scriptName + " did not match; " +
           "first difference at " + index + ", difference of length " +
           diffLength + ", \"" + difference + "\"" + "\ngolden:\n" + golden + "\nnew:\n" + results + "\ndiffChars g='" + golden.charAt(index) + "' r='" + results.charAt(index) + "'");
      
    }
    */
    throw new AssertionFailedError(
        "Golden file for test " + _scriptName + " did not match; " +
        "first difference at " + index + ", difference of length " +
        diffLength + ", \"" + difference + "\"");
  }
}