public void testAddRangeChangeHandler() {
HasData<String> listView = new MockHasData<String>();
MockView<String> view = new MockView<String>();
HasDataPresenter<String> presenter = new HasDataPresenter<String>(listView, view, 10, null);
MockRangeChangeHandler handler = new MockRangeChangeHandler();
// Adding a handler should not invoke the handler.
// Add the handler to the view because it is the source of events.
HandlerRegistration reg = listView.addRangeChangeHandler(handler);
assertNull(handler.getLastRange());
handler.reset();
// Change the pageStart.
presenter.setVisibleRange(new Range(10, 10));
assertEquals(new Range(10, 10), handler.getLastRange());
handler.reset();
// Change the pageSize.
presenter.setVisibleRange(new Range(10, 20));
assertEquals(new Range(10, 20), handler.getLastRange());
handler.reset();
// Reuse the same range and verify an event is not fired.
presenter.setVisibleRange(new Range(10, 20));
assertNull(handler.getLastRange());
handler.reset();
// Remove the handler and verify it no longer receives events.
reg.removeHandler();
presenter.setVisibleRange(new Range(20, 100));
assertNull(handler.getLastRange());
handler.reset();
}