• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.primitives;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import com.google.common.annotations.GwtCompatible;
22 import com.google.common.annotations.GwtIncompatible;
23 import com.google.common.annotations.J2ktIncompatible;
24 import com.google.common.collect.testing.Helpers;
25 import com.google.common.testing.NullPointerTester;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.List;
30 import junit.framework.TestCase;
31 import org.checkerframework.checker.nullness.qual.Nullable;
32 
33 /**
34  * Unit test for {@link Bytes}.
35  *
36  * @author Kevin Bourrillion
37  */
38 @ElementTypesAreNonnullByDefault
39 @GwtCompatible(emulated = true)
40 public class BytesTest extends TestCase {
41   private static final byte[] EMPTY = {};
42   private static final byte[] ARRAY1 = {(byte) 1};
43   private static final byte[] ARRAY234 = {(byte) 2, (byte) 3, (byte) 4};
44 
45   private static final byte[] VALUES = {Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE};
46 
testHashCode()47   public void testHashCode() {
48     for (byte value : VALUES) {
49       assertThat(Bytes.hashCode(value)).isEqualTo(((Byte) value).hashCode());
50     }
51   }
52 
testContains()53   public void testContains() {
54     assertThat(Bytes.contains(EMPTY, (byte) 1)).isFalse();
55     assertThat(Bytes.contains(ARRAY1, (byte) 2)).isFalse();
56     assertThat(Bytes.contains(ARRAY234, (byte) 1)).isFalse();
57     assertThat(Bytes.contains(new byte[] {(byte) -1}, (byte) -1)).isTrue();
58     assertThat(Bytes.contains(ARRAY234, (byte) 2)).isTrue();
59     assertThat(Bytes.contains(ARRAY234, (byte) 3)).isTrue();
60     assertThat(Bytes.contains(ARRAY234, (byte) 4)).isTrue();
61   }
62 
testIndexOf()63   public void testIndexOf() {
64     assertThat(Bytes.indexOf(EMPTY, (byte) 1)).isEqualTo(-1);
65     assertThat(Bytes.indexOf(ARRAY1, (byte) 2)).isEqualTo(-1);
66     assertThat(Bytes.indexOf(ARRAY234, (byte) 1)).isEqualTo(-1);
67     assertThat(Bytes.indexOf(new byte[] {(byte) -1}, (byte) -1)).isEqualTo(0);
68     assertThat(Bytes.indexOf(ARRAY234, (byte) 2)).isEqualTo(0);
69     assertThat(Bytes.indexOf(ARRAY234, (byte) 3)).isEqualTo(1);
70     assertThat(Bytes.indexOf(ARRAY234, (byte) 4)).isEqualTo(2);
71     assertThat(Bytes.indexOf(new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3}, (byte) 3))
72         .isEqualTo(1);
73   }
74 
testIndexOf_arrayTarget()75   public void testIndexOf_arrayTarget() {
76     assertThat(Bytes.indexOf(EMPTY, EMPTY)).isEqualTo(0);
77     assertThat(Bytes.indexOf(ARRAY234, EMPTY)).isEqualTo(0);
78     assertThat(Bytes.indexOf(EMPTY, ARRAY234)).isEqualTo(-1);
79     assertThat(Bytes.indexOf(ARRAY234, ARRAY1)).isEqualTo(-1);
80     assertThat(Bytes.indexOf(ARRAY1, ARRAY234)).isEqualTo(-1);
81     assertThat(Bytes.indexOf(ARRAY1, ARRAY1)).isEqualTo(0);
82     assertThat(Bytes.indexOf(ARRAY234, ARRAY234)).isEqualTo(0);
83     assertThat(Bytes.indexOf(ARRAY234, new byte[] {(byte) 2, (byte) 3})).isEqualTo(0);
84     assertThat(Bytes.indexOf(ARRAY234, new byte[] {(byte) 3, (byte) 4})).isEqualTo(1);
85     assertThat(Bytes.indexOf(ARRAY234, new byte[] {(byte) 3})).isEqualTo(1);
86     assertThat(Bytes.indexOf(ARRAY234, new byte[] {(byte) 4})).isEqualTo(2);
87     assertThat(
88             Bytes.indexOf(
89                 new byte[] {(byte) 2, (byte) 3, (byte) 3, (byte) 3, (byte) 3},
90                 new byte[] {(byte) 3}))
91         .isEqualTo(1);
92     assertThat(
93             Bytes.indexOf(
94                 new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3, (byte) 4, (byte) 2, (byte) 3},
95                 new byte[] {(byte) 2, (byte) 3, (byte) 4}))
96         .isEqualTo(2);
97     assertThat(
98             Bytes.indexOf(
99                 new byte[] {(byte) 2, (byte) 2, (byte) 3, (byte) 4, (byte) 2, (byte) 3, (byte) 4},
100                 new byte[] {(byte) 2, (byte) 3, (byte) 4}))
101         .isEqualTo(1);
102     assertThat(
103             Bytes.indexOf(
104                 new byte[] {(byte) 4, (byte) 3, (byte) 2},
105                 new byte[] {(byte) 2, (byte) 3, (byte) 4}))
106         .isEqualTo(-1);
107   }
108 
testLastIndexOf()109   public void testLastIndexOf() {
110     assertThat(Bytes.lastIndexOf(EMPTY, (byte) 1)).isEqualTo(-1);
111     assertThat(Bytes.lastIndexOf(ARRAY1, (byte) 2)).isEqualTo(-1);
112     assertThat(Bytes.lastIndexOf(ARRAY234, (byte) 1)).isEqualTo(-1);
113     assertThat(Bytes.lastIndexOf(new byte[] {(byte) -1}, (byte) -1)).isEqualTo(0);
114     assertThat(Bytes.lastIndexOf(ARRAY234, (byte) 2)).isEqualTo(0);
115     assertThat(Bytes.lastIndexOf(ARRAY234, (byte) 3)).isEqualTo(1);
116     assertThat(Bytes.lastIndexOf(ARRAY234, (byte) 4)).isEqualTo(2);
117     assertThat(Bytes.lastIndexOf(new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3}, (byte) 3))
118         .isEqualTo(3);
119   }
120 
testConcat()121   public void testConcat() {
122     assertThat(Bytes.concat()).isEqualTo(EMPTY);
123     assertThat(Bytes.concat(EMPTY)).isEqualTo(EMPTY);
124     assertThat(Bytes.concat(EMPTY, EMPTY, EMPTY)).isEqualTo(EMPTY);
125     assertThat(Bytes.concat(ARRAY1)).isEqualTo(ARRAY1);
126     assertThat(Bytes.concat(ARRAY1)).isNotSameInstanceAs(ARRAY1);
127     assertThat(Bytes.concat(EMPTY, ARRAY1, EMPTY)).isEqualTo(ARRAY1);
128     assertThat(Bytes.concat(ARRAY1, ARRAY1, ARRAY1))
129         .isEqualTo(new byte[] {(byte) 1, (byte) 1, (byte) 1});
130     assertThat(Bytes.concat(ARRAY1, ARRAY234))
131         .isEqualTo(new byte[] {(byte) 1, (byte) 2, (byte) 3, (byte) 4});
132   }
133 
134   @GwtIncompatible // different overflow behavior; could probably be made to work by using ~~
testConcat_overflow_negative()135   public void testConcat_overflow_negative() {
136     int dim1 = 1 << 16;
137     int dim2 = 1 << 15;
138     assertThat(dim1 * dim2).isLessThan(0);
139     testConcatOverflow(dim1, dim2);
140   }
141 
142   @GwtIncompatible // different overflow behavior; could probably be made to work by using ~~
testConcat_overflow_nonNegative()143   public void testConcat_overflow_nonNegative() {
144     int dim1 = 1 << 16;
145     int dim2 = 1 << 16;
146     assertThat(dim1 * dim2).isAtLeast(0);
147     testConcatOverflow(dim1, dim2);
148   }
149 
testConcatOverflow(int arraysDim1, int arraysDim2)150   private static void testConcatOverflow(int arraysDim1, int arraysDim2) {
151     assertThat((long) arraysDim1 * arraysDim2).isNotEqualTo((long) (arraysDim1 * arraysDim2));
152 
153     byte[][] arrays = new byte[arraysDim1][];
154     // it's shared to avoid using too much memory in tests
155     byte[] sharedArray = new byte[arraysDim2];
156     Arrays.fill(arrays, sharedArray);
157 
158     try {
159       Bytes.concat(arrays);
160       fail();
161     } catch (IllegalArgumentException expected) {
162     }
163   }
164 
testEnsureCapacity()165   public void testEnsureCapacity() {
166     assertThat(Bytes.ensureCapacity(EMPTY, 0, 1)).isSameInstanceAs(EMPTY);
167     assertThat(Bytes.ensureCapacity(ARRAY1, 0, 1)).isSameInstanceAs(ARRAY1);
168     assertThat(Bytes.ensureCapacity(ARRAY1, 1, 1)).isSameInstanceAs(ARRAY1);
169     assertThat(Bytes.ensureCapacity(ARRAY1, 2, 1))
170         .isEqualTo(new byte[] {(byte) 1, (byte) 0, (byte) 0});
171   }
172 
testEnsureCapacity_fail()173   public void testEnsureCapacity_fail() {
174     try {
175       Bytes.ensureCapacity(ARRAY1, -1, 1);
176       fail();
177     } catch (IllegalArgumentException expected) {
178     }
179     try {
180       // notice that this should even fail when no growth was needed
181       Bytes.ensureCapacity(ARRAY1, 1, -1);
182       fail();
183     } catch (IllegalArgumentException expected) {
184     }
185   }
186 
testToArray()187   public void testToArray() {
188     // need explicit type parameter to avoid javac warning!?
189     List<Byte> none = Arrays.<Byte>asList();
190     assertThat(Bytes.toArray(none)).isEqualTo(EMPTY);
191 
192     List<Byte> one = Arrays.asList((byte) 1);
193     assertThat(Bytes.toArray(one)).isEqualTo(ARRAY1);
194 
195     byte[] array = {(byte) 0, (byte) 1, (byte) 0x55};
196 
197     List<Byte> three = Arrays.asList((byte) 0, (byte) 1, (byte) 0x55);
198     assertThat(Bytes.toArray(three)).isEqualTo(array);
199 
200     assertThat(Bytes.toArray(Bytes.asList(array))).isEqualTo(array);
201   }
202 
testToArray_threadSafe()203   public void testToArray_threadSafe() {
204     for (int delta : new int[] {+1, 0, -1}) {
205       for (int i = 0; i < VALUES.length; i++) {
206         List<Byte> list = Bytes.asList(VALUES).subList(0, i);
207         Collection<Byte> misleadingSize = Helpers.misleadingSizeCollection(delta);
208         misleadingSize.addAll(list);
209         byte[] arr = Bytes.toArray(misleadingSize);
210         assertThat(arr).hasLength(i);
211         for (int j = 0; j < i; j++) {
212           assertThat(arr[j]).isEqualTo(VALUES[j]);
213         }
214       }
215     }
216   }
217 
testToArray_withNull()218   public void testToArray_withNull() {
219     List<@Nullable Byte> list = Arrays.asList((byte) 0, (byte) 1, null);
220     try {
221       Bytes.toArray(list);
222       fail();
223     } catch (NullPointerException expected) {
224     }
225   }
226 
testToArray_withConversion()227   public void testToArray_withConversion() {
228     byte[] array = {(byte) 0, (byte) 1, (byte) 2};
229 
230     List<Byte> bytes = Arrays.asList((byte) 0, (byte) 1, (byte) 2);
231     List<Short> shorts = Arrays.asList((short) 0, (short) 1, (short) 2);
232     List<Integer> ints = Arrays.asList(0, 1, 2);
233     List<Float> floats = Arrays.asList((float) 0, (float) 1, (float) 2);
234     List<Long> longs = Arrays.asList((long) 0, (long) 1, (long) 2);
235     List<Double> doubles = Arrays.asList((double) 0, (double) 1, (double) 2);
236 
237     assertThat(Bytes.toArray(bytes)).isEqualTo(array);
238     assertThat(Bytes.toArray(shorts)).isEqualTo(array);
239     assertThat(Bytes.toArray(ints)).isEqualTo(array);
240     assertThat(Bytes.toArray(floats)).isEqualTo(array);
241     assertThat(Bytes.toArray(longs)).isEqualTo(array);
242     assertThat(Bytes.toArray(doubles)).isEqualTo(array);
243   }
244 
245   @J2ktIncompatible // b/239034072: Kotlin varargs copy parameter arrays.
testAsList_isAView()246   public void testAsList_isAView() {
247     byte[] array = {(byte) 0, (byte) 1};
248     List<Byte> list = Bytes.asList(array);
249     list.set(0, (byte) 2);
250     assertThat(array).isEqualTo(new byte[] {(byte) 2, (byte) 1});
251     array[1] = (byte) 3;
252     assertThat(list).containsExactly((byte) 2, (byte) 3).inOrder();
253   }
254 
testAsList_toArray_roundTrip()255   public void testAsList_toArray_roundTrip() {
256     byte[] array = {(byte) 0, (byte) 1, (byte) 2};
257     List<Byte> list = Bytes.asList(array);
258     byte[] newArray = Bytes.toArray(list);
259 
260     // Make sure it returned a copy
261     list.set(0, (byte) 4);
262     assertThat(newArray).isEqualTo(new byte[] {(byte) 0, (byte) 1, (byte) 2});
263     newArray[1] = (byte) 5;
264     assertThat((byte) list.get(1)).isEqualTo((byte) 1);
265   }
266 
267   // This test stems from a real bug found by andrewk
testAsList_subList_toArray_roundTrip()268   public void testAsList_subList_toArray_roundTrip() {
269     byte[] array = {(byte) 0, (byte) 1, (byte) 2, (byte) 3};
270     List<Byte> list = Bytes.asList(array);
271     assertThat(Bytes.toArray(list.subList(1, 3))).isEqualTo(new byte[] {(byte) 1, (byte) 2});
272     assertThat(Bytes.toArray(list.subList(2, 2))).isEqualTo(new byte[] {});
273   }
274 
testAsListEmpty()275   public void testAsListEmpty() {
276     assertThat(Bytes.asList(EMPTY)).isSameInstanceAs(Collections.emptyList());
277   }
278 
testReverse()279   public void testReverse() {
280     testReverse(new byte[] {}, new byte[] {});
281     testReverse(new byte[] {1}, new byte[] {1});
282     testReverse(new byte[] {1, 2}, new byte[] {2, 1});
283     testReverse(new byte[] {3, 1, 1}, new byte[] {1, 1, 3});
284     testReverse(new byte[] {-1, 1, -2, 2}, new byte[] {2, -2, 1, -1});
285   }
286 
testReverse(byte[] input, byte[] expectedOutput)287   private static void testReverse(byte[] input, byte[] expectedOutput) {
288     input = Arrays.copyOf(input, input.length);
289     Bytes.reverse(input);
290     assertThat(input).isEqualTo(expectedOutput);
291   }
292 
testReverse(byte[] input, int fromIndex, int toIndex, byte[] expectedOutput)293   private static void testReverse(byte[] input, int fromIndex, int toIndex, byte[] expectedOutput) {
294     input = Arrays.copyOf(input, input.length);
295     Bytes.reverse(input, fromIndex, toIndex);
296     assertThat(input).isEqualTo(expectedOutput);
297   }
298 
testReverseIndexed()299   public void testReverseIndexed() {
300     testReverse(new byte[] {}, 0, 0, new byte[] {});
301     testReverse(new byte[] {1}, 0, 1, new byte[] {1});
302     testReverse(new byte[] {1, 2}, 0, 2, new byte[] {2, 1});
303     testReverse(new byte[] {3, 1, 1}, 0, 2, new byte[] {1, 3, 1});
304     testReverse(new byte[] {3, 1, 1}, 0, 1, new byte[] {3, 1, 1});
305     testReverse(new byte[] {-1, 1, -2, 2}, 1, 3, new byte[] {-1, -2, 1, 2});
306   }
307 
testRotate(byte[] input, int distance, byte[] expectedOutput)308   private static void testRotate(byte[] input, int distance, byte[] expectedOutput) {
309     input = Arrays.copyOf(input, input.length);
310     Bytes.rotate(input, distance);
311     assertThat(input).isEqualTo(expectedOutput);
312   }
313 
testRotate( byte[] input, int distance, int fromIndex, int toIndex, byte[] expectedOutput)314   private static void testRotate(
315       byte[] input, int distance, int fromIndex, int toIndex, byte[] expectedOutput) {
316     input = Arrays.copyOf(input, input.length);
317     Bytes.rotate(input, distance, fromIndex, toIndex);
318     assertThat(input).isEqualTo(expectedOutput);
319   }
320 
testRotate()321   public void testRotate() {
322     testRotate(new byte[] {}, -1, new byte[] {});
323     testRotate(new byte[] {}, 0, new byte[] {});
324     testRotate(new byte[] {}, 1, new byte[] {});
325 
326     testRotate(new byte[] {1}, -2, new byte[] {1});
327     testRotate(new byte[] {1}, -1, new byte[] {1});
328     testRotate(new byte[] {1}, 0, new byte[] {1});
329     testRotate(new byte[] {1}, 1, new byte[] {1});
330     testRotate(new byte[] {1}, 2, new byte[] {1});
331 
332     testRotate(new byte[] {1, 2}, -3, new byte[] {2, 1});
333     testRotate(new byte[] {1, 2}, -1, new byte[] {2, 1});
334     testRotate(new byte[] {1, 2}, -2, new byte[] {1, 2});
335     testRotate(new byte[] {1, 2}, 0, new byte[] {1, 2});
336     testRotate(new byte[] {1, 2}, 1, new byte[] {2, 1});
337     testRotate(new byte[] {1, 2}, 2, new byte[] {1, 2});
338     testRotate(new byte[] {1, 2}, 3, new byte[] {2, 1});
339 
340     testRotate(new byte[] {1, 2, 3}, -5, new byte[] {3, 1, 2});
341     testRotate(new byte[] {1, 2, 3}, -4, new byte[] {2, 3, 1});
342     testRotate(new byte[] {1, 2, 3}, -3, new byte[] {1, 2, 3});
343     testRotate(new byte[] {1, 2, 3}, -2, new byte[] {3, 1, 2});
344     testRotate(new byte[] {1, 2, 3}, -1, new byte[] {2, 3, 1});
345     testRotate(new byte[] {1, 2, 3}, 0, new byte[] {1, 2, 3});
346     testRotate(new byte[] {1, 2, 3}, 1, new byte[] {3, 1, 2});
347     testRotate(new byte[] {1, 2, 3}, 2, new byte[] {2, 3, 1});
348     testRotate(new byte[] {1, 2, 3}, 3, new byte[] {1, 2, 3});
349     testRotate(new byte[] {1, 2, 3}, 4, new byte[] {3, 1, 2});
350     testRotate(new byte[] {1, 2, 3}, 5, new byte[] {2, 3, 1});
351 
352     testRotate(new byte[] {1, 2, 3, 4}, -9, new byte[] {2, 3, 4, 1});
353     testRotate(new byte[] {1, 2, 3, 4}, -5, new byte[] {2, 3, 4, 1});
354     testRotate(new byte[] {1, 2, 3, 4}, -1, new byte[] {2, 3, 4, 1});
355     testRotate(new byte[] {1, 2, 3, 4}, 0, new byte[] {1, 2, 3, 4});
356     testRotate(new byte[] {1, 2, 3, 4}, 1, new byte[] {4, 1, 2, 3});
357     testRotate(new byte[] {1, 2, 3, 4}, 5, new byte[] {4, 1, 2, 3});
358     testRotate(new byte[] {1, 2, 3, 4}, 9, new byte[] {4, 1, 2, 3});
359 
360     testRotate(new byte[] {1, 2, 3, 4, 5}, -6, new byte[] {2, 3, 4, 5, 1});
361     testRotate(new byte[] {1, 2, 3, 4, 5}, -4, new byte[] {5, 1, 2, 3, 4});
362     testRotate(new byte[] {1, 2, 3, 4, 5}, -3, new byte[] {4, 5, 1, 2, 3});
363     testRotate(new byte[] {1, 2, 3, 4, 5}, -1, new byte[] {2, 3, 4, 5, 1});
364     testRotate(new byte[] {1, 2, 3, 4, 5}, 0, new byte[] {1, 2, 3, 4, 5});
365     testRotate(new byte[] {1, 2, 3, 4, 5}, 1, new byte[] {5, 1, 2, 3, 4});
366     testRotate(new byte[] {1, 2, 3, 4, 5}, 3, new byte[] {3, 4, 5, 1, 2});
367     testRotate(new byte[] {1, 2, 3, 4, 5}, 4, new byte[] {2, 3, 4, 5, 1});
368     testRotate(new byte[] {1, 2, 3, 4, 5}, 6, new byte[] {5, 1, 2, 3, 4});
369   }
370 
testRotateIndexed()371   public void testRotateIndexed() {
372     testRotate(new byte[] {}, 0, 0, 0, new byte[] {});
373 
374     testRotate(new byte[] {1}, 0, 0, 1, new byte[] {1});
375     testRotate(new byte[] {1}, 1, 0, 1, new byte[] {1});
376     testRotate(new byte[] {1}, 1, 1, 1, new byte[] {1});
377 
378     // Rotate the central 5 elements, leaving the ends as-is
379     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -6, 1, 6, new byte[] {0, 2, 3, 4, 5, 1, 6});
380     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -1, 1, 6, new byte[] {0, 2, 3, 4, 5, 1, 6});
381     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 1, 6, new byte[] {0, 1, 2, 3, 4, 5, 6});
382     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 5, 1, 6, new byte[] {0, 1, 2, 3, 4, 5, 6});
383     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 14, 1, 6, new byte[] {0, 2, 3, 4, 5, 1, 6});
384 
385     // Rotate the first three elements
386     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -2, 0, 3, new byte[] {2, 0, 1, 3, 4, 5, 6});
387     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -1, 0, 3, new byte[] {1, 2, 0, 3, 4, 5, 6});
388     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 0, 3, new byte[] {0, 1, 2, 3, 4, 5, 6});
389     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 1, 0, 3, new byte[] {2, 0, 1, 3, 4, 5, 6});
390     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 2, 0, 3, new byte[] {1, 2, 0, 3, 4, 5, 6});
391 
392     // Rotate the last four elements
393     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -6, 3, 7, new byte[] {0, 1, 2, 5, 6, 3, 4});
394     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -5, 3, 7, new byte[] {0, 1, 2, 4, 5, 6, 3});
395     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -4, 3, 7, new byte[] {0, 1, 2, 3, 4, 5, 6});
396     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -3, 3, 7, new byte[] {0, 1, 2, 6, 3, 4, 5});
397     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -2, 3, 7, new byte[] {0, 1, 2, 5, 6, 3, 4});
398     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, -1, 3, 7, new byte[] {0, 1, 2, 4, 5, 6, 3});
399     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 3, 7, new byte[] {0, 1, 2, 3, 4, 5, 6});
400     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 1, 3, 7, new byte[] {0, 1, 2, 6, 3, 4, 5});
401     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 2, 3, 7, new byte[] {0, 1, 2, 5, 6, 3, 4});
402     testRotate(new byte[] {0, 1, 2, 3, 4, 5, 6}, 3, 3, 7, new byte[] {0, 1, 2, 4, 5, 6, 3});
403   }
404 
405   @J2ktIncompatible
406   @GwtIncompatible // NullPointerTester
testNulls()407   public void testNulls() {
408     new NullPointerTester().testAllPublicStaticMethods(Bytes.class);
409   }
410 }
411