6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.collections;
27
28 import com.sun.javafx.collections.ObservableListWrapper;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import java.util.List;
33 import org.junit.Before;
34 import org.junit.Test;
35 import static org.junit.Assert.*;
36
37 public class ListChangeBuilderTest {
38
39 private ListChangeBuilder<String> builder;
40 private ObservableListWrapper<String> observableList;
41 private ArrayList<String> list;
42 private MockListObserver<String> observer;
43
44 @Before
45 public void setUp() {
46 observer = new MockListObserver<String>();
47 list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
48 observableList = new ObservableListWrapper<String>(list);
49 observableList.addListener(observer);
50 builder = new ListChangeBuilder<String>(observableList);
51 }
52
53 @Test
54 public void testAddRemove() {
55 builder.beginChange();
56 list.remove(2);
57 builder.nextRemove(2, "c");
58 list.add(2, "cc");
59 list.add(3, "ccc");
60 builder.nextAdd(2, 4);
61 list.remove(2);
62 builder.nextRemove(2, "cc");
63 list.remove(3);
64 builder.nextRemove(3, "d");
65 list.add(0, "aa");
66 builder.nextAdd(0, 1);
67 builder.endChange();
68
69 assertEquals(list, Arrays.asList("aa", "a", "b", "ccc"));
70
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.collections;
27
28 import test.javafx.collections.MockListObserver;
29 import com.sun.javafx.collections.ObservableListWrapper;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.List;
34 import javafx.collections.ListChangeBuilderShim;
35 import javafx.collections.ListChangeListener;
36 import javafx.collections.ObservableListWrapperShim;
37 import org.junit.Before;
38 import org.junit.Test;
39 import static org.junit.Assert.*;
40
41 public class ListChangeBuilderTest {
42
43 private ListChangeBuilderShim<String> builder;
44 private ObservableListWrapperShim<String> observableList;
45 private ArrayList<String> list;
46 private MockListObserver<String> observer;
47
48 @Before
49 public void setUp() {
50 observer = new MockListObserver<String>();
51 list = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
52 observableList = new ObservableListWrapperShim<String>(list);
53 observableList.addListener(observer);
54 builder = new ListChangeBuilderShim<String>(observableList);
55 }
56
57 @Test
58 public void testAddRemove() {
59 builder.beginChange();
60 list.remove(2);
61 builder.nextRemove(2, "c");
62 list.add(2, "cc");
63 list.add(3, "ccc");
64 builder.nextAdd(2, 4);
65 list.remove(2);
66 builder.nextRemove(2, "cc");
67 list.remove(3);
68 builder.nextRemove(3, "d");
69 list.add(0, "aa");
70 builder.nextAdd(0, 1);
71 builder.endChange();
72
73 assertEquals(list, Arrays.asList("aa", "a", "b", "ccc"));
74
|