Esempio n. 1
0
  @Test
  public void Put() throws Exception {
    final Map<String, String> base = new HashMap<String, String>();
    final ObservableMap<String, String> observable = new ObservableMap<String, String>(base);

    base.put("a", "1");
    base.put("b", "2");

    final EventLog log = new EventLog();
    observable.attach(log);

    observable.put("c", "3");

    assertEquals(MapFactory.start().add("a", "1").add("b", "2").add("c", "3").result(), base);
    assertEquals(1, log.size());

    log.clear();
    observable.put("b", "22");

    assertEquals(MapFactory.start().add("a", "1").add("b", "22").add("c", "3").result(), base);
    assertEquals(1, log.size());

    log.clear();
    observable.put("c", "3");

    assertEquals(MapFactory.start().add("a", "1").add("b", "22").add("c", "3").result(), base);
    assertEquals(0, log.size());
  }
Esempio n. 2
0
  @Test
  public void EntrySet() throws Exception {
    final Map<String, String> base = new LinkedHashMap<String, String>();
    final ObservableMap<String, String> observable = new ObservableMap<String, String>(base);

    base.put("a", "1");
    base.put("b", "2");
    base.put("c", "3");

    final EventLog log = new EventLog();
    observable.attach(log);

    final Iterator<Map.Entry<String, String>> itr = observable.entrySet().iterator();

    assertTrue(itr.hasNext());

    final Map.Entry<String, String> a = itr.next();

    assertEquals("a", a.getKey());
    assertEquals("1", a.getValue());

    assertTrue(itr.hasNext());

    final Map.Entry<String, String> b = itr.next();

    assertEquals("b", b.getKey());
    assertEquals("2", b.getValue());

    itr.remove();

    assertEquals(MapFactory.start().add("a", "1").add("c", "3").result(), base);
    assertEquals(1, log.size());

    assertTrue(itr.hasNext());

    final Map.Entry<String, String> c = itr.next();

    assertEquals("c", c.getKey());
    assertEquals("3", c.getValue());

    assertFalse(itr.hasNext());
  }