Package de.hsh.graja.modules.junit.api
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 isstart()
, which starts the diff process and either throws an AssertionError or returns silently.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiffHelper.DiffProcessor
callbackOnSystemInRead(Runnable readCallback)
Prepare console input before executing the methods.DiffHelper.DiffProcessor
hideCRLF()
Prepare this diff processor to not print CR and LF characters as special symbols.DiffHelper.DiffProcessor
includeExplanationInDiffSynopsis(Content explanation)
DiffHelper.DiffProcessor
includeExplanationOnThrowableFromMethod(Content explanation)
Prepare this diff processor to include an explanation when running a method or runnable fails.DiffHelper.DiffProcessor
normalizeOutput(StringNormalizer normalizer)
Prepare this diff processor to normalize output before searching for differences.DiffHelper.DiffProcessor
normalizeOutputExcludedFromDiffSynopsis(StringNormalizer normalizer)
Prepare this diff processor to normalize output before searching for differences.DiffHelper.DiffProcessor
ofClasses(Class<?> teacher, Class<?> student)
Prepare this diff processor to compare console output of a method of two different classes.DiffHelper.DiffProcessor
pipeToSystemIn(String input)
Prepare console input before executing the methods.DiffHelper.DiffProcessor
restrictOutputCapacity(long bytes, boolean failOnOverflow)
Prepare this diff processor to restrict the maximum output capacity to a given number of bytes.void
start()
This method will start execution of methods (if specified) and perform a comparison of the resulting strings.DiffHelper.DiffProcessor
useCommentAudienceOnDiff(Audience audience)
Prepare this diff processor to useaudience
as the comment audience in the diff synopsis.DiffHelper.DiffProcessor
useCommentLevelOnDiff(Level level)
Prepare this diff processor to uselevel
as the comment level in the diff synopsis.DiffHelper.DiffProcessor
useDiffSynopsisType(DiffComment.DiffSynopsisType diffSynopsisType)
Prepare this diff processor to usediffSynopsisType
for the diff synopsis.
-
-
-
Method Detail
-
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 behaviourstudent
- Student solution with observed behaviour- Throws:
IllegalArgumentException
- if this is a DiffProcessor comparing strings or runnables, i. e. if this DiffProcessor was created byDiffHelper.compareStrings(String, String)
or byDiffHelper.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 byDiffHelper.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 byDiffHelper.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 bytesfailOnOverflow
- 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 byDiffHelper.compareStrings(String, String)
.
-
useCommentLevelOnDiff
public DiffHelper.DiffProcessor useCommentLevelOnDiff(Level level)
Prepare this diff processor to uselevel
as the comment level in the diff synopsis.- Parameters:
level
- will be used as the comment level, if there are differences. Default isLevel.INFO
.
-
useCommentAudienceOnDiff
public DiffHelper.DiffProcessor useCommentAudienceOnDiff(Audience audience)
Prepare this diff processor to useaudience
as the comment audience in the diff synopsis.- Parameters:
audience
- will be used as the comment audience, if there are differences. Default isAudience.BOTH
.
-
useDiffSynopsisType
public DiffHelper.DiffProcessor useDiffSynopsisType(DiffComment.DiffSynopsisType diffSynopsisType)
Prepare this diff processor to usediffSynopsisType
for the diff synopsis.- Parameters:
diffSynopsisType
- will be used as the diff synopsis type, if there are differences. Default isDiffComment.DiffSynopsisType.DETAIL
.
-
hideCRLF
public DiffHelper.DiffProcessor hideCRLF()
Prepare this diff processor to not print CR and LF characters as special symbols.- Returns:
- this
-
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 aDiffHelper.DiffAssertionError
.CommentAssertionError
- If there were errors when executing the specified methods or runnables, then aCommentAssertionError
will be thrown.
-
-