source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.groovy@ 6592

Last change on this file since 6592 was 2613, checked in by Gubaer, 15 years ago

new: global in-memory cache for downloaded changesets
new: toggle dialog for changesets
new: downloading of changesets (currently without changeset content, will follow later)

File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.net.InetAddress.Cache;
5import org.junit.Test
6
7
8import static org.junit.Assert.*;
9
10class ChangesetCacheTest {
11
12 @Test
13 public void test_Constructor() {
14 ChangesetCache cache = ChangesetCache.getInstance()
15 assert cache != null
16 }
17
18 @Test
19 public void test_addAndRemoveListeners() {
20 ChangesetCache cache = ChangesetCache.getInstance()
21 cache.clear()
22
23 // should work
24 cache.addChangesetCacheListener null
25
26 // should work
27 def listener = new ChangesetCacheListener() {
28 public void changesetCacheUpdated(ChangesetCacheEvent event) {}
29 }
30 cache.addChangesetCacheListener listener
31 // adding a second time - should work too
32 cache.addChangesetCacheListener listener
33 assert cache.@listeners.size() == 1 // ... but only added once
34
35 cache.removeChangesetCacheListener null
36
37 cache.removeChangesetCacheListener listener
38 assert cache.@listeners.size() == 0
39 }
40
41 @Test
42 public void update_get_remove_cycle() {
43 ChangesetCache cache = ChangesetCache.getInstance()
44 cache.clear()
45
46 cache.update new Changeset(1)
47 assert cache.size() == 1
48 assert cache.get(1) != null
49 assert cache.get(1).id == 1
50 cache.remove(1)
51 assert cache.size() == 0
52 }
53
54 @Test
55 public void updateTwice() {
56 ChangesetCache cache = ChangesetCache.getInstance()
57 cache.clear()
58
59 Changeset cs = new Changeset(1)
60 cs.incomplete = false
61 cs.put "key1", "value1"
62 cs.open = true
63 cache.update cs
64
65 Changeset cs2 = new Changeset(cs)
66 assert cs2 != null
67 cs2.put "key2", "value2"
68 cs2.open = false
69 cache.update(cs2)
70
71 assert cache.size() == 1
72 assert cache.get(1) != null
73
74 cs = cache.get(1)
75 assert cs.get("key1") == "value1"
76 assert cs.get("key2") == "value2"
77 assert !cs.open
78 }
79
80
81 @Test
82 public void contains() {
83 ChangesetCache cache = ChangesetCache.getInstance()
84 cache.@listeners.clear()
85 cache.clear()
86
87
88 Changeset cs = new Changeset(1)
89 cache.update cs
90
91 assert cache.contains(1)
92 assert cache.contains(cs)
93 assert cache.contains(new Changeset(cs))
94
95 assert ! cache.contains(2)
96 assert ! cache.contains(new Changeset(2))
97 assert ! cache.contains(null)
98 }
99
100 @Test
101 public void fireingEvents_AddAChangeset() {
102 ChangesetCache cache = ChangesetCache.getInstance()
103 cache.clear()
104 cache.@listeners.clear()
105
106 // should work
107 def listener = new ChangesetCacheListener() {
108 public void changesetCacheUpdated(ChangesetCacheEvent event) {
109 assert event != null
110 assert event.getAddedChangesets().size() == 1
111 assert event.getRemovedChangesets().empty
112 assert event.getUpdatedChangesets().empty
113 assert event.getSource() == cache
114 }
115 }
116 cache.addChangesetCacheListener listener
117 cache.update(new Changeset(1))
118 cache.removeChangesetCacheListener listener
119 }
120
121 @Test
122 public void fireingEvents_UpdateChangeset() {
123 ChangesetCache cache = ChangesetCache.getInstance()
124 cache.clear()
125 cache.@listeners.clear()
126
127 // should work
128 def listener = new ChangesetCacheListener() {
129 public void changesetCacheUpdated(ChangesetCacheEvent event) {
130 assert event != null
131 assert event.getAddedChangesets().empty
132 assert event.getRemovedChangesets().empty
133 assert event.getUpdatedChangesets().size() == 1
134 assert event.getSource() == cache
135 }
136 }
137 cache.update(new Changeset(1))
138
139 cache.addChangesetCacheListener listener
140 cache.update(new Changeset(1))
141 cache.removeChangesetCacheListener listener
142 }
143
144 @Test
145 public void fireingEvents_RemoveChangeset() {
146 ChangesetCache cache = ChangesetCache.getInstance()
147 cache.clear()
148 cache.@listeners.clear()
149
150 // should work
151 def listener = new ChangesetCacheListener() {
152 public void changesetCacheUpdated(ChangesetCacheEvent event) {
153 assert event != null
154 assert event.getAddedChangesets().empty
155 assert event.getRemovedChangesets().size() == 1
156 assert event.getUpdatedChangesets().empty
157 assert event.getSource() == cache
158 }
159 }
160 cache.update(new Changeset(1))
161
162 cache.addChangesetCacheListener listener
163 cache.remove 1
164 cache.removeChangesetCacheListener listener
165 }
166
167}
Note: See TracBrowser for help on using the repository browser.