-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed complex type writer and added tests. (#1)
* Fixed complex type writer and added tests. * [Core] Add explicit error message to ComplexTypeWriter When dealing with nested complex types, the ComplexTypeWriter would produce unbalanced and misaligned tables. This could be resolved by adding an `@XStreamConverter` to the complex field but this was not obvious. By adding an explicit exception this is resolved. For ease of use this exception is not thrown when acomplex field is empty or not included in the table .
- Loading branch information
1 parent
fd25cdc
commit 9fcf26a
Showing
4 changed files
with
303 additions
and
10 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
core/src/main/java/cucumber/runtime/table/PascalCaseStringConverter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cucumber.runtime.table; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class PascalCaseStringConverter implements StringConverter { | ||
|
||
private static final String WHITESPACE = " "; | ||
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+"); | ||
|
||
@Override | ||
public String map(String string) { | ||
String[] splitted = normalizeSpace(string).split(WHITESPACE); | ||
for (int i = 0; i < splitted.length; i++) { | ||
splitted[i] = capitalize(splitted[i]); | ||
} | ||
return join(splitted); | ||
} | ||
|
||
private String join(String[] splitted) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (String s : splitted) { | ||
sb.append(s); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
private String normalizeSpace(String originalHeaderName) { | ||
return WHITESPACE_PATTERN.matcher(originalHeaderName.trim()).replaceAll(WHITESPACE); | ||
} | ||
|
||
private String capitalize(String string) { | ||
return new StringBuilder(string.length()).append(Character.toTitleCase(string.charAt(0))).append(string.substring(1)).toString(); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.