package de.codecentric.jbehave.junit.monitoring;

import java.util.HashSet;
import java.util.Set;

public class DescriptionTextUniquefier {

	private Set<String> strings = new HashSet<>();

	public String getUniqueDescription(String junitSafeString) {
		while (strings.contains(junitSafeString)) {
			junitSafeString = junitSafeString + '\u200B'; // zero-width-space
		}
		strings.add(junitSafeString);
		return junitSafeString;
	}

}

@@ -155,22 +155,33 @@
 String%3E 
-string
+uniqueDescription
 s = new 
@@ -262,21 +262,78 @@
 %7B%0A%09%09
-while (string
+String uniqueDescription = junitSafeString;%0A%09%09while (uniqueDescription
 s.co
@@ -343,31 +343,33 @@
 ins(
-j
 uni
-tSafeString
+queDescription
 )) %7B%0A%09%09%09
 juni
@@ -368,43 +368,28 @@
 %0A%09%09%09
-j
 uni
-tSafeString = junitSafeString
+queDescription
  +
+=
  '%5Cu
@@ -425,35 +425,48 @@
 %7D%0A%09%09
-string
+uniqueDescription
 s.add(
-j
 uni
-tSafeString
+queDescription
 );%0A%09
@@ -473,31 +473,33 @@
 %09return 
-j
 uni
-tSafeString
+queDescription
 ;%0A%09%7D%0A%0A%7D%0A

Refactor DescriptionTextUniquefier