Class DiffHelper

java.lang.Object
de.hsh.graja.modules.junit.api.DiffHelper

public class DiffHelper extends Object

This class identifies differences between a sample solution and a student solution class. It returns with a junit assertion error, if there were differences. The differences are returned as a DiffAssertionError, that contains detailed data on the differences.

The DiffHelper class creates a DiffHelper.DiffProcessor object, which is the core processing unit for diff checking. There are four methods to create a DiffHelper.DiffProcessor object:

A typical call flow is

 DiffHelper.callMethod("mymethod", a, b)
    .ofClasses(mypackage.Sample.class, studentClass)
    .pipeToSystemIn("console has\nsome input")
    .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
    .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
    .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
    .start();
 
  • Method Details

    • callMain

      public static DiffHelper.DiffProcessor callMain()

      This method searches for console output differences between an expected and an observed class when calling the main method for each class.

      A typical call flow is

       DiffHelper.callMain()
          .ofClasses(mypackage.Sample.class, studentClass)
          .pipeToSystemIn("console has\nsome input")
          .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
          .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
          .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
          .start();
       
    • callMain

      public static DiffHelper.DiffProcessor callMain(String[] args)

      This method searches for console output differences between an expected and an observed class when calling the main method for each class.

      A typical call flow is

       DiffHelper.callMain(args)
          .ofClasses(mypackage.Sample.class, studentClass)
          .pipeToSystemIn("console has\nsome input")
          .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
          .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
          .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
          .start();
       
    • callMethod

      public static DiffHelper.DiffProcessor callMethod(String methodName, Object... params)

      This method searches for console output differences between an expected and an observed class when calling a method for each class.

      A typical call flow is

       DiffHelper.callMethod("mymethod", a, b)
          .ofClasses(mypackage.Sample.class, studentClass)
          .pipeToSystemIn("console has\nsome input")
          .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
          .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
          .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
          .start();
       

      Parameters:
      methodName - name of static method to call
      params - parameters for method call
    • executeRunnables

      public static DiffHelper.DiffProcessor executeRunnables(Runnable teacher, Runnable student)

      This method searches for output differences between a runnable instance provided by the teacher and a runnable instance provided by a student.

      A typical call flow is

       DiffHelper.executeRunnables(rt, rs)
          .pipeToSystemIn("console has\nsome input")
          .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
          .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
          .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
          .start();
       
      Parameters:
      teacher - a Runnable instance that executes teacher code
      student - a Runnable instance that executes student code
    • compareStrings

      public static DiffHelper.DiffProcessor compareStrings(String expected, String observed)

      This method searches for differences between an expected and an observed string. A typical call flow is

       DiffHelper.compareStrings(e, o)
          .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES))
          .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES))
          .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...")
          .start();
       
      Parameters:
      expected - expected string
      observed - observed string
    • compareObjects

      public static DiffHelper.DiffProcessor compareObjects(Object expected, Object observed)

      This method searches for differences between an expected and an observed object after being converted to strings (see compareStrings(String, String).

      Parameters:
      expected - expected object
      observed - observed object