1
1
package org .github .goldsam .diffsync .core .context ;
2
2
3
3
import java .util .Arrays ;
4
- import java .util .List ;
5
- import org .github .goldsam .diffsync .core .ConnectionListener ;
6
4
import org .github .goldsam .diffsync .core .IntDifferencer ;
7
5
import org .github .goldsam .diffsync .core .MockConnectionListener ;
8
6
import org .github .goldsam .diffsync .core .MockContextListener ;
9
- import org .github .goldsam .diffsync .core .edit . Edit ;
7
+ import org .github .goldsam .diffsync .core .PatchFailedException ;
10
8
import org .github .goldsam .diffsync .core .edit .ImmutableEdit ;
11
9
import org .github .goldsam .diffsync .core .edit .MemoryEditStack ;
12
10
import org .junit .Test ;
13
11
import static org .junit .Assert .*;
14
- import org .junit .runner .RunWith ;
15
- import org .junit .runners .Parameterized ;
16
12
17
13
public class LocalContextTest {
18
14
@@ -97,7 +93,7 @@ public void updateAdvancesLocalVersion() {
97
93
assertEquals (localContext .getLocalVersion (), 1 );
98
94
99
95
localContext .update (-5 );
100
- assertEquals (localContext .getLocalVersion (), 2 );
96
+ assertEquals (localContext .getLocalVersion (), 2 );
101
97
}
102
98
103
99
@ Test
@@ -108,7 +104,7 @@ public void updateDoesNotAdvancesRemoteVersion() {
108
104
assertEquals (localContext .getRemoteVersion (), 0 );
109
105
110
106
localContext .update (-5 );
111
- assertEquals (localContext .getRemoteVersion (), 0 );
107
+ assertEquals (localContext .getRemoteVersion (), 0 );
112
108
}
113
109
114
110
@ Test
@@ -135,117 +131,104 @@ public void updatePushesToEditStack() {
135
131
Arrays .asList (new ImmutableEdit <>(6 , 0 ), new ImmutableEdit <>(-11 , 1 )),
136
132
localContext .getEdits ());
137
133
}
138
-
139
- //
134
+
135
+ @ Test
136
+ public void applyingEditsFromTheFutureDoesNothing () throws PatchFailedException {
137
+ initializeAndReset ();
138
+ localContext .update (6 );
139
+ localContext .update (-5 );
140
+
141
+ localContext .processEdits (Arrays .asList (new ImmutableEdit <>(-3 , 5L )), 0L );
142
+ assertEquals (
143
+ Arrays .asList (new ImmutableEdit <>(6 , 0 ), new ImmutableEdit <>(-11 , 1 )),
144
+ localContext .getEdits ());
145
+ assertEquals (localContext .getLocalVersion (), 2 );
146
+ assertEquals (localContext .getRemoteVersion (), 0 );
147
+ }
148
+
140
149
// @Test
141
- // public void updateShouldSetTheCurrentDocuent() {
142
- // initialize(true);;
143
- //
144
- // localContext.update(6);
145
- // assertEquals(Long.valueOf(6), localContext.getDocument());
146
- //
147
- // localContext.update(-5);
148
- // assertEquals(Long.valueOf(-5), localContext.getDocument());
150
+ // public void applyingEditMatchingRemoteAndLocalVersion_popsCorrespondingEditFromEditStack() throws PatchFailedException {
151
+ // initializeAndReset();
152
+ //// localContext.update(6);
153
+ //
154
+ // localContext.processEdits(Arrays.asList(new ImmutableEdit<>(6, 0)), 0L);
155
+ //// assertTrue("edit stack is empty", localContext.getEdits().isEmpty());
149
156
// }
157
+
158
+ @ Test
159
+ public void applyingEditsMatchingRemoteAndLocalVersion_updatesDocumentAndCurrentShadow () throws PatchFailedException {
160
+ initializeAndReset ();
161
+
162
+ localContext .processEdits (
163
+ Arrays .asList (
164
+ new ImmutableEdit <>(6 , 0 ),
165
+ new ImmutableEdit <>(-11 , 1 )),
166
+ 0L );
167
+ assertEquals (
168
+ Integer .valueOf (-5 ),
169
+ localContext .getDocument ());
170
+ }
171
+
172
+ @ Test
173
+ public void applyingEditMatchingRemoteAndLocalVersion_updatesRemoteVersion () throws PatchFailedException {
174
+ initializeAndReset ();
175
+
176
+ localContext .processEdits (
177
+ Arrays .asList (
178
+ new ImmutableEdit <>(6 , 0 ),
179
+ new ImmutableEdit <>(-11 , 1 )),
180
+ 0L );
181
+ assertEquals (2 , localContext .getRemoteVersion ());
182
+ }
183
+
184
+ @ Test
185
+ public void applyingEditMatchingRemoteAndLocalVersion_firesEditsAppliedEvent () throws PatchFailedException {
186
+ initializeAndReset ();
150
187
151
- // @Test
152
- // public void testGetSharedContext() {
153
- // System.out.println("getSharedContext");
154
- // LocalContext instance = null;
155
- // SharedContext expResult = null;
156
- // SharedContext result = instance.getSharedContext();
157
- // assertEquals(expResult, result);
158
- // fail("The test case is a prototype.");
159
- // }
160
- //
161
- // @Test
162
- // public void testGetConnectionListener() {
163
- // System.out.println("getConnectionListener");
164
- // LocalContext instance = null;
165
- // ConnectionListener expResult = null;
166
- // ConnectionListener result = instance.getConnectionListener();
167
- // assertEquals(expResult, result);
168
- // fail("The test case is a prototype.");
169
- // }
170
- //
171
- // @Test
172
- // public void testGetRemoteVersion() {
173
- // System.out.println("getRemoteVersion");
174
- // LocalContext instance = null;
175
- // long expResult = 0L;
176
- // long result = instance.getRemoteVersion();
177
- // assertEquals(expResult, result);
178
- // fail("The test case is a prototype.");
179
- // }
180
- //
181
- // @Test
182
- // public void testGetLocalVersion() {
183
- // System.out.println("getLocalVersion");
184
- // LocalContext instance = null;
185
- // long expResult = 0L;
186
- // long result = instance.getLocalVersion();
187
- // assertEquals(expResult, result);
188
- // fail("The test case is a prototype.");
189
- // }
190
- //
191
- // @Test
192
- // public void testReset_GenericType_long() {
193
- // System.out.println("reset");
194
- // Object document = null;
195
- // long version = 0L;
196
- // LocalContext instance = null;
197
- // instance.reset(document, version);
198
- // fail("The test case is a prototype.");
199
- // }
200
- //
201
- // @Test
202
- // public void testReset_long() {
203
- // System.out.println("reset");
204
- // long version = 0L;
205
- // LocalContext instance = null;
206
- // instance.reset(version);
207
- // fail("The test case is a prototype.");
208
- // }
209
- //
210
- // @Test
211
- // public void testReset_0args() {
212
- // System.out.println("reset");
213
- // LocalContext instance = null;
214
- // instance.reset();
215
- // fail("The test case is a prototype.");
216
- // }
217
- //
218
- // @Test
219
- // public void testUpdate_0args() {
220
- // System.out.println("update");
221
- // LocalContext instance = null;
222
- // instance.update();
223
- // fail("The test case is a prototype.");
224
- // }
225
- //
226
- // @Test
227
- // public void testUpdate_GenericType() {
228
- // System.out.println("update");
229
- // Object newCurrentDocument = null;
230
- // LocalContext instance = null;
231
- // instance.update(newCurrentDocument);
232
- // fail("The test case is a prototype.");
233
- // }
234
- //
235
- // @Test
236
- // public void testUpdate_Function() {
237
- // System.out.println("update");
238
- // LocalContext instance = null;
239
- // instance.update(null);
240
- // fail("The test case is a prototype.");
241
- // }
242
- //
243
- // @Test
244
- // public void testProcessEdits() throws Exception {
245
- // System.out.println("processEdits");
246
- // LocalContext instance = null;
247
- // instance.processEdits(null);
248
- // fail("The test case is a prototype.");
249
- // }
188
+ localContext .processEdits (
189
+ Arrays .asList (
190
+ new ImmutableEdit <>(6 , 0 ),
191
+ new ImmutableEdit <>(-11 , 1 )),
192
+ 0L );
193
+
194
+ assertEquals (
195
+ Arrays .asList (
196
+ new MockContextListener .ProcessedEdit <>(
197
+ localContext ,
198
+ Arrays .asList (
199
+ new ImmutableEdit <>(6 , 0 ),
200
+ new ImmutableEdit <>(-11 , 1 )),
201
+ -5 ,
202
+ 2L )),
203
+ contextListener .getProcessedEdits ());
204
+ }
250
205
206
+ @ Test
207
+ public void applyingEditsAfterLostReturnAck () throws PatchFailedException {
208
+ initializeAndReset ();
209
+
210
+ localContext .processEdits (
211
+ Arrays .asList (
212
+ new ImmutableEdit <>(6 , 0 )),
213
+ 0L );
214
+
215
+ localContext .update (8 );
216
+
217
+ localContext .processEdits (
218
+ Arrays .asList (
219
+ new ImmutableEdit <>(6 , 0 ),
220
+ new ImmutableEdit <>(-11 , 1 )),
221
+ 0L );
222
+ //
223
+ // assertEquals(
224
+ // Arrays.asList(
225
+ // new MockContextListener.ProcessedEdit<>(
226
+ // localContext,
227
+ // Arrays.asList(
228
+ // new ImmutableEdit<>(6, 0),
229
+ // new ImmutableEdit<>(-11, 1)),
230
+ // -5,
231
+ // 2L)),
232
+ // contextListener.getProcessedEdits());
233
+ }
251
234
}
0 commit comments