Search in sources :

Example 6 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class TestObservableArrayListWriteOperations method removeListener_shouldNotFireListener.

// TODO: removeAll, retainAll
// ////////////////////////////////////////
// add(Object)
// ////////////////////////////////////////
@Test
public void removeListener_shouldNotFireListener() {
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    final TestListChangeListener listener = new TestListChangeListener();
    final Subscription subscription = list.onChanged(listener);
    subscription.unsubscribe();
    list.add("42");
    assertThat(listener.calls, is(0));
}
Also used : ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Subscription(com.canoo.platform.core.functional.Subscription) Test(org.testng.annotations.Test)

Example 7 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class TestObservableArrayList method testRetainAll.

@Test
public void testRetainAll() {
    final AtomicBoolean removed = new AtomicBoolean(false);
    final AtomicBoolean added = new AtomicBoolean(false);
    final AtomicInteger callCount = new AtomicInteger(0);
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals(list.size(), 0);
    addOnChangeListener(removed, added, callCount, list);
    list.addAll("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 10);
    Assert.assertTrue(added.get());
    Assert.assertFalse(removed.get());
    list.retainAll(Arrays.asList("1", "2", "3", "4", "5"));
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 5);
    assertSameContent(list, Arrays.asList("1", "2", "3", "4", "5"));
    Assert.assertTrue(removed.get());
    Assert.assertFalse(added.get());
    Assert.assertEquals(callCount.get(), 6);
    list.clear();
    list.addAll("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 10);
    list.retainAll("1", "2", "3", "4", "5");
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 5);
    assertSameContent(list, Arrays.asList("1", "2", "3", "4", "5"));
    list.clear();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 8 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class TestObservableArrayList method testRemoveAll.

@Test
public void testRemoveAll() {
    final AtomicBoolean removed = new AtomicBoolean(false);
    final AtomicBoolean added = new AtomicBoolean(false);
    final AtomicInteger callCount = new AtomicInteger(0);
    final ObservableArrayList<String> list = new ObservableArrayList<>();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals(list.size(), 0);
    addOnChangeListener(removed, added, callCount, list);
    list.addAll("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 10);
    Assert.assertTrue(added.get());
    Assert.assertFalse(removed.get());
    list.removeAll(Arrays.asList("1", "2", "3", "4", "5"));
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.size(), 5);
    assertSameContent(list, Arrays.asList("6", "7", "8", "9", "10"));
    Assert.assertTrue(removed.get());
    Assert.assertFalse(added.get());
    Assert.assertEquals(6, callCount.get());
    list.clear();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 9 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class FXBinderTest method testSeveralBinds.

@Test
public void testSeveralBinds() {
    ObservableList<String> dolphinList = new ObservableArrayList<>();
    javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    for (int i = 0; i < 10; i++) {
        Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
        binding.unbind();
    }
    dolphinList.addAll(Arrays.asList("A", "B", "C"));
    for (int i = 0; i < 10; i++) {
        Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
        binding.unbind();
    }
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 10 with ObservableArrayList

use of com.canoo.dp.impl.remoting.collections.ObservableArrayList in project dolphin-platform by canoo.

the class FXBinderTest method testListBinding.

@Test
public void testListBinding() {
    ObservableList<String> dolphinList = new ObservableArrayList<>();
    javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
    assertEquals(dolphinList.size(), 0);
    assertEquals(javaFXList.size(), 0);
    dolphinList.add("Hello");
    assertEquals(dolphinList.size(), 1);
    assertEquals(javaFXList.size(), 1);
    assertTrue(dolphinList.contains("Hello"));
    assertTrue(javaFXList.contains("Hello"));
    dolphinList.add("World");
    dolphinList.add("Dolphin");
    assertEquals(dolphinList.size(), 3);
    assertEquals(javaFXList.size(), 3);
    assertEquals(dolphinList.indexOf("Hello"), 0);
    assertEquals(dolphinList.indexOf("World"), 1);
    assertEquals(dolphinList.indexOf("Dolphin"), 2);
    assertEquals(javaFXList.indexOf("Hello"), 0);
    assertEquals(javaFXList.indexOf("World"), 1);
    assertEquals(javaFXList.indexOf("Dolphin"), 2);
    dolphinList.clear();
    assertEquals(dolphinList.size(), 0);
    assertEquals(javaFXList.size(), 0);
    dolphinList.add("Java");
    assertEquals(dolphinList.size(), 1);
    assertEquals(javaFXList.size(), 1);
    assertTrue(dolphinList.contains("Java"));
    assertTrue(javaFXList.contains("Java"));
    binding.unbind();
    assertEquals(dolphinList.size(), 1);
    assertEquals(javaFXList.size(), 1);
    assertTrue(dolphinList.contains("Java"));
    assertTrue(javaFXList.contains("Java"));
    dolphinList.add("Duke");
    assertEquals(dolphinList.size(), 2);
    assertEquals(javaFXList.size(), 1);
    assertTrue(dolphinList.contains("Java"));
    assertTrue(dolphinList.contains("Duke"));
    assertTrue(javaFXList.contains("Java"));
    FXBinder.bind(javaFXList).to(dolphinList);
    dolphinList.clear();
    assertEquals(dolphinList.size(), 0);
    assertEquals(javaFXList.size(), 0);
    Runnable check = () -> {
        assertEquals(dolphinList.size(), 4);
        assertEquals(javaFXList.size(), 4);
        assertEquals(dolphinList.indexOf("A"), 0);
        assertEquals(dolphinList.indexOf("B"), 1);
        assertEquals(dolphinList.indexOf("C"), 2);
        assertEquals(dolphinList.indexOf("D"), 3);
        assertEquals(javaFXList.indexOf("A"), 0);
        assertEquals(javaFXList.indexOf("B"), 1);
        assertEquals(javaFXList.indexOf("C"), 2);
        assertEquals(javaFXList.indexOf("D"), 3);
    };
    // add first
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("B", "C", "D"));
    dolphinList.add(0, "A");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("C", "D"));
    dolphinList.add(0, "A");
    dolphinList.add(1, "B");
    check.run();
    // add any
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "D"));
    dolphinList.add(2, "C");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "D"));
    dolphinList.add(1, "B");
    dolphinList.add(2, "C");
    check.run();
    // add last
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C"));
    dolphinList.add(3, "D");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B"));
    dolphinList.add(2, "C");
    dolphinList.add(3, "D");
    check.run();
    // removePresentationModel first
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X", "A", "B", "C", "D"));
    dolphinList.remove(0);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X", "A", "B", "C", "D"));
    dolphinList.remove("X");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X1", "X2", "A", "B", "C", "D"));
    dolphinList.remove(0);
    dolphinList.remove(0);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X1", "X2", "A", "B", "C", "D"));
    dolphinList.remove("X1");
    dolphinList.remove("X2");
    check.run();
    // removePresentationModel any
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X", "C", "D"));
    dolphinList.remove(2);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X", "C", "D"));
    dolphinList.remove("X");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2", "C", "D"));
    dolphinList.remove(2);
    dolphinList.remove(2);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2", "C", "D"));
    dolphinList.remove("X1");
    dolphinList.remove("X2");
    check.run();
    // removePresentationModel last
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X"));
    dolphinList.remove(4);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X"));
    dolphinList.remove("X");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X1", "X2"));
    dolphinList.remove(5);
    dolphinList.remove(4);
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X1", "X2"));
    dolphinList.remove("X1");
    dolphinList.remove("X2");
    check.run();
    // set first
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X", "B", "C", "D"));
    dolphinList.set(0, "A");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("X1", "X2", "C", "D"));
    dolphinList.set(0, "A");
    dolphinList.set(1, "B");
    check.run();
    // set any
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X", "D"));
    dolphinList.set(2, "C");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "X1", "X2", "D"));
    dolphinList.set(1, "B");
    dolphinList.set(2, "C");
    check.run();
    // set last
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "X"));
    dolphinList.set(3, "D");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2"));
    dolphinList.set(2, "C");
    dolphinList.set(3, "D");
    check.run();
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "C", "X1", "X2", "X3", "D"));
    dolphinList.remove("X1");
    dolphinList.remove("X2");
    dolphinList.remove("X3");
    assertEquals(dolphinList.size(), 4);
    assertEquals(javaFXList.size(), 4);
    assertEquals(dolphinList.indexOf("A"), 0);
    assertEquals(dolphinList.indexOf("B"), 1);
    assertEquals(dolphinList.indexOf("C"), 2);
    assertEquals(dolphinList.indexOf("D"), 3);
    assertEquals(javaFXList.indexOf("A"), 0);
    assertEquals(javaFXList.indexOf("B"), 1);
    assertEquals(javaFXList.indexOf("C"), 2);
    assertEquals(javaFXList.indexOf("D"), 3);
    dolphinList.clear();
    dolphinList.addAll(Arrays.asList("A", "B", "F", "D"));
    dolphinList.set(2, "C");
    assertEquals(dolphinList.size(), 4);
    assertEquals(javaFXList.size(), 4);
    assertEquals(dolphinList.indexOf("A"), 0);
    assertEquals(dolphinList.indexOf("B"), 1);
    assertEquals(dolphinList.indexOf("C"), 2);
    assertEquals(dolphinList.indexOf("D"), 3);
    assertEquals(javaFXList.indexOf("A"), 0);
    assertEquals(javaFXList.indexOf("B"), 1);
    assertEquals(javaFXList.indexOf("C"), 2);
    assertEquals(javaFXList.indexOf("D"), 3);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Aggregations

ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)11 Test (org.testng.annotations.Test)11 Binding (com.canoo.platform.core.functional.Binding)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Subscription (com.canoo.platform.core.functional.Subscription)2