Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / test / java / org / gvsig / fmap / mapcontext / tools / persistence / Point2DPersistenceFactoryTest.java @ 40559

History | View | Annotate | Download (3.15 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

    
30
import java.awt.geom.Point2D;
31

    
32
import org.easymock.MockControl;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37

    
38
/**
39
 * Unit tests for the class {@link Point2DPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class Point2DPersistenceFactoryTest extends
44
                AbstractLibraryAutoInitTestCase {
45

    
46
        private Point2DPersistenceFactory factory;
47
        private MockControl stateControl;
48
        private PersistentState state;
49
        private Point2D point;
50

    
51
        protected void doSetUp() throws Exception {
52
                PersistenceManager persistenceManager = ToolsLocator
53
                                .getPersistenceManager();
54
                factory = (Point2DPersistenceFactory) persistenceManager.getFactories()
55
                                .get(Point2D.class);
56
                stateControl = MockControl.createNiceControl(PersistentState.class);
57
                state = (PersistentState) stateControl.getMock();
58
                double x = Math.random() * 1000d;
59
                double y = Math.random() * 1000d;
60
                point = new Point2D.Double(x, y);
61
        }
62

    
63
        /**
64
         * Test method for
65
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)}
66
         * .
67
         */
68
        public void testCreateFromState() throws Exception {
69
                stateControl.expectAndReturn(state
70
                                .getDouble(Point2DPersistenceFactory.FIELD_X), point.getX());
71
                stateControl.expectAndReturn(state
72
                                .getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY());
73
                stateControl.replay();
74

    
75
                Point2D newPoint = (Point2D) factory.createFromState(state);
76
                assertTrue(newPoint.equals(point));
77

    
78
                stateControl.verify();
79
        }
80

    
81
        /**
82
         * Test method for
83
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
84
         * .
85
         */
86
        public void testSaveToState() throws Exception {
87
                state.set(Point2DPersistenceFactory.FIELD_X, point.getX());
88
                state.set(Point2DPersistenceFactory.FIELD_Y, point.getY());
89
                stateControl.replay();
90

    
91
                factory.saveToState(state, point);
92

    
93
                stateControl.verify();
94
        }
95
}