@Test
  public void testCreateBasedOnGeomToCreate() throws Exception {
    TestEditBlackboard bb = new TestEditBlackboard();
    String fid = "FeatureID";
    EditGeom geom = bb.newGeom(fid, null);
    bb.addPoint(10, 10, geom.getShell());
    EditGeom geom2 = bb.newGeom(fid, null);
    AttributeTypeBuilder builder = new AttributeTypeBuilder();
    builder.setBinding(Geometry.class);
    builder.setName("geom");
    GeometryDescriptor at =
        (GeometryDescriptor) builder.buildDescriptor("geom", builder.buildGeometryType());
    Map<String, Bag> result = GeometryCreationUtil.createAllGeoms(geom, Point.class, at, false);

    assertEquals(1, result.get(fid).jts.size());

    bb.addPoint(100, 100, geom2.getShell());
    result = GeometryCreationUtil.createAllGeoms(geom, Point.class, at, false);

    assertEquals(1, result.size());
    assertEquals(2, result.get(fid).jts.size());
    assertEquals(Point.class, result.get(fid).jts.get(0).getClass());
    assertEquals(Point.class, result.get(fid).jts.get(1).getClass());

    String fid2 = "FID2";
    EditGeom differentGeom = bb.newGeom(fid2, null);
    bb.addPoint(200, 200, differentGeom.getShell());

    result = GeometryCreationUtil.createAllGeoms(geom, Point.class, at, false);
    assertEquals(2, result.size());
    assertEquals(2, result.get(fid).jts.size());
    assertEquals(Point.class, result.get(fid).jts.get(0).getClass());
    assertEquals(Point.class, result.get(fid).jts.get(1).getClass());
    assertEquals(1, result.get(fid2).jts.size());
    assertEquals(Point.class, result.get(fid2).jts.get(0).getClass());

    result = GeometryCreationUtil.createAllGeoms(geom, LineString.class, at, false);
    assertEquals(2, result.size());
    assertEquals(2, result.get(fid).jts.size());
    assertEquals(LineString.class, result.get(fid).jts.get(0).getClass());
    assertEquals(LineString.class, result.get(fid).jts.get(1).getClass());
    assertEquals(1, result.get(fid2).jts.size());
    assertEquals(Point.class, result.get(fid2).jts.get(0).getClass());

    result = GeometryCreationUtil.createAllGeoms(geom, Polygon.class, at, false);
    assertEquals(2, result.size());
    assertEquals(2, result.get(fid).jts.size());
    assertEquals(Polygon.class, result.get(fid).jts.get(0).getClass());
    assertEquals(Polygon.class, result.get(fid).jts.get(1).getClass());
    assertEquals(1, result.get(fid2).jts.size());
    assertEquals(Point.class, result.get(fid2).jts.get(0).getClass());

    geom.getFeatureIDRef().set(null);
    geom2.getFeatureIDRef().set(null);

    result = GeometryCreationUtil.createAllGeoms(geom, Polygon.class, at, false);
    assertEquals(2, result.size());
    assertEquals(2, result.get(null).jts.size());
    assertEquals(Polygon.class, result.get(null).jts.get(0).getClass());
    assertEquals(Polygon.class, result.get(null).jts.get(1).getClass());
    assertEquals(1, result.get(fid2).jts.size());
    assertEquals(Point.class, result.get(fid2).jts.get(0).getClass());
  }
  @Test
  public void testSetup() throws Exception {
    EventListener l = new EventListener();
    EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    assertPixMapState(map, 1, 0, 0, 0);

    map.addPoint(10, 5, map.getGeoms().get(0).getShell());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(5, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 5), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    map.addPoint(10, 10, map.getGeoms().get(0).getShell());

    assertPixMapState(map, 1, 2, 0, 0);
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(EventType.ADD_POINT, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(null, editBlackboardEvent.getOldValue());
    assertEquals(Point.valueOf(10, 10), editBlackboardEvent.getNewValue());
    assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource());

    GeometryFactory factory = new GeometryFactory();
    Geometry geom = factory.createPoint(new Coordinate(10, 5));
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Map<Geometry, EditGeom> mapping = map.setGeometries(geom, null);
    assertNotNull(mapping.get(geom));
    assertEquals(ShapeType.POINT, mapping.get(geom).getShapeType());
    assertPixMapState(map, 1, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(EventType.SET_GEOMS, l.event.getType());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getOldValue()).size());
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPoint(new Coordinate[] {new Coordinate(10, 5), new Coordinate(20, 10)});
    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    String string = "featureID"; // $NON-NLS-1$
    mapping = map.setGeometries(geom, string);
    EditGeom next = mapping.values().iterator().next();
    assertEquals(ShapeType.POINT, next.getShapeType());
    assertEquals(string, next.getFeatureIDRef().get());
    assertNotNull(mapping.get(geom.getGeometryN(0)));
    assertNotNull(mapping.get(geom.getGeometryN(1)));
    assertPixMapState(map, 2, 1, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(1).getShell().getPoint(0).getX());
    assertEquals(15, map.getGeoms().get(1).getShell().getPoint(0).getY());
    assertEquals(new Coordinate(10, 5), map.getGeoms().get(0).getShell().getCoord(0));
    assertEquals(new Coordinate(20, 10), map.getGeoms().get(1).getShell().getCoord(0));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    LinearRing ring = createShellRing(factory, 10);

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(ring, null);
    assertEquals(ShapeType.LINE, mapping.get(ring).getShapeType());
    assertNotNull(mapping.get(ring));
    assertPixMapState(map, 1, 5, 0, 0);
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(1).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY());
    assertEquals(30, map.getGeoms().get(0).getShell().getPoint(2).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(2).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(3).getX());
    assertEquals(15, map.getGeoms().get(0).getShell().getPoint(3).getY());
    assertEquals(20, map.getGeoms().get(0).getShell().getPoint(4).getX());
    assertEquals(10, map.getGeoms().get(0).getShell().getPoint(4).getY());
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    Polygon polygon = createPolygon(factory, 10);
    mapping = map.setGeometries(polygon, null);
    assertEquals(ShapeType.POLYGON, mapping.get(polygon).getShapeType());
    assertNotNull(mapping.get(polygon));
    assertPixMapState(map, 1, 5, 1, 5);
    assertEquals(Point.valueOf(20, 10), map.getGeoms().get(0).getShell().getPoint(0));
    assertEquals(Point.valueOf(25, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(0));
    assertEquals(Point.valueOf(30, 10), map.getGeoms().get(0).getShell().getPoint(1));
    assertEquals(Point.valueOf(28, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(1));
    assertEquals(new Coordinate(15, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(0));
    assertEquals(new Coordinate(18, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(1));
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());

    geom =
        factory.createMultiPolygon(
            new Polygon[] {createPolygon(factory, 0), createPolygon(factory, 20)});

    map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
    map.getListeners().add(l);
    mapping = map.setGeometries(geom, null);
    assertPixMapState(map, 2, 5, 1, 5);
    editBlackboardEvent = l.getEditBlackboardEvent();
    assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size());
    assertEquals(map, editBlackboardEvent.getSource());
  }