Statistics
| Revision:

root / tags / v2_0_0_Build_2011 / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / tools / persistence / FontPersistenceFactoryTest.java @ 33562

History | View | Annotate | Download (3.21 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.Font;
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 FontPersistenceFactory}.
39
 * 
40
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
41
 */
42
public class FontPersistenceFactoryTest extends AbstractLibraryAutoInitTestCase {
43

    
44
        private FontPersistenceFactory factory;
45
        private MockControl stateControl;
46
        private PersistentState state;
47
        private Font font;
48

    
49
        protected void doSetUp() throws Exception {
50
                PersistenceManager persistenceManager = ToolsLocator
51
                                .getPersistenceManager();
52
                factory = (FontPersistenceFactory) persistenceManager.getFactories()
53
                                .get(Font.class);
54
                stateControl = MockControl.createNiceControl(PersistentState.class);
55
                state = (PersistentState) stateControl.getMock();
56
                font = new Font("Arial", Font.BOLD, 18);
57
        }
58

    
59
        /**
60
         * Test method for
61
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
62
         * .
63
         */
64
        public void testCreateFromState() throws Exception {
65
                stateControl.expectAndReturn(state
66
                                .getString(FontPersistenceFactory.FIELD_NAME), font.getName());
67
                stateControl.expectAndReturn(state
68
                                .getInt(FontPersistenceFactory.FIELD_STYLE), font.getStyle());
69
                stateControl.expectAndReturn(state
70
                                .getInt(FontPersistenceFactory.FIELD_SIZE), font.getSize());
71
                stateControl.replay();
72

    
73
                Font newFont = (Font) factory.createFromState(state);
74
                assertTrue(newFont.equals(font));
75

    
76
                stateControl.verify();
77
        }
78

    
79
        /**
80
         * Test method for
81
         * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
82
         * .
83
         */
84
        public void testSaveToState() throws Exception {
85
                state.set(FontPersistenceFactory.FIELD_NAME, font.getName());
86
                state.set(FontPersistenceFactory.FIELD_STYLE, font.getStyle());
87
                state.set(FontPersistenceFactory.FIELD_SIZE, font.getSize());
88
                stateControl.replay();
89

    
90
                factory.saveToState(state, font);
91

    
92
                stateControl.verify();
93
        }
94

    
95
}