### Question:
StringUtilities { public static int[] findBreakPoints(String textString, int lines) { SortedSet<Integer> breakSet = new TreeSet<>(); breakSet.addAll(allIndicesOf(textString, ' ')); breakSet.addAll(allIndicesOf(textString, '-')); List<Integer> breakList = new ArrayList<>(); for (int value : breakSet) { breakList.add(value + 1); } int[] lineBreaks = new int[lines - 1]; int textLength = textString.length(); int currentBreakPoint = 0; for (int searchedBreakPoint = 0; searchedBreakPoint < lines - 1; searchedBreakPoint++) { int lastAllowedBreakPointIndex = breakList.size() - (lines - 1 - searchedBreakPoint); int niceTextStartPosition = textLength / lines * (searchedBreakPoint + 1); while (currentBreakPoint < lastAllowedBreakPointIndex) { if (breakList.get(currentBreakPoint) >= niceTextStartPosition) { break; } currentBreakPoint++; } if (breakList.size() > currentBreakPoint) { lineBreaks[searchedBreakPoint] = breakList.get(currentBreakPoint); } else { lineBreaks[searchedBreakPoint] = 0; } currentBreakPoint++; } Arrays.sort(lineBreaks); return lineBreaks; }  static String getFileNameRepresentation(String string); static List<Integer> allIndicesOf(String string, char character); static int[] findBreakPoints(String textString, int lines); static String insertLineBreakEveryXCharacters(String textString, String lineBreak, int numberOfCharacters); static String joinStringsWithDelimiter(String[] stringsToJoin, String delimiter); static String joinStringsWithDelimiter(String[] stringsToJoin, String delimiter, String nullString); static char lastCharacter(String string); static String cutOffLastCharacters(String string, int characterCount); static boolean isNullOrTrimmedEmpty(String text); static final String EMPTY_STRING; }### Answer:
@Test public void testFindLineBreaks() throws Exception { Assert.assertTrue(Arrays.equals(new int[] { 6 }, StringUtilities.findBreakPoints("Hallo Du!", 2))); Assert.assertTrue(Arrays.equals(new int[] { 6, 9 }, StringUtilities.findBreakPoints("Hallo Du da!", 3))); Assert.assertTrue(Arrays.equals(new int[] { 6 }, StringUtilities.findBreakPoints("Hallo-Du!", 2))); Assert.assertTrue(Arrays.equals(new int[] { 6, 9 }, StringUtilities.findBreakPoints("Hallo-Du da!", 3))); Assert.assertTrue(Arrays.equals(new int[] { 6, 13 }, StringUtilities.findBreakPoints("Oh Du Lebest draussen!", 3))); int[] breakPoints = StringUtilities.findBreakPoints("Hallo Du da drueben!", 3); Assert.assertTrue(Arrays.equals(new int[] { 6, 12 }, breakPoints)); Assert.assertTrue(Arrays.equals(new int[] { 0, 3 }, StringUtilities.findBreakPoints("Zu kurz.", 3))); }