Home | History | Annotate | Download | only in testers
      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.collect.testing.testers;
     18 
     19 /**
     20  * A generic JUnit test which tests {@code get()} operations on a list. Can't be
     21  * invoked directly; please see
     22  * {@link com.google.common.collect.testing.ListTestSuiteBuilder}.
     23  *
     24  * <p>This class is GWT compatible.
     25  *
     26  * @author Chris Povirk
     27  */
     28 public class ListGetTester<E> extends AbstractListTester<E> {
     29   public void testGet_valid() {
     30     // This calls get() on each index and checks the result:
     31     expectContents(createSamplesArray());
     32   }
     33 
     34   public void testGet_negative() {
     35     try {
     36       getList().get(-1);
     37       fail("get(-1) should throw");
     38     } catch (IndexOutOfBoundsException expected) {
     39     }
     40   }
     41 
     42   public void testGet_tooLarge() {
     43     try {
     44       getList().get(getNumElements());
     45       fail("get(size) should throw");
     46     } catch (IndexOutOfBoundsException expected) {
     47     }
     48   }
     49 }
     50