@Test public void givenUnjoinableBoxFollowedByJoinableBoxWithoutProperSplitPointAtLineEnd_whenAdditionalBoxWithoutProperSplitPointDoesNotFitIntoLine_shouldWrapCompleteJoinedBoxIntoNextLine() throws Exception { final List<IInlineBox> boxes = boxes(square(10), staticText("L"), staticText("or")); lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT); assertEquals(2, boxes.size()); assertEquals("Lor", ((StaticText) boxes.get(1)).getText()); }
@Test public void givenSquareFollowedBySingleSpace_whenSplittingWithinSpace_shouldKeepSpaceOnFirstLine() throws Exception { final List<IInlineBox> boxes = boxes(staticText("Lorem "), square(15), staticText(" ")); layout(boxes); final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth(); lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 1, TextAlign.LEFT); assertEquals(1, lines.getLines().size()); assertEquals(boxes.get(2), lines.getLines().iterator().next().getLastChild()); }
@Test public void givenUnjoinableBoxFollowedByJoinableBoxWithoutProperSplitPointAtLineEnd_whenAdditionalBoxWithoutProperSplitPointDoesNotFitIntoLine_shouldRemoveOriginalLastBox() throws Exception { final List<IInlineBox> boxes = boxes(square(10), staticText("L"), staticText("or")); lines.arrangeBoxes(graphics, boxes.listIterator(), 18, TextAlign.LEFT); for (final IInlineBox box : boxes) { if (box.getWidth() == 0) { fail("Splitting left over an empty box."); } } }
@Test public void givenInlineContainerFollowedByTextThatStartsWithSpace_whenSplittingWithinText_shouldSplitAfterSpace() throws Exception { final List<IInlineBox> boxes = boxes(staticText("Lorem "), inlineContainer(staticText("ipsum")), staticText(" dolor")); layout(boxes); final int widthOfHeadBoxes = boxes.get(0).getWidth() + boxes.get(1).getWidth(); lines.arrangeBoxes(graphics, boxes.listIterator(), widthOfHeadBoxes + 10, TextAlign.LEFT); assertEquals(2, lines.getLines().size()); assertEquals(" ", ((StaticText) lines.getLines().iterator().next().getLastChild()).getText()); }
@Test public void givenUnjoinableBoxes_whenBoxesFitIntoSameLane_shouldNotJoinBoxes() throws Exception { lines.arrangeBoxes(graphics, unjoinableBoxes.listIterator(), 210, TextAlign.LEFT); assertEquals(3, unjoinableBoxes.size()); }
@Test public void givenAllBoxesFitIntoOneLine_shouldArrangeBoxesInOneLine() throws Exception { lines.arrangeBoxes(graphics, joinableBoxes.listIterator(), 210, TextAlign.LEFT); assertEquals(1, lines.getLines().size()); }