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 @ 40559
History | View | Annotate | Download (3.84 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.get()); |
62 |
|
63 |
history = new ExtentHistory(2); |
64 |
|
65 |
history.put(rectangle); |
66 |
history.put(rectangle2); |
67 |
history.put(rectangle3); |
68 |
|
69 |
assertEquals(rectangle3, history.get()); |
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.removePrev(); |
87 |
assertFalse(history.hasPrevious()); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Test method for {@link org.gvsig.fmap.mapcontext.ExtentHistory#get()}.
|
92 |
*/
|
93 |
public void testGet() { |
94 |
ExtentHistory history = new ExtentHistory();
|
95 |
|
96 |
assertNull("The ExtentHistory has got an element without adding one",
|
97 |
history.get()); |
98 |
|
99 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
100 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
101 |
|
102 |
history.put(rectangle); |
103 |
assertEquals(rectangle, history.get()); |
104 |
|
105 |
history.put(rectangle2); |
106 |
assertEquals(rectangle2, history.get()); |
107 |
|
108 |
history.removePrev(); |
109 |
assertEquals(rectangle, history.get()); |
110 |
|
111 |
history.removePrev(); |
112 |
assertNull("The ExtentHistory has got an element, "
|
113 |
+ "but all have been previously removed", history.get());
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Test method for
|
118 |
* {@link org.gvsig.fmap.mapcontext.ExtentHistory#removePrev()}.
|
119 |
*/
|
120 |
public void testRemovePrev() { |
121 |
ExtentHistory history = new ExtentHistory();
|
122 |
|
123 |
assertNull( |
124 |
"The ExtentHistory allows removing an element without adding "
|
125 |
+ "at least one", history.removePrev());
|
126 |
|
127 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
128 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
129 |
|
130 |
history.put(rectangle); |
131 |
history.put(rectangle2); |
132 |
|
133 |
history.removePrev(); |
134 |
assertEquals(rectangle, history.get()); |
135 |
|
136 |
history.removePrev(); |
137 |
assertNull("The ExtentHistory allows to remove the last element, "
|
138 |
+ "but all have been previously removed", history.removePrev());
|
139 |
} |
140 |
} |