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

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

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

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

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

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

    
80
                stateControl.verify();
81
        }
82

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

    
95
                factory.saveToState(state, color);
96

    
97
                stateControl.verify();
98
        }
99

    
100
}