LogTextArea extends TextArea { public void addLineToLog(String data) { checkNotNull(data, "Data cannot be null"); if (fullLog.length() + data.length() >= MAX_STRING_LENGTH && !full) { full = true; fullLog.append("[ERROR] Too much output to display. Discarding the rest."); } else if (!full) { fullLog.append(data).append('\n'); } else { return; } final double scrollPosition; if (isPausedScroll()) { scrollPosition = this.getScrollTop(); } else { scrollPosition = Double.MAX_VALUE; } this.setText(fullLog.toString()); this.setScrollTop(scrollPosition); }  void addLineToLog(String data); final boolean isPausedScroll(); final void setPausedScroll(boolean value); final BooleanProperty pausedScrollProperty(); @Override void clear();  }
@Test public void testAddFirstLine() { final String firstLine = "First Line Of Text"; logTextArea.addLineToLog(firstLine); assertEquals("First line wasn't added", firstLine + "\n", logTextArea.getText()); }
@Test public void testAddTwoLines() { final String firstLine = "First Line Of Text"; final String secondLine = "Second line of text"; logTextArea.addLineToLog(firstLine); logTextArea.addLineToLog(secondLine); assertEquals("Second line wasn't added", firstLine + "\n" + secondLine + "\n", logTextArea .getText()); }
@Test public void testAddingReallyLongLineOfText() { final String initialLength = StringUtils.rightPad("Initial string", LogTextArea .MAX_STRING_LENGTH - 3, "Long\n"); logTextArea.addLineToLog(initialLength); assertEquals("Text was not added to logger", initialLength + "\n", logTextArea.getText()); }
@Test public void testAddingStringThatIsTooLong() { final String initialText = StringUtils.rightPad("Initial string", LogTextArea .MAX_STRING_LENGTH, "Long\n"); logTextArea.addLineToLog(initialText); assertNotEquals("The initial text should not have been appended as it was too long", initialText + "\n", logTextArea.getText()); }
@Test public void testAddingStringToFullLog() { testAddingStringThatIsTooLong(); final String currentText = logTextArea.getText(); logTextArea.addLineToLog("More logged text"); assertEquals("This text should not be appended as the log is full", currentText, logTextArea .getText()); }