@Test
 public void sortingWitoutAccessToInternalArray() {
   ThisIsNotAnArrayList<Integer> arrayListThatIsnt =
       new ThisIsNotAnArrayList<Integer>(FastList.newListWith(5, 3, 4, 1, 2));
   Verify.assertStartsWith(
       ArrayListIterate.sortThis(arrayListThatIsnt, Comparators.naturalOrder()), 1, 2, 3, 4, 5);
 }
 @Test
 public void valuesCollection_toArray_withLargeTarget() {
   MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two");
   String[] target = new String[3];
   target[2] = "yow!";
   String[] values = map.values().toArray(target);
   ArrayIterate.sort(
       values, values.length, Comparators.safeNullsHigh(Comparators.<String>naturalOrder()));
   Assert.assertArrayEquals(new String[] {"One", "Two", null}, values);
 }
 @Test
 public void keySet_ToArray_withLargeTarget() {
   MutableMap<Integer, String> map =
       this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
   Integer[] target = new Integer[6]; // deliberately large to force the extra to be set to null
   target[4] = 42;
   target[5] = 42;
   Integer[] result = map.keySet().toArray(target);
   ArrayIterate.sort(
       result, result.length, Comparators.safeNullsHigh(Comparators.<Integer>naturalOrder()));
   Assert.assertArrayEquals(new Integer[] {1, 2, 3, 4, 42, null}, result);
 }
  @Test
  public void keySet_copyKeys() {
    // a map with a null key
    MutableMap<Integer, Integer> map1 = this.newMapWithKeyValue(null, 0);
    Assert.assertArrayEquals(new Object[] {null}, map1.keySet().toArray());

    // a map with a chain containing empty slots
    MutableMap<Integer, Integer> map2 = this.mapWithCollisionsOfSize(5);
    Assert.assertArrayEquals(new Object[] {0, 17, 34, 51, 68}, map2.keySet().toArray());

    // a map with a chain containing empty slots and null key
    MutableMap<Integer, Integer> map3 = this.mapWithCollisionsOfSize(5);
    map3.put(null, 42);
    Integer[] array = map3.keySet().toArray(new Integer[map3.size()]);
    ArrayIterate.sort(
        array, array.length, Comparators.safeNullsHigh(Comparators.<Integer>naturalOrder()));
    Assert.assertArrayEquals(new Object[] {0, 17, 34, 51, 68, null}, array);
  }
 public MutableList<T> toSortedList() {
   return this.toSortedList(Comparators.naturalOrder());
 }
 @Test
 public void max() {
   Assert.assertEquals(
       Integer.valueOf(1),
       this.classUnderTest().max(Comparators.reverse(Comparators.naturalOrder())));
 }
 @Test(expected = NullPointerException.class)
 public void max_null_throws() {
   this.classUnderTestWithNull().max(Comparators.naturalOrder());
 }
 @Test
 public void max() {
   Assert.assertEquals(Integer.valueOf(3), this.newWith(1, 3, 2).max(Comparators.naturalOrder()));
 }
 @Test(expected = NullPointerException.class)
 public void max_null_throws() {
   this.newWith(1, null, 2).max(Comparators.naturalOrder());
 }
 @Test(expected = NoSuchElementException.class)
 public void max_empty_throws() {
   this.newWith().max(Comparators.naturalOrder());
 }