/sigmah/src/test/java/org/sigmah/client/page/entry/editor/MapTest.java

http://sigma-h.googlecode.com/ · Java · 79 lines · 37 code · 25 blank · 17 comment · 0 complexity · fb29a2edf8353ab8560ee47cd7d1ae9e MD5 · raw file

  1. /*
  2. * All Sigmah code is released under the GNU General Public License v3
  3. * See COPYRIGHT.txt and LICENSE.txt.
  4. */
  5. package org.sigmah.client.page.entry.editor;
  6. import org.junit.Assert;
  7. import org.junit.Test;
  8. import org.sigmah.client.page.entry.editor.mock.MockMapView;
  9. import org.sigmah.shared.dto.BoundingBoxDTO;
  10. import org.sigmah.shared.dto.SiteDTO;
  11. /**
  12. * @author Alex Bertram (akbertram@gmail.com)
  13. */
  14. public class MapTest {
  15. private static final double DELTA = 0.001;
  16. @Test
  17. public void testMapInitialView() {
  18. // Collaborator: view
  19. MockMapView map = new MockMapView();
  20. // Class under test
  21. MapPresenter presenter = new MapPresenter(map);
  22. // VERIFY that the initial view is set to the admin bounds,
  23. // and that, in the absence of X/Y data, the marker is set to
  24. // the center of these Bounds
  25. BoundingBoxDTO bounds = new BoundingBoxDTO(0, 0, 300, 300);
  26. presenter.setSite(new SiteDTO(), null, bounds);
  27. Assert.assertEquals(bounds, map.getMapView());
  28. Assert.assertEquals(bounds.getCenterX(), map.markerX, DELTA);
  29. Assert.assertEquals(bounds.getCenterY(), map.markerY, DELTA);
  30. }
  31. @Test
  32. public void testMarkerMove() {
  33. // Collaborator: view
  34. MockMapView map = new MockMapView();
  35. // Class under test
  36. MapPresenter presenter = new MapPresenter(map);
  37. // VERIFY that marker movement updates the coordinates
  38. BoundingBoxDTO bounds = new BoundingBoxDTO(0, 0, 300, 200);
  39. SiteDTO site = new SiteDTO();
  40. site.setX(25.0);
  41. site.setY(30.0);
  42. presenter.setSite(site, null, bounds);
  43. presenter.onMarkerMoved(50.0, 65.0);
  44. Assert.assertEquals("y", 50.0, map.getY(), DELTA);
  45. Assert.assertEquals("x", 65.0, map.getX(), DELTA);
  46. // VERIFY that attempting to move the marker out of the
  47. // bounds results in clamping
  48. presenter.onMarkerMoved(900, 800);
  49. Assert.assertEquals("marker x clamped", 300.0, map.markerX, DELTA);
  50. Assert.assertEquals("marker y clamped", 200.0, map.markerY, DELTA);
  51. Assert.assertEquals("coord x clamped", 300.0, map.getX(), DELTA);
  52. Assert.assertEquals("coord y clamped", 200.0, map.getY(), DELTA);
  53. }
  54. }