Package de.hsh.graja.modules.junit.api
Class DiffHelper.DiffProcessor
java.lang.Object
de.hsh.graja.modules.junit.api.DiffHelper.DiffProcessor
- Enclosing class:
- DiffHelper
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 Summary
Modifier and TypeMethodDescriptioncallbackOnSystemInRead
(Runnable readCallback) Prepare console input before executing the methods.hideCRLF()
Prepare this diff processor to not print CR and LF characters as special symbols.includeExplanationInDiffSynopsis
(Content explanation) includeExplanationOnThrowableFromMethod
(Content explanation) Prepare this diff processor to include an explanation when running a method or runnable fails.normalizeOutput
(StringNormalizer normalizer) Prepare this diff processor to normalize output before searching for differences.Prepare this diff processor to normalize output before searching for differences.Prepare this diff processor to compare console output of a method of two different classes.overridePosOnFail
(ASTPos astpos) pipeToSystemIn
(String input) Prepare console input before executing the methods.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.useCommentAudienceOnDiff
(Audience audience) Prepare this diff processor to useaudience
as the comment audience in the diff synopsis.useCommentLevelOnDiff
(Level level) Prepare this diff processor to uselevel
as the comment level in the diff synopsis.useDiffSynopsisType
(DiffComment.DiffSynopsisType diffSynopsisType) Prepare this diff processor to usediffSynopsisType
for the diff synopsis.
-
Method Details
-
ofClasses
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
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
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
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
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
- Parameters:
explanation
- will be appended to output, if there are differences.
-
includeExplanationOnThrowableFromMethod
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
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
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
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
Prepare this diff processor to not print CR and LF characters as special symbols.- Returns:
- this
-
overridePosOnFail
-
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 aDiffHelper.DiffAssertionError
.CommentAssertionError
- If there were errors when executing the specified methods or runnables, then aCommentAssertionError
will be thrown.
-