Class Failure
java.lang.Object
io.github.valentinherrmann.levenshtein.Failure
The one format of every behaviour failure: a block of labelled lines, localized with
Messages and
LevenshteinSettings.getLanguage(). The framework reports exceptions of student code,
invokeExpectingException and testGettersSetters with it, and test authors use it for their
own checks, so students see the same format everywhere:
Method: calculateLoudness(double, double) Scenario: generated case 3, seed 2040003 Input: volume = 12.50, crowdNoise = 3.00 Expected: 31.25 Actual: 27.00
throw Failure.of(methodWrapper)
.scenario("generated case 3, seed 2040003")
.input("volume = 12.50, crowdNoise = 3.00")
.expected(31.25).actual(actual)
.error();
Lines that are not set are left out. The AssertionError of error() never has a cause, so no
stack trace of the student code is shown.
Structural failures (a missing class, method, ...) keep their short form and do not use this block.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCode without a result that may throw anything.static interfaceCode that returns a value and may throw anything. -
Method Summary
Modifier and TypeMethodDescriptionactualText(String text) Shows argument values in the Input line, formatted likeformat(Object)and separated by commas.static voidcall(Failure.ThrowingRunnable code) Likecall(ThrowingSupplier)for code without a result.static <R> Rcall(Failure.ThrowingSupplier<R> code) Runs student code and turns an exception it throws into a failure block (Actual: the exception).cases(int failed, int total) Adds the line "(n of m cases failed)" if more than one case was checked.error()expectedText(String text) static StringFormats a value the same way in every failure message:doubleandfloatvalues withLevenshteinSettings.getDecimals()decimals (dot as separator), strings in double quotes, characters in single quotes,null, arrays and collections in brackets, very long values cut.message()static Failureof(ConstructorWrapper<?> constructor) static Failureof(MethodWrapper<?, ?> method) static FailureShows an exception of the student code as actual outcome, e.g.toString()
-
Method Details
-
of
- Parameters:
method- the method whose behaviour is wrong (the Method line shows its name and parameter types)- Returns:
- a new failure
-
of
- Parameters:
constructor- the constructor whose behaviour is wrong- Returns:
- a new failure
-
of
-
scenario
-
input
-
arguments
Shows argument values in the Input line, formatted likeformat(Object)and separated by commas. No arguments leave the line out.- Parameters:
args- the argument values- Returns:
- this failure
-
expected
- Parameters:
value- the expected value, formatted withformat(Object)- Returns:
- this failure
-
actual
- Parameters:
value- the actual value, formatted withformat(Object)- Returns:
- this failure
-
expectedText
-
actualText
-
thrown
Shows an exception of the student code as actual outcome, e.g.IllegalStateException: message(never with a stack trace). AStackOverflowErroradds a hint on endless recursion.- Parameters:
t- the exception thrown by the student code- Returns:
- this failure
-
cases
Adds the line "(n of m cases failed)" if more than one case was checked.- Parameters:
failed- the number of failed casestotal- the number of all checked cases- Returns:
- this failure
-
message
- Returns:
- the block in the current language
-
error
- Returns:
- a failure with the block as message and without a cause, ready to be thrown
-
toString
-
format
Formats a value the same way in every failure message:doubleandfloatvalues withLevenshteinSettings.getDecimals()decimals (dot as separator), strings in double quotes, characters in single quotes,null, arrays and collections in brackets, very long values cut.- Parameters:
value- any value- Returns:
- the formatted value
-
call
Runs student code and turns an exception it throws into a failure block (Actual: the exception). Failures (AssertionError) and security violations are passed on unchanged.- Type Parameters:
R- the result type- Parameters:
code- the code to run, e.g.() -> wrapper.invokeRaw(...)or a call of a student method- Returns:
- the result of the code
-
call
Likecall(ThrowingSupplier)for code without a result.- Parameters:
code- the code to run
-