Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect.testing;
 
 
 
 import java.util.List;
Generates a test suite covering the java.util.List implementations in the java.util package. Can be subclassed to specify tests that should be suppressed.

Author(s):
Kevin Bourrillion
 
 public class TestsForListsInJavaUtil {
   public static Test suite() {
     return new TestsForListsInJavaUtil().allTests();
   }
 
   public Test allTests() {
     TestSuite suite = new TestSuite("java.util Lists");
     suite.addTest(testsForEmptyList());
     suite.addTest(testsForSingletonList());
     suite.addTest(testsForArraysAsList());
     suite.addTest(testsForArrayList());
     suite.addTest(testsForLinkedList());
     suite.addTest(testsForCheckedList());
     suite.addTest(testsForAbstractList());
     return suite;
   }
 
   protected Collection<MethodsuppressForEmptyList() {
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
   protected Collection<MethodsuppressForArrayList() {
     return Collections.emptySet();
   }
   protected Collection<MethodsuppressForLinkedList() {
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
 
   public Test testsForEmptyList() {
     return ListTestSuiteBuilder
         .using(new TestStringListGenerator() {
             @Override public List<Stringcreate(String[] elements) {
              return Collections.emptyList();
            }
          })
        .named("emptyList")
        .withFeatures(
            .,
            .)
        .createTestSuite();
  }
  public Test testsForSingletonList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              return Collections.singletonList(elements[0]);
            }
          })
        .named("singletonList")
        .withFeatures(
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForArraysAsList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              return Arrays.asList(elements.clone());
            }
          })
        .named("Arrays.asList")
        .withFeatures(
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForArrayList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              return new ArrayList<String>(MinimalCollection.of(elements));
            }
          })
        .named("ArrayList")
        .withFeatures(
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForLinkedList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              return new LinkedList<String>(MinimalCollection.of(elements));
            }
          })
        .named("LinkedList")
        .withFeatures(
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              return new CopyOnWriteArrayList<String>(
                  MinimalCollection.of(elements));
            }
          })
        .named("CopyOnWriteArrayList")
        .withFeatures(
            .,
            .,
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              List<StringinnerList = new ArrayList<String>();
              Collections.addAll(innerListelements);
              return Collections.unmodifiableList(innerList);
            }
          })
        .named("unmodifiableList/ArrayList")
        .withFeatures(
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForCheckedList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator() {
            @Override public List<Stringcreate(String[] elements) {
              List<StringinnerList = new ArrayList<String>();
              Collections.addAll(innerListelements);
              return Collections.checkedList(innerListString.class);
            }
          })
        .named("checkedList/ArrayList")
        .withFeatures(
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForAbstractList() {
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator () {
            @Override protected List<Stringcreate(final String[] elements) {
              return new AbstractList<String>() {
                @Override public int size() {
                  return elements.length;
                }
                @Override public String get(int index) {
                  return elements[index];
                }
              };
            }
          })
        .named("AbstractList")
        .withFeatures(
            .,
            .,
            .)
        .createTestSuite();
  }
    return ListTestSuiteBuilder
        .using(new TestStringListGenerator () {
            @Override protected List<Stringcreate(final String[] elements) {
              // For this test we trust ArrayList works
              final List<Stringlist = new ArrayList<String>();
              Collections.addAll(listelements);
              return new AbstractSequentialList<String>() {
                @Override public int size() {
                  return list.size();
                }
                @Override public ListIterator<StringlistIterator(int index) {
                  return list.listIterator(index);
                }
              };
            }
          })
        .named("AbstractSequentialList")
        .withFeatures(
            .,
            .,
            .)
        .createTestSuite();
  }
New to GrepCode? Check out our FAQ X