StringBuilder (@NotNull StringBuilder sb, @NotNull String prefix, @NotNull String text, @NotNull String suffix) { sb.append(prefix).append("string()."); final String[] parts = text.split("[,|\\s]+"); boolean useMatches = false; for (String part : parts) { if (isRegexp(part)) { useMatches = true; break; } } if (useMatches) { sb.append("matches(\"").append(text).append("\")"); } else if (parts.length > 1) { sb.append("oneOf("); boolean first = true; for (String part : parts) { if (first) first = false; else sb.append(", "); sb.append("\"").append(part).append("\""); } sb.append(")"); } else { sb.append("equalTo(\"").append(text).append("\")"); } sb.append(suffix); return sb; }