26
26
import com .google .protobuf .ListValue ;
27
27
import com .google .protobuf .NullValue ;
28
28
import java .math .BigDecimal ;
29
+ import java .util .UUID ;
29
30
import org .junit .Test ;
30
31
import org .junit .runner .RunWith ;
31
32
import org .junit .runners .JUnit4 ;
@@ -51,6 +52,7 @@ public void of() {
51
52
String numeric = "3.141592" ;
52
53
String timestamp = "2015-09-15T00:00:00Z" ;
53
54
String date = "2015-09-15" ;
55
+ String uuid = UUID .randomUUID ().toString ();
54
56
String json = "{\" color\" :\" red\" ,\" value\" :\" #f00\" }" ;
55
57
k =
56
58
Key .of (
@@ -65,8 +67,9 @@ public void of() {
65
67
json ,
66
68
ByteArray .copyFrom ("y" ),
67
69
Timestamp .parseTimestamp (timestamp ),
68
- Date .parseDate (date ));
69
- assertThat (k .size ()).isEqualTo (12 );
70
+ Date .parseDate (date ),
71
+ UUID .fromString (uuid ));
72
+ assertThat (k .size ()).isEqualTo (13 );
70
73
assertThat (k .getParts ())
71
74
.containsExactly (
72
75
null ,
@@ -80,7 +83,8 @@ public void of() {
80
83
json ,
81
84
ByteArray .copyFrom ("y" ),
82
85
Timestamp .parseTimestamp (timestamp ),
83
- Date .parseDate (date ))
86
+ Date .parseDate (date ),
87
+ UUID .fromString (uuid ))
84
88
.inOrder ();
85
89
86
90
// Singleton null key.
@@ -94,6 +98,7 @@ public void builder() {
94
98
String numeric = "3.141592" ;
95
99
String timestamp = "2015-09-15T00:00:00Z" ;
96
100
String date = "2015-09-15" ;
101
+ String uuid = UUID .randomUUID ().toString ();
97
102
String json = "{\" color\" :\" red\" ,\" value\" :\" #f00\" }" ;
98
103
Key k =
99
104
Key .newBuilder ()
@@ -109,8 +114,9 @@ public void builder() {
109
114
.append (ByteArray .copyFrom ("y" ))
110
115
.append (Timestamp .parseTimestamp (timestamp ))
111
116
.append (Date .parseDate (date ))
117
+ .append (UUID .fromString (uuid ))
112
118
.build ();
113
- assertThat (k .size ()).isEqualTo (12 );
119
+ assertThat (k .size ()).isEqualTo (13 );
114
120
assertThat (k .getParts ())
115
121
.containsExactly (
116
122
null ,
@@ -124,7 +130,8 @@ public void builder() {
124
130
json ,
125
131
ByteArray .copyFrom ("y" ),
126
132
Timestamp .parseTimestamp (timestamp ),
127
- Date .parseDate (date ))
133
+ Date .parseDate (date ),
134
+ UUID .fromString (uuid ))
128
135
.inOrder ();
129
136
}
130
137
@@ -153,6 +160,8 @@ public void testToString() {
153
160
.isEqualTo ("[" + timestamp + "]" );
154
161
String date = "2015-09-15" ;
155
162
assertThat (Key .of (Date .parseDate (date )).toString ()).isEqualTo ("[" + date + "]" );
163
+ String uuid = UUID .randomUUID ().toString ();
164
+ assertThat (Key .of (UUID .fromString (uuid )).toString ()).isEqualTo ("[" + uuid + "]" );
156
165
assertThat (Key .of (1 , 2 , 3 ).toString ()).isEqualTo ("[1,2,3]" );
157
166
}
158
167
@@ -173,6 +182,7 @@ public void equalsAndHashCode() {
173
182
Key .newBuilder ().append ((ByteArray ) null ).build (),
174
183
Key .newBuilder ().append ((Timestamp ) null ).build (),
175
184
Key .newBuilder ().append ((Date ) null ).build (),
185
+ Key .newBuilder ().append ((UUID ) null ).build (),
176
186
Key .newBuilder ().appendObject (null ).build ());
177
187
178
188
tester .addEqualityGroup (Key .of (true ), Key .newBuilder ().append (true ).build ());
@@ -197,6 +207,8 @@ public void equalsAndHashCode() {
197
207
tester .addEqualityGroup (Key .of (t ), Key .newBuilder ().append (t ).build ());
198
208
Date d = Date .parseDate ("2016-09-15" );
199
209
tester .addEqualityGroup (Key .of (d ), Key .newBuilder ().append (d ).build ());
210
+ UUID uuid = UUID .randomUUID ();
211
+ tester .addEqualityGroup (Key .of (uuid ), Key .newBuilder ().append (uuid ).build ());
200
212
tester .addEqualityGroup (Key .of ("a" , 2 , null ));
201
213
202
214
tester .testEquals ();
@@ -215,13 +227,15 @@ public void serialization() {
215
227
reserializeAndAssert (Key .of (ByteArray .copyFrom ("xyz" )));
216
228
reserializeAndAssert (Key .of (Timestamp .parseTimestamp ("2015-09-15T00:00:00Z" )));
217
229
reserializeAndAssert (Key .of (Date .parseDate ("2015-09-15" )));
230
+ reserializeAndAssert (Key .of (UUID .randomUUID ()));
218
231
reserializeAndAssert (Key .of (1 , 2 , 3 ));
219
232
}
220
233
221
234
@ Test
222
235
public void toProto () {
223
236
String timestamp = "2015-09-15T00:00:00Z" ;
224
237
String date = "2015-09-15" ;
238
+ String uuid = UUID .randomUUID ().toString ();
225
239
Key k =
226
240
Key .newBuilder ()
227
241
.append ((Boolean ) null )
@@ -236,6 +250,7 @@ public void toProto() {
236
250
.append (ByteArray .copyFrom ("y" ))
237
251
.append (Timestamp .parseTimestamp (timestamp ))
238
252
.append (Date .parseDate (date ))
253
+ .append (UUID .fromString (uuid ))
239
254
.build ();
240
255
ListValue .Builder builder = ListValue .newBuilder ();
241
256
builder .addValuesBuilder ().setNullValue (NullValue .NULL_VALUE );
@@ -250,6 +265,7 @@ public void toProto() {
250
265
builder .addValuesBuilder ().setStringValue ("eQ==" );
251
266
builder .addValuesBuilder ().setStringValue (timestamp );
252
267
builder .addValuesBuilder ().setStringValue (date );
268
+ builder .addValuesBuilder ().setStringValue (uuid );
253
269
assertThat (k .toProto ()).isEqualTo (builder .build ());
254
270
}
255
271
}
0 commit comments