root / tags / v2_0_0_Build_2011 / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / tools / persistence / Rectangle2DPersistenceFactoryTest.java @ 33562
History | View | Annotate | Download (4.3 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.Rectangle2D; |
30 |
|
31 |
import org.easymock.MockControl; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
35 |
import org.gvsig.tools.persistence.PersistentState; |
36 |
|
37 |
/**
|
38 |
* Unit tests for the class {@link Rectangle2DPersistenceFactory}.
|
39 |
*
|
40 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
41 |
*/
|
42 |
public class Rectangle2DPersistenceFactoryTest extends |
43 |
AbstractLibraryAutoInitTestCase { |
44 |
|
45 |
private Rectangle2DPersistenceFactory factory;
|
46 |
private MockControl stateControl;
|
47 |
private PersistentState state;
|
48 |
private Rectangle2D rectangle; |
49 |
|
50 |
protected void doSetUp() throws Exception { |
51 |
PersistenceManager persistenceManager = ToolsLocator |
52 |
.getPersistenceManager(); |
53 |
factory = (Rectangle2DPersistenceFactory) persistenceManager |
54 |
.getFactories().get(Rectangle2D.class);
|
55 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
56 |
state = (PersistentState) stateControl.getMock(); |
57 |
double x = Math.random() * 1000d; |
58 |
double y = Math.random() * 1000d; |
59 |
rectangle = new Rectangle2D.Double(x, y, 320, 200); |
60 |
} |
61 |
|
62 |
/**
|
63 |
* Test method for
|
64 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#createFromState(PersistentState, Class)}
|
65 |
* .
|
66 |
*/
|
67 |
public void testCreateFromState() throws Exception { |
68 |
stateControl.expectAndReturn(state |
69 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_X), rectangle |
70 |
.getX()); |
71 |
stateControl.expectAndReturn(state |
72 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_Y), rectangle |
73 |
.getY()); |
74 |
stateControl.expectAndReturn(state |
75 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_WIDTH), |
76 |
rectangle.getWidth()); |
77 |
stateControl.expectAndReturn(state |
78 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_HEIGHT), |
79 |
rectangle.getHeight()); |
80 |
stateControl.replay(); |
81 |
|
82 |
Rectangle2D newRectangle = (Rectangle2D) factory.createFromState(state); |
83 |
|
84 |
System.out.println("Orig x = " + rectangle.getX() + " - New x = " |
85 |
+ newRectangle.getX()); |
86 |
assertEquals(rectangle.getX(), newRectangle.getX(), 0.0d);
|
87 |
System.out.println("Orig y = " + rectangle.getY() + " - New y = " |
88 |
+ newRectangle.getY()); |
89 |
assertEquals(rectangle.getY(), newRectangle.getY(), 0.0d);
|
90 |
System.out.println("Orig width = " + rectangle.getWidth() |
91 |
+ " - New width = " + newRectangle.getWidth());
|
92 |
assertEquals(rectangle.getWidth(), newRectangle.getWidth(), 0.0d);
|
93 |
System.out.println("Orig height = " + rectangle.getHeight() |
94 |
+ " - New height = " + newRectangle.getHeight());
|
95 |
assertEquals(rectangle.getHeight(), newRectangle.getHeight(), 0.0d);
|
96 |
|
97 |
assertTrue(newRectangle.equals(rectangle)); |
98 |
|
99 |
stateControl.verify(); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Test method for
|
104 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
|
105 |
* .
|
106 |
*/
|
107 |
public void testSaveToState() throws Exception { |
108 |
state.set(Rectangle2DPersistenceFactory.FIELD_X, rectangle.getX()); |
109 |
state.set(Rectangle2DPersistenceFactory.FIELD_Y, rectangle.getY()); |
110 |
state.set(Rectangle2DPersistenceFactory.FIELD_WIDTH, rectangle |
111 |
.getWidth()); |
112 |
state.set(Rectangle2DPersistenceFactory.FIELD_HEIGHT, rectangle |
113 |
.getHeight()); |
114 |
stateControl.replay(); |
115 |
|
116 |
factory.saveToState(state, rectangle); |
117 |
|
118 |
stateControl.verify(); |
119 |
} |
120 |
} |