2626import com .google .protobuf .ListValue ;
2727import com .google .protobuf .NullValue ;
2828import java .math .BigDecimal ;
29+ import java .util .UUID ;
2930import org .junit .Test ;
3031import org .junit .runner .RunWith ;
3132import org .junit .runners .JUnit4 ;
@@ -51,6 +52,7 @@ public void of() {
5152 String numeric = "3.141592" ;
5253 String timestamp = "2015-09-15T00:00:00Z" ;
5354 String date = "2015-09-15" ;
55+ String uuid = UUID .randomUUID ().toString ();
5456 String json = "{\" color\" :\" red\" ,\" value\" :\" #f00\" }" ;
5557 k =
5658 Key .of (
@@ -65,8 +67,9 @@ public void of() {
6567 json ,
6668 ByteArray .copyFrom ("y" ),
6769 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 );
7073 assertThat (k .getParts ())
7174 .containsExactly (
7275 null ,
@@ -80,7 +83,8 @@ public void of() {
8083 json ,
8184 ByteArray .copyFrom ("y" ),
8285 Timestamp .parseTimestamp (timestamp ),
83- Date .parseDate (date ))
86+ Date .parseDate (date ),
87+ UUID .fromString (uuid ))
8488 .inOrder ();
8589
8690 // Singleton null key.
@@ -94,6 +98,7 @@ public void builder() {
9498 String numeric = "3.141592" ;
9599 String timestamp = "2015-09-15T00:00:00Z" ;
96100 String date = "2015-09-15" ;
101+ String uuid = UUID .randomUUID ().toString ();
97102 String json = "{\" color\" :\" red\" ,\" value\" :\" #f00\" }" ;
98103 Key k =
99104 Key .newBuilder ()
@@ -109,8 +114,9 @@ public void builder() {
109114 .append (ByteArray .copyFrom ("y" ))
110115 .append (Timestamp .parseTimestamp (timestamp ))
111116 .append (Date .parseDate (date ))
117+ .append (UUID .fromString (uuid ))
112118 .build ();
113- assertThat (k .size ()).isEqualTo (12 );
119+ assertThat (k .size ()).isEqualTo (13 );
114120 assertThat (k .getParts ())
115121 .containsExactly (
116122 null ,
@@ -124,7 +130,8 @@ public void builder() {
124130 json ,
125131 ByteArray .copyFrom ("y" ),
126132 Timestamp .parseTimestamp (timestamp ),
127- Date .parseDate (date ))
133+ Date .parseDate (date ),
134+ UUID .fromString (uuid ))
128135 .inOrder ();
129136 }
130137
@@ -153,6 +160,8 @@ public void testToString() {
153160 .isEqualTo ("[" + timestamp + "]" );
154161 String date = "2015-09-15" ;
155162 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 + "]" );
156165 assertThat (Key .of (1 , 2 , 3 ).toString ()).isEqualTo ("[1,2,3]" );
157166 }
158167
@@ -173,6 +182,7 @@ public void equalsAndHashCode() {
173182 Key .newBuilder ().append ((ByteArray ) null ).build (),
174183 Key .newBuilder ().append ((Timestamp ) null ).build (),
175184 Key .newBuilder ().append ((Date ) null ).build (),
185+ Key .newBuilder ().append ((UUID ) null ).build (),
176186 Key .newBuilder ().appendObject (null ).build ());
177187
178188 tester .addEqualityGroup (Key .of (true ), Key .newBuilder ().append (true ).build ());
@@ -197,6 +207,8 @@ public void equalsAndHashCode() {
197207 tester .addEqualityGroup (Key .of (t ), Key .newBuilder ().append (t ).build ());
198208 Date d = Date .parseDate ("2016-09-15" );
199209 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 ());
200212 tester .addEqualityGroup (Key .of ("a" , 2 , null ));
201213
202214 tester .testEquals ();
@@ -215,13 +227,15 @@ public void serialization() {
215227 reserializeAndAssert (Key .of (ByteArray .copyFrom ("xyz" )));
216228 reserializeAndAssert (Key .of (Timestamp .parseTimestamp ("2015-09-15T00:00:00Z" )));
217229 reserializeAndAssert (Key .of (Date .parseDate ("2015-09-15" )));
230+ reserializeAndAssert (Key .of (UUID .randomUUID ()));
218231 reserializeAndAssert (Key .of (1 , 2 , 3 ));
219232 }
220233
221234 @ Test
222235 public void toProto () {
223236 String timestamp = "2015-09-15T00:00:00Z" ;
224237 String date = "2015-09-15" ;
238+ String uuid = UUID .randomUUID ().toString ();
225239 Key k =
226240 Key .newBuilder ()
227241 .append ((Boolean ) null )
@@ -236,6 +250,7 @@ public void toProto() {
236250 .append (ByteArray .copyFrom ("y" ))
237251 .append (Timestamp .parseTimestamp (timestamp ))
238252 .append (Date .parseDate (date ))
253+ .append (UUID .fromString (uuid ))
239254 .build ();
240255 ListValue .Builder builder = ListValue .newBuilder ();
241256 builder .addValuesBuilder ().setNullValue (NullValue .NULL_VALUE );
@@ -250,6 +265,7 @@ public void toProto() {
250265 builder .addValuesBuilder ().setStringValue ("eQ==" );
251266 builder .addValuesBuilder ().setStringValue (timestamp );
252267 builder .addValuesBuilder ().setStringValue (date );
268+ builder .addValuesBuilder ().setStringValue (uuid );
253269 assertThat (k .toProto ()).isEqualTo (builder .build ());
254270 }
255271}
0 commit comments