RandomElements { public List<T> shuffled() { List<T> result = new ArrayList<T>(this.elements); Collections.shuffle(result); return result; } private  RandomElements(T[] elements); private  RandomElements(Collection<T> elements); @SafeVarargs static RandomElements<T> from(Collection<T> elements, T... others); @SafeVarargs static RandomElements<T> from(T... elements); T sample(); List<T> sample(int nToReturn); List<T> sampleWithReplacement(int nToReturn); List<T> shuffled();  }
@Test void shuffledCollectionHasElementsInDifferentOrder_fromOriginalCollection() { List<String> original = length(10).alphanumerics(200); List<String> shuffled = shuffled(original); assertNotEquals(original, shuffled); assertTrue(original.containsAll(shuffled)); assertTrue(shuffled.containsAll(original)); }
@Test void shuffledCollectionHasElementsInDifferentOrder_fromOriginalArray() { List<String> original = length(10).alphanumerics(200); String[] originalArray = original.toArray(new String[]{}); List<String> shuffled = shuffled(originalArray); assertNotEquals(original, shuffled); assertTrue(original.containsAll(shuffled)); assertTrue(shuffled.containsAll(original)); }