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 / ExtentHistoryTest.java @ 42192

History | View | Annotate | Download (4.23 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;
29

    
30
import java.awt.Rectangle;
31
import java.awt.geom.Rectangle2D;
32

    
33
import junit.framework.TestCase;
34

    
35
/**
36
 * Unit tests for the class {@link ExtentHistory}.
37
 * 
38
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
39
 */
40
public class ExtentHistoryTest extends TestCase {
41

    
42
        protected void setUp() throws Exception {
43
                super.setUp();
44
        }
45

    
46
        /**
47
         * Test method for
48
         * {@link org.gvsig.fmap.mapcontext.ExtentHistory#put(java.awt.geom.Rectangle2D)}
49
         * .
50
         */
51
        public void testPut() {
52
                ExtentHistory history = new ExtentHistory();
53

    
54
                Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
55
                Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
56
                Rectangle2D rectangle3 = new Rectangle2D.Double(3, 3, 4, 4);
57
                history.put(rectangle3);
58
                history.put(rectangle2);
59
                history.put(rectangle);
60

    
61
                assertEquals(rectangle, history.getPrev());
62

    
63
                history = new ExtentHistory(2);
64

    
65
                history.put(rectangle);
66
                history.put(rectangle2);
67
                history.put(rectangle3);
68

    
69
                assertEquals(rectangle3, history.getPrev());
70
        }
71

    
72
        /**
73
         * Test method for
74
         * {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasPrevious()}.
75
         */
76
        public void testHasPrevious() {
77
                ExtentHistory history = new ExtentHistory();
78

    
79
                assertFalse(history.hasPrevious());
80

    
81
                Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
82
                history.put(rectangle);
83

    
84
                assertTrue(history.hasPrevious());
85

    
86
                history.setPreviousExtent(); //.getPrev();//.removePrev();
87
                assertFalse(history.hasPrevious());
88
        }
89

    
90
         /**
91
   * Test method for
92
   * {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasNext()}.
93
   */
94
  public void testHasNext() {
95
    ExtentHistory history = new ExtentHistory();
96

    
97
    assertFalse(history.hasNext());
98

    
99
    Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
100
    history.put(rectangle);
101

    
102
    assertTrue(history.hasPrevious());
103

    
104
    history.setPreviousExtent();
105
    assertTrue(history.hasNext());
106
  }
107

    
108
        /**
109
         * Test method for {@link org.gvsig.fmap.mapcontext.ExtentHistory#getPrev()}.
110
         */
111
        public void testGet() {
112
                ExtentHistory history = new ExtentHistory();
113

    
114
                assertNull("The ExtentHistory has got an element without adding one",
115
                                history.getPrev());
116

    
117
                Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
118
                Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
119

    
120
                history.put(rectangle);
121
                assertEquals(rectangle, history.getPrev());
122

    
123
                history.put(rectangle2);
124
                assertEquals(rectangle2, history.getPrev());
125

    
126
                assertEquals(rectangle, history.setPreviousExtent());
127

    
128
                assertNull("The ExtentHistory hasn't got a previous element", history.setPreviousExtent());
129
        }
130

    
131
        /**
132
         * Test method for
133
         * {@link org.gvsig.fmap.mapcontext.ExtentHistory#removePrev()}.
134
         */
135
        public void testRemovePrev() {
136
                ExtentHistory history = new ExtentHistory();
137

    
138
                assertNull(
139
                                "The ExtentHistory allows setting an element without adding "
140
                                                + "at least one", history.setPreviousExtent());
141

    
142
                Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
143
                Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
144

    
145
                history.put(rectangle);
146
                history.put(rectangle2);
147

    
148
                assertEquals(rectangle, history.setPreviousExtent());
149

    
150
                assertNull("The ExtentHistory allows to set the last element, "
151
                                + "but all have been previously removed", history.setPreviousExtent());
152
        }
153
}