Extract duplicated PatternTest code to testMultiplePatterns method

This commit is contained in:
Riccardo Azzolini 2018-10-06 18:45:28 +02:00
parent 0ec3974f41
commit 957e85b4d0

View File

@ -155,16 +155,7 @@ public class PatternTest {
)
);
for (final ImmutablePair<Pattern, Function> patternAndMatchingFunction : patternsAndMatchingFunctions) {
final Pattern pattern = patternAndMatchingFunction.getLeft();
final Function shouldMatch = patternAndMatchingFunction.getRight();
assertFalse(pattern.match(shouldNotMatch).isPresent());
final Optional<Map<String, Function>> subFunctions = pattern.match(shouldMatch);
assertTrue(subFunctions.isPresent());
assertEquals(shouldMatch, pattern.replace(mathContext, subFunctions.get()));
}
testMultiplePatterns(shouldNotMatch, patternsAndMatchingFunctions);
}
@Test
@ -201,6 +192,13 @@ public class PatternTest {
)
);
testMultiplePatterns(shouldNotMatch, patternsAndMatchingFunctions);
}
private void testMultiplePatterns(
final Function shouldNotMatch,
final List<ImmutablePair<Pattern, Function>> patternsAndMatchingFunctions
) {
for (final ImmutablePair<Pattern, Function> patternAndMatchingFunction : patternsAndMatchingFunctions) {
final Pattern pattern = patternAndMatchingFunction.getLeft();
final Function shouldMatch = patternAndMatchingFunction.getRight();