Improve extensibility of RestDocumentationContextPlaceholderResolver

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
This commit is contained in:
Andy Wilkinson
2015-09-09 10:08:28 +01:00
parent 1e53502958
commit 5dc28b9bb0

View File

@@ -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();