root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / tools / persistence / Point2DPersistenceFactoryTest.java @ 32880
History | View | Annotate | Download (2.96 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
28 |
|
29 |
import java.awt.geom.Point2D; |
30 |
|
31 |
import org.easymock.MockControl; |
32 |
import org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory; |
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
34 |
import org.gvsig.tools.persistence.PersistentState; |
35 |
|
36 |
/**
|
37 |
* Unit tests for the class {@link Point2DPersistenceFactory}.
|
38 |
*
|
39 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
40 |
*/
|
41 |
public class Point2DPersistenceFactoryTest extends |
42 |
AbstractLibraryAutoInitTestCase { |
43 |
|
44 |
private Point2DPersistenceFactory factory;
|
45 |
private MockControl stateControl;
|
46 |
private PersistentState state;
|
47 |
private Point2D point; |
48 |
|
49 |
protected void doSetUp() throws Exception { |
50 |
factory = new Point2DPersistenceFactory();
|
51 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
52 |
state = (PersistentState) stateControl.getMock(); |
53 |
double x = Math.random() * 1000d; |
54 |
double y = Math.random() * 1000d; |
55 |
point = new Point2D.Double(x, y); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Test method for
|
60 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)}
|
61 |
* .
|
62 |
*/
|
63 |
public void testCreateFromState() throws Exception { |
64 |
stateControl.expectAndReturn(state |
65 |
.getDouble(Point2DPersistenceFactory.FIELD_X), point.getX()); |
66 |
stateControl.expectAndReturn(state |
67 |
.getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY()); |
68 |
stateControl.replay(); |
69 |
|
70 |
Point2D newPoint = (Point2D) factory.createFromState(state); |
71 |
assertTrue(newPoint.equals(point)); |
72 |
|
73 |
stateControl.verify(); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Test method for
|
78 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
|
79 |
* .
|
80 |
*/
|
81 |
public void testSaveToState() throws Exception { |
82 |
state.set(Point2DPersistenceFactory.FIELD_X, point.getX()); |
83 |
state.set(Point2DPersistenceFactory.FIELD_Y, point.getY()); |
84 |
stateControl.replay(); |
85 |
|
86 |
factory.saveToState(state, point); |
87 |
|
88 |
stateControl.verify(); |
89 |
} |
90 |
} |