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 aDiffHelper.DiffProcessor
object, which is the core processing unit for diff checking. There are four methods to create aDiffHelper.DiffProcessor
object:compareStrings(String, String)
returns aDiffHelper.DiffProcessor
object comparing two strings.callMain()
returns aDiffHelper.DiffProcessor
object comparing the console output of two classes' main methods.callMethod(String, Object...)
returns aDiffHelper.DiffProcessor
object comparing the console output generated by the specified method of two different classes.executeRunnables(Runnable, Runnable)
returns aDiffHelper.DiffProcessor
object comparing the console output of the two runnable's run methods.
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();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DiffHelper.DiffAssertionError
This error is thrown, whenDiffHelper.DiffProcessor
detects a difference.static class
DiffHelper.DiffProcessor
This class realizes a fluent interface when instrumenting the Diff with information used when diffing.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.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 (seecompareStrings(String, String)
.static DiffHelper.DiffProcessor
compareStrings(String expected, String observed)
This method searches for differences between an expected and an observed string.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.
-
-
-
Method Detail
-
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();
-
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 callparams
- 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 codestudent
- 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 stringobserved
- 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 objectobserved
- observed object
-
-