TextSplitter { public static StringStyle[] splitStringAlgorithm(String text, double width, DrawHandler drawer) { return splitStringAndHeightAlgorithm(text, width, drawer).getWrappedLines(); }  static void drawText(DrawHandler drawer, String[] textLines, double topLeftX, double topLeftY, double width, double height, AlignHorizontal hAlignment, AlignVertical vAlignment); static boolean checkifStringFitsNoWordwrap(String text, double width, DrawHandler drawer); static boolean checkifStringFitsWithWordwrap(String text, double width, DrawHandler drawer); static double getSplitStringHeight(String text, double width, DrawHandler drawer); static double getSplitStringHeight(String[] textLines, double width, DrawHandler drawer); static StringStyle[] splitStringAlgorithm(String text, double width, DrawHandler drawer); static double getTextMinWidth(String text, DrawHandler drawer); static double getTextMinWidth(String[] textLines, DrawHandler drawer);  }
@Test public void ifASingleWordDoesntFitTheSpaceSplitItIntoMultipleLines() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("MessagePresenter", 30.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Arrays.asList("Mes", "sag", "ePr", "ese", "nte", "r")); }
@Test public void firstWordIsSplitPartiallyIntoSecondLineWithSecondWordThirdWordFitsLine() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("MessagePresenter (text) text3blaxxxx", 100.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Arrays.asList("MessagePresen", "ter (text)", "text3blaxxxx")); }
@Test public void shortWordThenLongWord() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("tter looooooooooooongword", 30.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Arrays.asList("tte", "r", "loo", "ooo", "ooo", "ooo", "oon", "gwo", "rd")); }
@Test public void severalWordsSplitIntoDistinctLines() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("test test2 test3 test4", 50.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Arrays.asList("test", "test2", "test3", "test4")); }
@Test public void manyShortWordsWithEnoughSpace() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test", 5000.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Arrays.asList("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test")); }
@Test public void emptyResultIfNotEnoughSpaceForSingleChar() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Collections.<String> emptyList()); }
@Test public void emptyString() throws Exception { StringStyle[] style = TextSplitter.splitStringAlgorithm("", 1.0, dimensionCalculatorDrawHandler); assertContentEquals(style, Collections.<String> emptyList()); }