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 / Rectangle2DPersistenceFactoryTest.java @ 40559

History | View | Annotate | Download (4.34 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.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
}