3131import static org .junit .Assert .assertEquals ;
3232import static org .junit .Assert .fail ;
3333
34- /** Tests for {@link DatastoreHelper}. */
34+ /**
35+ * Tests for {@link DatastoreHelper}.
36+ */
3537@ RunWith (JUnit4 .class )
3638public class DatastoreHelperTest {
3739
3840 private static final Key PARENT =
39- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Parent" ).setId (23L )).build ();
41+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Parent" ).setId (23L )).build ();
4042 private static final Key GRANDPARENT =
41- Key .newBuilder ()
42- .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
43- .build ();
43+ Key .newBuilder ()
44+ .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
45+ .build ();
4446 private static final Key CHILD =
45- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Child" ).setId (26L )).build ();
47+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Child" ).setId (26L )).build ();
4648
4749 @ Test
4850 public void testMakeKey_BadTypeForKind () {
@@ -70,92 +72,92 @@ public void testMakeKey_Empty() {
7072 @ Test
7173 public void testMakeKey_Incomplete () {
7274 assertEquals (
73- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" )).build (),
74- makeKey ("Foo" ).build ());
75+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" )).build (),
76+ makeKey ("Foo" ).build ());
7577 }
7678
7779 @ Test
7880 public void testMakeKey_IdInt () {
7981 assertEquals (
80- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
81- makeKey ("Foo" , 1 ).build ());
82+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
83+ makeKey ("Foo" , 1 ).build ());
8284 }
8385
8486 @ Test
8587 public void testMakeKey_IdLong () {
8688 assertEquals (
87- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
88- makeKey ("Foo" , 1L ).build ());
89+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
90+ makeKey ("Foo" , 1L ).build ());
8991 }
9092
9193 @ Test
9294 public void testMakeKey_IdShort () {
9395 assertEquals (
94- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
95- makeKey ("Foo" , (short ) 1 ).build ());
96+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setId (1 )).build (),
97+ makeKey ("Foo" , (short ) 1 ).build ());
9698 }
9799
98100 @ Test
99101 public void testMakeKey_Name () {
100102 assertEquals (
101- Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setName ("hi" )).build (),
102- makeKey ("Foo" , "hi" ).build ());
103+ Key .newBuilder ().addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setName ("hi" )).build (),
104+ makeKey ("Foo" , "hi" ).build ());
103105 }
104106
105107 @ Test
106108 public void testMakeKey_KindNameKind () {
107109 assertEquals (
108- Key .newBuilder ()
109- .addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setName ("hi" ))
110- .addPath (Key .PathElement .newBuilder ().setKind ("Bar" ))
111- .build (),
112- makeKey ("Foo" , "hi" , "Bar" ).build ());
110+ Key .newBuilder ()
111+ .addPath (Key .PathElement .newBuilder ().setKind ("Foo" ).setName ("hi" ))
112+ .addPath (Key .PathElement .newBuilder ().setKind ("Bar" ))
113+ .build (),
114+ makeKey ("Foo" , "hi" , "Bar" ).build ());
113115 }
114116
115117 @ Test
116118 public void testMakeKey_KeyKind () {
117119 // 1 key at the beginning of the series
118120 assertEquals (
119- Key .newBuilder ()
120- .addPath (PARENT .getPath (0 ))
121- .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
122- .build (),
123- makeKey (PARENT , "Child" ).build ());
121+ Key .newBuilder ()
122+ .addPath (PARENT .getPath (0 ))
123+ .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
124+ .build (),
125+ makeKey (PARENT , "Child" ).build ());
124126 }
125127
126128 @ Test
127129 public void testMakeKey_KindIdKeyKind () {
128130 // 1 key in the middle of the series
129131 assertEquals (
130- Key .newBuilder ()
131- .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
132- .addPath (PARENT .getPath (0 ))
133- .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
134- .build (),
135- makeKey ("Grandparent" , 24L , PARENT , "Child" ).build ());
132+ Key .newBuilder ()
133+ .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
134+ .addPath (PARENT .getPath (0 ))
135+ .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
136+ .build (),
137+ makeKey ("Grandparent" , 24L , PARENT , "Child" ).build ());
136138 }
137139
138140 @ Test
139141 public void testMakeKey_KindIdKey () {
140142 // 1 key at the end of the series
141143 assertEquals (
142- Key .newBuilder ()
143- .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
144- .addPath (PARENT .getPath (0 ))
145- .build (),
146- makeKey ("Grandparent" , 24L , PARENT ).build ());
144+ Key .newBuilder ()
145+ .addPath (Key .PathElement .newBuilder ().setKind ("Grandparent" ).setId (24L ))
146+ .addPath (PARENT .getPath (0 ))
147+ .build (),
148+ makeKey ("Grandparent" , 24L , PARENT ).build ());
147149 }
148150
149151 @ Test
150152 public void testMakeKey_KeyKindIdKey () {
151153 // 1 key at the beginning and 1 key at the end of the series
152154 assertEquals (
153- Key .newBuilder ()
154- .addPath (GRANDPARENT .getPath (0 ))
155- .addPath (Key .PathElement .newBuilder ().setKind ("Parent" ).setId (23L ))
156- .addPath (CHILD .getPath (0 ))
157- .build (),
158- makeKey (GRANDPARENT , "Parent" , 23 , CHILD ).build ());
155+ Key .newBuilder ()
156+ .addPath (GRANDPARENT .getPath (0 ))
157+ .addPath (Key .PathElement .newBuilder ().setKind ("Parent" ).setId (23L ))
158+ .addPath (CHILD .getPath (0 ))
159+ .build (),
160+ makeKey (GRANDPARENT , "Parent" , 23 , CHILD ).build ());
159161 }
160162
161163 @ Test
@@ -168,80 +170,80 @@ public void testMakeKey_Key() {
168170 public void testMakeKey_KeyKey () {
169171 // Just 2 keys
170172 assertEquals (
171- Key .newBuilder ().addPath (PARENT .getPath (0 )).addPath (CHILD .getPath (0 )).build (),
172- makeKey (PARENT , CHILD ).build ());
173+ Key .newBuilder ().addPath (PARENT .getPath (0 )).addPath (CHILD .getPath (0 )).build (),
174+ makeKey (PARENT , CHILD ).build ());
173175 }
174176
175177 @ Test
176178 public void testMakeKey_KeyKeyKey () {
177179 // Just 3 keys
178180 assertEquals (
179- Key .newBuilder ()
180- .addPath (GRANDPARENT .getPath (0 ))
181- .addPath (PARENT .getPath (0 ))
182- .addPath (CHILD .getPath (0 ))
183- .build (),
184- makeKey (GRANDPARENT , PARENT , CHILD ).build ());
181+ Key .newBuilder ()
182+ .addPath (GRANDPARENT .getPath (0 ))
183+ .addPath (PARENT .getPath (0 ))
184+ .addPath (CHILD .getPath (0 ))
185+ .build (),
186+ makeKey (GRANDPARENT , PARENT , CHILD ).build ());
185187 }
186188
187189 @ Test
188190 public void testMakeKey_KeyMultiLevelKey () {
189191 // 1 key with 2 elements
190192 assertEquals (
191- Key .newBuilder ()
192- .addPath (GRANDPARENT .getPath (0 ))
193- .addPath (PARENT .getPath (0 ))
194- .addPath (CHILD .getPath (0 ))
195- .build (),
196- makeKey (GRANDPARENT , makeKey (PARENT , CHILD ).build ()).build ());
193+ Key .newBuilder ()
194+ .addPath (GRANDPARENT .getPath (0 ))
195+ .addPath (PARENT .getPath (0 ))
196+ .addPath (CHILD .getPath (0 ))
197+ .build (),
198+ makeKey (GRANDPARENT , makeKey (PARENT , CHILD ).build ()).build ());
197199 }
198200
199201 @ Test
200202 public void testMakeKey_MultiLevelKeyKey () {
201203 // 1 key with 2 elements
202204 assertEquals (
203- Key .newBuilder ()
204- .addPath (GRANDPARENT .getPath (0 ))
205- .addPath (PARENT .getPath (0 ))
206- .addPath (CHILD .getPath (0 ))
207- .build (),
208- makeKey (makeKey (GRANDPARENT , PARENT ).build (), CHILD ).build ());
205+ Key .newBuilder ()
206+ .addPath (GRANDPARENT .getPath (0 ))
207+ .addPath (PARENT .getPath (0 ))
208+ .addPath (CHILD .getPath (0 ))
209+ .build (),
210+ makeKey (makeKey (GRANDPARENT , PARENT ).build (), CHILD ).build ());
209211 }
210212
211213 @ Test
212214 public void testMakeKey_MultiLevelKey () {
213215 // 1 key with 3 elements
214216 assertEquals (
215- Key .newBuilder ()
216- .addPath (GRANDPARENT .getPath (0 ))
217- .addPath (PARENT .getPath (0 ))
218- .addPath (CHILD .getPath (0 ))
219- .build (),
220- makeKey (makeKey (GRANDPARENT , PARENT , CHILD ).build ()).build ());
217+ Key .newBuilder ()
218+ .addPath (GRANDPARENT .getPath (0 ))
219+ .addPath (PARENT .getPath (0 ))
220+ .addPath (CHILD .getPath (0 ))
221+ .build (),
222+ makeKey (makeKey (GRANDPARENT , PARENT , CHILD ).build ()).build ());
221223 }
222224
223225 @ Test
224226 public void testMakeKey_PartitionId () {
225227 PartitionId partitionId = PartitionId .newBuilder ().setNamespaceId ("namespace-id" ).build ();
226228 Key parent = PARENT .toBuilder ().setPartitionId (partitionId ).build ();
227229 assertEquals (
228- Key .newBuilder ()
229- .setPartitionId (partitionId )
230- .addPath (PARENT .getPath (0 ))
231- .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
232- .build (),
233- makeKey (parent , "Child" ).build ());
230+ Key .newBuilder ()
231+ .setPartitionId (partitionId )
232+ .addPath (PARENT .getPath (0 ))
233+ .addPath (Key .PathElement .newBuilder ().setKind ("Child" ))
234+ .build (),
235+ makeKey (parent , "Child" ).build ());
234236 }
235237
236238 @ Test
237239 public void testMakeKey_NonMatchingPartitionId2 () {
238240 PartitionId partitionId1 = PartitionId .newBuilder ().setNamespaceId ("namespace-id" ).build ();
239241 PartitionId partitionId2 =
240- PartitionId .newBuilder ().setNamespaceId ("another-namespace-id" ).build ();
242+ PartitionId .newBuilder ().setNamespaceId ("another-namespace-id" ).build ();
241243 try {
242244 makeKey (
243- PARENT .toBuilder ().setPartitionId (partitionId1 ).build (),
244- CHILD .toBuilder ().setPartitionId (partitionId2 ).build ());
245+ PARENT .toBuilder ().setPartitionId (partitionId1 ).build (),
246+ CHILD .toBuilder ().setPartitionId (partitionId2 ).build ());
245247 fail ("expected IllegalArgumentException" );
246248 } catch (IllegalArgumentException expected ) {
247249 }
@@ -293,15 +295,15 @@ private void assertMillisecondsToTimestamp(long millis, long seconds, long nanos
293295
294296 private void assertTimestampToMilliseconds (long millis , long seconds , int nanos ) {
295297 Value .Builder value =
296- Value .newBuilder ()
297- .setTimestampValue (Timestamp .newBuilder ().setSeconds (seconds ).setNanos (nanos ));
298+ Value .newBuilder ()
299+ .setTimestampValue (Timestamp .newBuilder ().setSeconds (seconds ).setNanos (nanos ));
298300 assertEquals (millis , DatastoreHelper .toDate (value .build ()).getTime ());
299301 }
300302
301303 @ Test
302304 public void testProjectionHandling () {
303305 assertEquals (
304- ByteString .copyFromUtf8 ("hi" ), getByteString (makeValue ("hi" ).setMeaning (18 ).build ()));
306+ ByteString .copyFromUtf8 ("hi" ), getByteString (makeValue ("hi" ).setMeaning (18 ).build ()));
305307 try {
306308 getByteString (makeValue ("hi" ).build ());
307309 fail ("Expected IllegalArgumentException" );
0 commit comments