-
Notifications
You must be signed in to change notification settings - Fork 587
/
MultimapKeyValuesSerializingProcedureTest.java
149 lines (126 loc) · 4.14 KB
/
MultimapKeyValuesSerializingProcedureTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.block.procedure.checked;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Iterator;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.multimap.list.FastListMultimap;
import org.junit.Assert;
import org.junit.Test;
public class MultimapKeyValuesSerializingProcedureTest
{
@Test
public void testSerialization()
{
FastListMultimap<String, String> map = new FastListMultimap<>();
map.put("A", "alpha");
map.put("A", "beta");
FastList<? extends Serializable> expectedWrites = FastList.newListWith("A", 2, "alpha", "beta");
Procedure2<String, RichIterable<String>> procedure =
new MultimapKeyValuesSerializingProcedure<>(new MockObjectOutput(expectedWrites));
map.toMap().forEachKeyValue(procedure);
}
public static final class MockObjectOutput implements ObjectOutput
{
private final Iterator<? extends Serializable> iterator;
public MockObjectOutput(Iterable<? extends Serializable> expectedWrites)
{
this.iterator = expectedWrites.iterator();
}
@Override
public void writeObject(Object obj)
{
Assert.assertEquals(this.iterator.next(), obj);
}
@Override
public void writeInt(int v)
{
Assert.assertEquals(this.iterator.next(), v);
}
@Override
public void write(int i)
{
throw new RuntimeException("write not implemented");
}
@Override
public void write(byte[] bs)
{
throw new RuntimeException("write not implemented");
}
@Override
public void write(byte[] bs, int off, int len)
{
throw new RuntimeException("write not implemented");
}
@Override
public void writeBoolean(boolean v)
{
throw new RuntimeException("writeBoolean not implemented");
}
@Override
public void writeByte(int v)
{
throw new RuntimeException("writeByte not implemented");
}
@Override
public void writeShort(int v)
{
throw new RuntimeException("writeShort not implemented");
}
@Override
public void writeChar(int v)
{
throw new RuntimeException("writeChar not implemented");
}
@Override
public void writeLong(long v)
{
throw new RuntimeException("writeLong not implemented");
}
@Override
public void writeFloat(float v)
{
throw new RuntimeException("writeFloat not implemented");
}
@Override
public void writeDouble(double v)
{
throw new RuntimeException("writeDouble not implemented");
}
@Override
public void writeBytes(String s)
{
throw new RuntimeException("writeBytes not implemented");
}
@Override
public void writeChars(String s)
{
throw new RuntimeException("writeChars not implemented");
}
@Override
public void writeUTF(String s)
{
throw new RuntimeException("writeUTF not implemented");
}
@Override
public void flush()
{
throw new RuntimeException("flush not implemented");
}
@Override
public void close()
{
throw new RuntimeException("close not implemented");
}
}
}