Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2011 / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / tools / persistence / ColorPersistenceFactoryTest.java @ 33562

History | View | Annotate | Download (3.32 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.Color;
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 ColorPersistenceFactory}.
39
 * 
40
 * @author gvSIG team
41
 */
42
public class ColorPersistenceFactoryTest extends
43
                AbstractLibraryAutoInitTestCase {
44

    
45
        private ColorPersistenceFactory factory;
46
        private MockControl stateControl;
47
        private PersistentState state;
48
        private Color color;
49

    
50
        protected void doSetUp() throws Exception {
51
                PersistenceManager persistenceManager = ToolsLocator
52
                                .getPersistenceManager();
53
                factory = (ColorPersistenceFactory) persistenceManager.getFactories()
54
                                .get(Color.class);
55
                stateControl = MockControl.createNiceControl(PersistentState.class);
56
                state = (PersistentState) stateControl.getMock();
57
                color = Color.magenta;
58
        }
59

    
60
        /**
61
         * Test method for
62
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
63
         * .
64
         */
65
        public void testCreateFromState() throws Exception {
66
                stateControl.expectAndReturn(state
67
                                .getInt(ColorPersistenceFactory.FIELD_RED), color.getRed());
68
                stateControl.expectAndReturn(state
69
                                .getInt(ColorPersistenceFactory.FIELD_GREEN), color.getGreen());
70
                stateControl.expectAndReturn(state
71
                                .getInt(ColorPersistenceFactory.FIELD_BLUE), color.getBlue());
72
                stateControl.expectAndReturn(state
73
                                .getInt(ColorPersistenceFactory.FIELD_ALPHA), color.getAlpha());
74
                stateControl.replay();
75

    
76
                Color newColor = (Color) factory.createFromState(state);
77
                assertTrue(newColor.equals(color));
78

    
79
                stateControl.verify();
80
        }
81

    
82
        /**
83
         * Test method for
84
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
85
         * .
86
         */
87
        public void testSaveToState() throws Exception {
88
                state.set(ColorPersistenceFactory.FIELD_RED, color.getRed());
89
                state.set(ColorPersistenceFactory.FIELD_GREEN, color.getGreen());
90
                state.set(ColorPersistenceFactory.FIELD_BLUE, color.getBlue());
91
                state.set(ColorPersistenceFactory.FIELD_ALPHA, color.getAlpha());
92
                stateControl.replay();
93

    
94
                factory.saveToState(state, color);
95

    
96
                stateControl.verify();
97
        }
98

    
99
}