Created
November 27, 2020 04:40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class BoundaryConditions { | |
// This is example in your test, showing how | |
// the system under test uses these ingredients to | |
// produce useful work | |
static <T> T example( | |
Solution.FromBowlingScore<T> score, | |
Solution.FromUnknown<T> unknown, | |
int [] unsanitizedThrows) { | |
// If you were really planning to support a function | |
// for this exact scenario, then the demonstration | |
// of how to use it is trivial. More likely would | |
// be to inline this to demonstrate the next level | |
// down. | |
return Solution.simplestThingThatCouldPossiblyWork( | |
score, | |
unknown, | |
unsanitizedThrows | |
); | |
} | |
} | |
// Here's the facade, which provides a simplified | |
// expression of the example that exploits that | |
// the fact that the inputs are pre-sanitized | |
static int score(int ... preSanitizedInputs) { | |
Supplier<Integer> result = BoundaryConditions.example( | |
FROM_BOWLING_SCORE, | |
FROM_UNKNOWN, | |
preSanitizedInputs | |
); | |
return result.get(); | |
} | |
static final Solution.FromBowlingScore<Supplier<Integer>> | |
FROM_BOWLING_SCORE = score -> () -> score; | |
static final Solution.FromUnknown<Supplier<Integer>> | |
FROM_UNKNOWN = () -> { | |
Assert.fail("FROM_UNKNOWN should not be called for pre-sanitized inputs"); | |
return null; // unreachable code | |
}; | |
// And here's a demonstration of a check that is relatively easy to type. | |
// in practice, you'd probably introduce a parameterized test t | |
public void testSomeThrows() { | |
Assert.assertEquals( | |
6, | |
score( | |
1,2,3 | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment