From e84ceedd582a9a0b2e6370a586c1f4c2ac7f2365 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 5 Oct 2015 21:21:02 +0200 Subject: [PATCH] [#72] Added explanation to matchers --- .../accurest/util/ContentUtils.groovy | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy index 87b940c663..c18a918c8b 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/util/ContentUtils.groovy @@ -179,6 +179,30 @@ class ContentUtils { }) } + /** + *

+ * If you wonder why there is val[1] without null-check then take a look at this: + *

+ *

+ * Example: + *

+ *

+ * Our string equals: {@code EXECUTION>>assertThatRejectionReasonIsNull($it)<<} + * The matcher matches this group with the pattern {@code EXECUTION>>(.*)<<} + *

+ *

+ * So {@code executionMatcher[0]} returns 2 elements: + *

+ *

+ *

+ * Thus one can safely write {@code executionMatcher[0][1]} to retrieve the matched group + *

+ * @param string to match the regexps against + * @return object converted from temporary holders + */ static Object returnParsedObject(String string) { Matcher matcher = TEMPORARY_PATTERN_HOLDER.matcher(string.trim()) if (matcher.matches()) {