コード例 #1
0
  /**
   * Test when user add new icon, after that repeats click on icon and chaotic click on map to move
   * editing icon At the end is succ finish => icon should be at the last click position
   */
  private void tstClickOnMapEditingAndFinish() {
    // simple add and finish adding of new item
    map.clearOverlays();
    mapAddOverlayEvents.clear();
    mapRemoveOverlayEvents.clear();
    MapControllerT mc = new MapControllerT(map, service);
    mc.startAdding();
    LatLng ll1 = getRandomLatLng();
    mc.onMapClick(new MapClickEvent(map, null, ll1, null));
    mc.finishWorking(false);

    // now presenter is calling web service to save and after succ. save is called onAddItem
    MapItem mapItem = RandomGenerator.genMapItem(false);
    LatLng mapItemLatLng = LatLng.newInstance(mapItem.getY(), mapItem.getX());
    mc.addMapItem(mapItem);
    MapItemOverlay<MapItem> mi = (MapItemOverlay<MapItem>) mapAddOverlayEvents.get(1).getOverlay();
    DataComparator.assertEquals(mapItemLatLng, mi.getLatLng());

    // simulate click on icon
    mc.startEditing(mi);

    LatLng ll = null;
    for (int i = 0; i < 10; i++) // just chaotic click, icon should moves
    {
      ll = getRandomLatLng();
      mc.onMapClick(new MapClickEvent(map, null, ll, null));
      DataComparator.assertEquals(ll, mi.getLatLng());
      DataComparator.assertEquals(mapItemLatLng, mc.mStartEditLatLng);
    }

    mc.finishWorking(false); // finished => not canceled
    assertEquals(mc.mState, State.Default);
    assertNull(mc.mCurrentMarker);
    assertNull(mc.mStartEditLatLng);
    // after finish nothing should happen
    assertEquals(1, mc.mCurrentVisibleMapItems.size());
    assertEquals(2, mapAddOverlayEvents.size());
    assertEquals(1, mapRemoveOverlayEvents.size());
    // only editing icon should be at the last click position
    DataComparator.assertEquals(ll, mi.getLatLng());
  }
コード例 #2
0
 private LatLng getRandomLatLng() {
   return LatLng.newInstance(RandomGenerator.genRandomY(), RandomGenerator.genRandomX());
 }
コード例 #3
0
  private void tstLoadData() {
    // simple add and finish adding of new item
    map.clearOverlays();
    mapAddOverlayEvents.clear();
    mapRemoveOverlayEvents.clear();

    MapControllerT mc = new MapControllerT(map, service);
    randomData = new ArrayList<MapItem>();
    int iterator = 0;
    for (; iterator < 20; iterator++) {
      MapItem mi = RandomGenerator.genMapItem(false);
      mi.setId(iterator); // init ids
      randomData.add(mi);
    }

    service.setOnGetListener(
        new MockDataServiceAsync.OnGetListener() {
          @Override
          public void get(
              String className, String filters, boolean deep, AsyncCallback<List<?>> callback) {}

          @Override
          public void get(
              String className,
              double x1,
              double x2,
              double y1,
              double y2,
              boolean deep,
              AsyncCallback<List<?>> callback) {
            callback.onSuccess(randomData);
          }

          @Override
          public void get(String className, AsyncCallback<List<?>> callback) {}
        });

    // simulate map drag move
    LatLngBounds llb =
        LatLngBounds.newInstance(LatLng.newInstance(0, 0), LatLng.newInstance(80, 80));
    mc.loadIcons(12, llb); // just ensure about good zoom limit
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    // call again, no new icon should be added into map
    mc.loadIcons(12, llb); //
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    // add 10 new icons into database simulates different db result depending on latlngbounds
    for (; iterator < 30; iterator++) {
      MapItem mi = RandomGenerator.genMapItem(false);
      mi.setId(iterator); // init ids
      randomData.add(mi);
    }

    // call again, only 10 news icon should be added into map
    mc.loadIcons(12, llb); //
    assertTrue(mc.calledOnLoad); // should becalled
    mc.calledOnLoad = false;
    assertEquals(randomData.size(), mc.mCurrentVisibleMapItems.size()); // this icons should be here
    assertEquals(randomData.size(), mapAddOverlayEvents.size());

    for (int i = 0; i < iterator; i++) {
      long l = i;
      // check added data, should be same
      assertTrue(mc.mCurrentVisibleMapItems.containsKey(l));
      MapItemOverlay<MapItem> mi =
          (MapItemOverlay<MapItem>) mapAddOverlayEvents.get(i).getOverlay();
      DataComparator.assertEquals(randomData.get(i), mi.getMapItem(), true);
      DataComparator.assertEquals(randomData.get(i), mi.getMapItem(), true);
    }
  }