Home | History | Annotate | Download | only in collect
      1 /*
      2  * Copyright (C) 2007 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;
     18 
     19 import java.util.ListIterator;
     20 
     21 /**
     22  * Tests for {@code ForwardingListIterator}.
     23  *
     24  * @author Robert Konigsberg
     25  */
     26 public class ForwardingListIteratorTest extends ForwardingTestCase {
     27 
     28   private ForwardingListIterator<String> forward;
     29 
     30   @Override public void setUp() throws Exception {
     31     super.setUp();
     32     /*
     33      * Class parameters must be raw, so we can't create a proxy with generic
     34      * type arguments. The created proxy only records calls and returns null, so
     35      * the type is irrelevant at runtime.
     36      */
     37     @SuppressWarnings("unchecked")
     38     final ListIterator<String> li = createProxyInstance(ListIterator.class);
     39     forward = new ForwardingListIterator<String>() {
     40       @Override protected ListIterator<String> delegate() {
     41         return li;
     42       }
     43     };
     44   }
     45 
     46   public void testAdd_T() {
     47     forward.add("asdf");
     48     assertEquals("[add(Object)]", getCalls());
     49   }
     50 
     51   public void testHasNext() {
     52     forward.hasNext();
     53     assertEquals("[hasNext]", getCalls());
     54   }
     55 
     56   public void testHasPrevious() {
     57     forward.hasPrevious();
     58     assertEquals("[hasPrevious]", getCalls());
     59   }
     60 
     61   public void testNext() {
     62     forward.next();
     63     assertEquals("[next]", getCalls());
     64   }
     65 
     66   public void testNextIndex() {
     67     forward.nextIndex();
     68     assertEquals("[nextIndex]", getCalls());
     69   }
     70 
     71   public void testPrevious() {
     72     forward.previous();
     73     assertEquals("[previous]", getCalls());
     74   }
     75 
     76   public void testPreviousIndex() {
     77     forward.previousIndex();
     78     assertEquals("[previousIndex]", getCalls());
     79   }
     80 
     81   public void testRemove() {
     82     forward.remove();
     83     assertEquals("[remove]", getCalls());
     84   }
     85 
     86   public void testSet_T() {
     87     forward.set("asdf");
     88     assertEquals("[set(Object)]", getCalls());
     89   }
     90 }
     91