From 5dc28b9bb010ba61c03401a9866328748bbc5b95 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 Sep 2015 10:08:28 +0100 Subject: [PATCH] Improve extensibility of RestDocumentationContextPlaceholderResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, RestDocumentationContextPlaceholderResolver could be subclassed, but it didn’t provide access to its state (the RestDocumentationContext). This commit opens up RestDocumentationContextPlaceholderResolver by adding a getter method for its RestDocumentationContext. It also makes the kebab-base and snake_case conversion methods protected (rather than private) so that they can be used by subclasses. See gh-116 --- .../RestDocumentationContextPlaceholderResolver.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/RestDocumentationContextPlaceholderResolver.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/RestDocumentationContextPlaceholderResolver.java index 706078d0..8a2f9314 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/RestDocumentationContextPlaceholderResolver.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/RestDocumentationContextPlaceholderResolver.java @@ -66,22 +66,26 @@ public class RestDocumentationContextPlaceholderResolver implements PlaceholderR return this.context.getTestMethodName(); } if ("method-name".equals(placeholderName)) { - return camelCaseToDash(this.context.getTestMethodName()); + return camelCaseToKebabCase(this.context.getTestMethodName()); } if ("method_name".equals(placeholderName)) { - return camelCaseToUnderscore(this.context.getTestMethodName()); + return camelCaseToSnakeCase(this.context.getTestMethodName()); } return null; } - private String camelCaseToDash(String string) { + protected final String camelCaseToKebabCase(String string) { return camelCaseToSeparator(string, "-"); } - private String camelCaseToUnderscore(String string) { + protected final String camelCaseToSnakeCase(String string) { return camelCaseToSeparator(string, "_"); } + protected final RestDocumentationContext getContext() { + return this.context; + } + private String camelCaseToSeparator(String string, String separator) { Matcher matcher = CAMEL_CASE_PATTERN.matcher(string); StringBuffer result = new StringBuffer();