PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 6package org.sigmah.client.page.entry.editor;
 7
 8import org.junit.Assert;
 9import org.junit.Test;
10import org.sigmah.client.page.entry.editor.mock.MockMapView;
11import org.sigmah.shared.dto.BoundingBoxDTO;
12import org.sigmah.shared.dto.SiteDTO;
13
14/**
15 * @author Alex Bertram (akbertram@gmail.com)
16 */
17public class MapTest {
18
19    private static final double DELTA = 0.001;
20
21    @Test
22    public void testMapInitialView() {
23
24        // Collaborator: view
25        MockMapView map = new MockMapView();
26
27        // Class under test
28        MapPresenter presenter = new MapPresenter(map);
29
30        // VERIFY that the initial view is set to the admin bounds,
31        // and that, in the absence of X/Y data, the marker is set to
32        // the center of these Bounds
33
34        BoundingBoxDTO bounds = new BoundingBoxDTO(0, 0, 300, 300);
35
36        presenter.setSite(new SiteDTO(), null, bounds);
37
38        Assert.assertEquals(bounds, map.getMapView());
39        Assert.assertEquals(bounds.getCenterX(), map.markerX, DELTA);
40        Assert.assertEquals(bounds.getCenterY(), map.markerY, DELTA);
41    }
42
43
44    @Test
45    public void testMarkerMove() {
46
47
48        // Collaborator: view
49        MockMapView map = new MockMapView();
50
51        // Class under test
52        MapPresenter presenter = new MapPresenter(map);
53
54        // VERIFY that marker movement updates the coordinates
55
56        BoundingBoxDTO bounds = new BoundingBoxDTO(0, 0, 300, 200);
57        SiteDTO site = new SiteDTO();
58        site.setX(25.0);
59        site.setY(30.0);
60        presenter.setSite(site, null, bounds);
61
62        presenter.onMarkerMoved(50.0, 65.0);
63
64        Assert.assertEquals("y", 50.0, map.getY(), DELTA);
65        Assert.assertEquals("x", 65.0, map.getX(), DELTA);
66
67        // VERIFY that attempting to move the marker out of the
68        // bounds results in clamping
69
70        presenter.onMarkerMoved(900, 800);
71
72        Assert.assertEquals("marker x clamped", 300.0, map.markerX, DELTA);
73        Assert.assertEquals("marker y clamped", 200.0, map.markerY, DELTA);
74        Assert.assertEquals("coord x clamped", 300.0, map.getX(), DELTA);
75        Assert.assertEquals("coord y clamped", 200.0, map.getY(), DELTA);
76    }
77
78
79}