Class DiffHelper.DiffProcessor

java.lang.Object
de.hsh.graja.modules.junit.api.DiffHelper.DiffProcessor
Enclosing class:
DiffHelper

public static class DiffHelper.DiffProcessor extends Object
This class realizes a fluent interface when instrumenting the Diff with information used when diffing. The last method called is start(), which starts the diff process and either throws an AssertionError or returns silently.
  • Method Details

    • ofClasses

      public DiffHelper.DiffProcessor ofClasses(Class<?> teacher, Class<?> student)
      Prepare this diff processor to compare console output of a method of two different classes.
      Parameters:
      teacher - Sample solution with expected behaviour
      student - Student solution with observed behaviour
      Throws:
      IllegalArgumentException - if this is a DiffProcessor comparing strings or runnables, i. e. if this DiffProcessor was created by DiffHelper.compareStrings(String, String) or by DiffHelper.executeRunnables(Runnable, Runnable).
    • pipeToSystemIn

      public DiffHelper.DiffProcessor pipeToSystemIn(String input)
      Prepare console input before executing the methods.
      Parameters:
      input - String with console input (null, if not needed)
      Throws:
      IllegalArgumentException - if this is a DiffProcessor comparing strings, i. e. if this DiffProcessor was created by DiffHelper.compareStrings(String, String).
    • callbackOnSystemInRead

      public DiffHelper.DiffProcessor callbackOnSystemInRead(Runnable readCallback)
      Prepare console input before executing the methods.
      Parameters:
      input - String with console input (null, if not needed)
      Throws:
      IllegalArgumentException - if this is a DiffProcessor comparing strings, i. e. if this DiffProcessor was created by DiffHelper.compareStrings(String, String).
    • normalizeOutput

      public DiffHelper.DiffProcessor normalizeOutput(StringNormalizer normalizer)
      Prepare this diff processor to normalize output before searching for differences.
      Parameters:
      normalizer - normalizes output before diffing
    • normalizeOutputExcludedFromDiffSynopsis

      public DiffHelper.DiffProcessor normalizeOutputExcludedFromDiffSynopsis(StringNormalizer normalizer)
      Prepare this diff processor to normalize output before searching for differences. This method specifies a normalization, that will be in effect when comparing strings, but the normalization will not be noticable in the diff synopsis. This can be used to perform normalizations that will degenerate the two strings to unreadable strings in order to perform a very sloppy comparison. E. g. we could compare two strings after eliminating all whitespaces from both strings. If there are differences, the output won't get unreadable, since it will be based on the unnormalized versions of the two compared strings.
      Parameters:
      normalizer - normalizes output before diffing
    • restrictOutputCapacity

      public DiffHelper.DiffProcessor restrictOutputCapacity(long bytes, boolean failOnOverflow)
      Prepare this diff processor to restrict the maximum output capacity to a given number of bytes. If the output exceeds the capacity, Graja will throw an AssertionError if failOnOverflow is true, or it will ignore the output silently, otherwise.
      Parameters:
      bytes - maximum capacity in bytes
      failOnOverflow - if true, an AssertionError will be thrown on overflow.
      Returns:
      reference to this DiffProcessor
    • includeExplanationInDiffSynopsis

      public DiffHelper.DiffProcessor includeExplanationInDiffSynopsis(Content explanation)
      Parameters:
      explanation - will be appended to output, if there are differences.
    • includeExplanationOnThrowableFromMethod

      public DiffHelper.DiffProcessor includeExplanationOnThrowableFromMethod(Content explanation)
      Prepare this diff processor to include an explanation when running a method or runnable fails.
      Parameters:
      explanation - will be appended to output, if the method execution failed by throwing a Throwable. This can be used to include additional information into the output in order to give hints to the students, what input parameters have been passed to the method that caused the failure.
      Throws:
      IllegalArgumentException - if this is a DiffProcessor comparing strings, i. e. if this DiffProcessor was created by DiffHelper.compareStrings(String, String).
    • useCommentLevelOnDiff

      public DiffHelper.DiffProcessor useCommentLevelOnDiff(Level level)
      Prepare this diff processor to use level as the comment level in the diff synopsis.
      Parameters:
      level - will be used as the comment level, if there are differences. Default is Level.INFO.
    • useCommentAudienceOnDiff

      public DiffHelper.DiffProcessor useCommentAudienceOnDiff(Audience audience)
      Prepare this diff processor to use audience as the comment audience in the diff synopsis.
      Parameters:
      audience - will be used as the comment audience, if there are differences. Default is Audience.BOTH.
    • useDiffSynopsisType

      public DiffHelper.DiffProcessor useDiffSynopsisType(DiffComment.DiffSynopsisType diffSynopsisType)
      Prepare this diff processor to use diffSynopsisType for the diff synopsis.
      Parameters:
      diffSynopsisType - will be used as the diff synopsis type, if there are differences. Default is DiffComment.DiffSynopsisType.DETAIL.
    • hideCRLF

      public DiffHelper.DiffProcessor hideCRLF()
      Prepare this diff processor to not print CR and LF characters as special symbols.
      Returns:
      this
    • overridePosOnFail

      public DiffHelper.DiffProcessor overridePosOnFail(ASTPos astpos)
    • suppressPosOnFail

      public DiffHelper.DiffProcessor suppressPosOnFail()
    • start

      public void start()
      This method will start execution of methods (if specified) and perform a comparison of the resulting strings.
      Throws:
      DiffHelper.DiffAssertionError - If there are differences, this method will throw a DiffHelper.DiffAssertionError.
      CommentAssertionError - If there were errors when executing the specified methods or runnables, then a CommentAssertionError will be thrown.