### Question:
LogListView extends ListView<LogMessage> implements Listener<LogMessage> { @Override public void onEvent(LogMessage event) { Platform.runLater(() -> { getItems().add(event); scrollToBottomIfShowing(); }); } @Inject  LogListView(UserContext userContext); @Override void onEvent(LogMessage event); void scrollToBottomIfShowing();  }### Answer:
@Test public void append() throws InterruptedException, TimeoutException { when(userContext.getNumberOfLogRows()).thenReturn(200); LogListView victim = new LogListView(userContext); victim.onEvent(new LogMessage("testMessage", LogLevel.WARN)); victim.onEvent(new LogMessage("anotherTestMessage", LogLevel.INFO)); waitOrTimeout(() -> victim.getItems().size() == 2, timeout(seconds(2))); waitOrTimeout(() -> "testMessage".equals(victim.getItems().get(0).getMessage()), timeout(seconds(2))); waitOrTimeout(() -> "anotherTestMessage".equals(victim.getItems().get(1).getMessage()), timeout(seconds(2))); }
@Test public void appendSizeConstraint() throws InterruptedException, TimeoutException { when(userContext.getNumberOfLogRows()).thenReturn(2); LogListView victim = new LogListView(userContext); victim.onEvent(new LogMessage("testMessage", LogLevel.WARN)); victim.onEvent(new LogMessage("anotherTestMessage", LogLevel.INFO)); victim.onEvent(new LogMessage("anotherTestMessage2", LogLevel.INFO)); victim.onEvent(new LogMessage("anotherTestMessage3", LogLevel.INFO)); waitOrTimeout(() -> victim.getItems().size() == 2, timeout(seconds(2))); waitOrTimeout(() -> "anotherTestMessage2".equals(victim.getItems().get(0).getMessage()), timeout(seconds(2))); waitOrTimeout(() -> "anotherTestMessage3".equals(victim.getItems().get(1).getMessage()), timeout(seconds(2))); }
@Test public void maxNumberOfLogRowsChanged() throws InterruptedException, TimeoutException { when(userContext.getNumberOfLogRows()).thenReturn(5); LogListView victim = new LogListView(userContext); victim.onEvent(new LogMessage("testMessage", LogLevel.WARN)); victim.onEvent(new LogMessage("anotherTestMessage", LogLevel.INFO)); victim.onEvent(new LogMessage("anotherTestMessage2", LogLevel.INFO)); victim.onEvent(new LogMessage("anotherTestMessage3", LogLevel.INFO)); victim.onEvent(new LogMessage("anotherTestMessage4", LogLevel.INFO)); waitOrTimeout(() -> victim.getItems().size() == 5, timeout(seconds(2))); when(userContext.getNumberOfLogRows()).thenReturn(2); eventStudio().broadcast(new MaxLogRowsChangedEvent()); waitOrTimeout(() -> victim.getItems().size() == 2, timeout(seconds(2))); waitOrTimeout(() -> "anotherTestMessage3".equals(victim.getItems().get(0).getMessage()), timeout(seconds(2))); waitOrTimeout(() -> "anotherTestMessage4".equals(victim.getItems().get(1).getMessage()), timeout(seconds(2))); }