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 / Rectangle2DPersistenceFactoryTest.java @ 40559
History | View | Annotate | Download (4.34 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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.Rectangle2D; |
||
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 Rectangle2DPersistenceFactory}.
|
||
40 | *
|
||
41 | * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
||
42 | */
|
||
43 | public class Rectangle2DPersistenceFactoryTest extends |
||
44 | AbstractLibraryAutoInitTestCase { |
||
45 | |||
46 | private Rectangle2DPersistenceFactory factory;
|
||
47 | private MockControl stateControl;
|
||
48 | private PersistentState state;
|
||
49 | private Rectangle2D rectangle; |
||
50 | |||
51 | protected void doSetUp() throws Exception { |
||
52 | PersistenceManager persistenceManager = ToolsLocator |
||
53 | .getPersistenceManager(); |
||
54 | factory = (Rectangle2DPersistenceFactory) persistenceManager |
||
55 | .getFactories().get(Rectangle2D.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 | rectangle = new Rectangle2D.Double(x, y, 320, 200); |
||
61 | } |
||
62 | |||
63 | /**
|
||
64 | * Test method for
|
||
65 | * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#createFromState(PersistentState, Class)}
|
||
66 | * .
|
||
67 | */
|
||
68 | public void testCreateFromState() throws Exception { |
||
69 | stateControl.expectAndReturn(state |
||
70 | .getDouble(Rectangle2DPersistenceFactory.FIELD_X), rectangle |
||
71 | .getX()); |
||
72 | stateControl.expectAndReturn(state |
||
73 | .getDouble(Rectangle2DPersistenceFactory.FIELD_Y), rectangle |
||
74 | .getY()); |
||
75 | stateControl.expectAndReturn(state |
||
76 | .getDouble(Rectangle2DPersistenceFactory.FIELD_WIDTH), |
||
77 | rectangle.getWidth()); |
||
78 | stateControl.expectAndReturn(state |
||
79 | .getDouble(Rectangle2DPersistenceFactory.FIELD_HEIGHT), |
||
80 | rectangle.getHeight()); |
||
81 | stateControl.replay(); |
||
82 | |||
83 | Rectangle2D newRectangle = (Rectangle2D) factory.createFromState(state); |
||
84 | |||
85 | System.out.println("Orig x = " + rectangle.getX() + " - New x = " |
||
86 | + newRectangle.getX()); |
||
87 | assertEquals(rectangle.getX(), newRectangle.getX(), 0.0d);
|
||
88 | System.out.println("Orig y = " + rectangle.getY() + " - New y = " |
||
89 | + newRectangle.getY()); |
||
90 | assertEquals(rectangle.getY(), newRectangle.getY(), 0.0d);
|
||
91 | System.out.println("Orig width = " + rectangle.getWidth() |
||
92 | + " - New width = " + newRectangle.getWidth());
|
||
93 | assertEquals(rectangle.getWidth(), newRectangle.getWidth(), 0.0d);
|
||
94 | System.out.println("Orig height = " + rectangle.getHeight() |
||
95 | + " - New height = " + newRectangle.getHeight());
|
||
96 | assertEquals(rectangle.getHeight(), newRectangle.getHeight(), 0.0d);
|
||
97 | |||
98 | assertTrue(newRectangle.equals(rectangle)); |
||
99 | |||
100 | stateControl.verify(); |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Test method for
|
||
105 | * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
|
||
106 | * .
|
||
107 | */
|
||
108 | public void testSaveToState() throws Exception { |
||
109 | state.set(Rectangle2DPersistenceFactory.FIELD_X, rectangle.getX()); |
||
110 | state.set(Rectangle2DPersistenceFactory.FIELD_Y, rectangle.getY()); |
||
111 | state.set(Rectangle2DPersistenceFactory.FIELD_WIDTH, rectangle |
||
112 | .getWidth()); |
||
113 | state.set(Rectangle2DPersistenceFactory.FIELD_HEIGHT, rectangle |
||
114 | .getHeight()); |
||
115 | stateControl.replay(); |
||
116 | |||
117 | factory.saveToState(state, rectangle); |
||
118 | |||
119 | stateControl.verify(); |
||
120 | } |
||
121 | } |