package org.fxmisc.flowless;

import static org.junit.Assert.*;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.embed.swing.JFXPanel;
import javafx.scene.shape.Rectangle;

import org.junit.BeforeClass;
import org.junit.Test;

public class VirtualFlowTest {

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        new JFXPanel();
    }

    @Test
    public void idempotentShowTest() {
        // create VirtualFlow with 1 big cell
        Rectangle rect = new Rectangle(500, 500);
        ObservableList<Rectangle> items = FXCollections.singletonObservableList(rect);
        VirtualFlow<Rectangle, Cell<Rectangle, Rectangle>> vf = VirtualFlow.createVertical(items, Cell::wrapNode);
        vf.resize(100, 100); // size of VirtualFlow less than that of the cell
        vf.layout();

        vf.show(110.0);
        vf.show(110.0);
        vf.layout();
        assertEquals(-10.0, rect.getBoundsInParent().getMinY(), 0.01);
    }

    @Test
    public void idempotentSetLengthOffsetTest() {
        // create VirtualFlow with 1 big cell
        Rectangle rect = new Rectangle(500, 500);
        ObservableList<Rectangle> items = FXCollections.singletonObservableList(rect);
        VirtualFlow<Rectangle, Cell<Rectangle, Rectangle>> vf = VirtualFlow.createVertical(items, Cell::wrapNode);
        vf.resize(100, 100); // size of VirtualFlow less than that of the cell
        vf.layout();

        vf.setLengthOffset(10.0);
        vf.setLengthOffset(10.0);
        vf.layout();
        assertEquals(-10.0, rect.getBoundsInParent().getMinY(), 0.01);
    }

}

@@ -58,9 +58,160 @@
 ert.
-*
+assertEquals;%0Aimport static org.junit.Assert.assertSame;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test
 ;%0A%0Ai
@@ -370,62 +370,8 @@
 e;%0A%0A
-import org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0A
 publ
@@ -1728,10 +1728,1493 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void fastVisibleIndexTest() %7B%0A        ObservableList%3CRectangle%3E items = FXCollections.observableArrayList();%0A        for (int i = 0; i %3C 100; i++) %7B%0A            items.add(new Rectangle(500, 100));%0A        %7D%0A%0A        VirtualFlow%3CRectangle, Cell%3CRectangle, Rectangle%3E%3E vf = VirtualFlow.createVertical(items, Cell::wrapNode);%0A        vf.resize(100, 450); // size of VirtualFlow enough to show several cells%0A        vf.layout();%0A%0A        ObservableList%3CCell%3CRectangle,Rectangle%3E%3E visibleCells = vf.visibleCells();%0A        %0A        vf.show(0);%0A        vf.layout();%0A        assertSame(visibleCells.get(0), vf.getCell(vf.getFirstVisibleIndex()));%0A        assertSame(visibleCells.get(visibleCells.size() - 1), vf.getCell(vf.getLastVisibleIndex()));%0A        assertTrue(vf.getFirstVisibleIndex() %3C= 0 && 0 %3C= vf.getLastVisibleIndex());%0A        %0A        vf.show(50);%0A        vf.layout();%0A        assertSame(visibleCells.get(0), vf.getCell(vf.getFirstVisibleIndex()));%0A        assertSame(visibleCells.get(visibleCells.size() - 1), vf.getCell(vf.getLastVisibleIndex()));%0A        assertTrue(vf.getFirstVisibleIndex() %3C= 50 && 50 %3C= vf.getLastVisibleIndex());%0A%0A        vf.show(99);%0A        vf.layout();%0A        assertSame(visibleCells.get(0), vf.getCell(vf.getFirstVisibleIndex()));%0A        assertSame(visibleCells.get(visibleCells.size() - 1), vf.getCell(vf.getLastVisibleIndex()));%0A        assertTrue(vf.getFirstVisibleIndex() %3C= 99 && 99 %3C= vf.getLastVisibleIndex());%0A    %7D%0A
 %7D%0A

Add a test for the getFirstVisibleIndex/getLastVisibleIndex methods.