Home | History | Annotate | Download | only in bugs
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 package org.mockitousage.bugs;
      6 
      7 import org.junit.Test;
      8 import org.mockito.exceptions.base.MockitoException;
      9 import org.mockito.stubbing.OngoingStubbing;
     10 
     11 import java.util.Map;
     12 
     13 import static org.assertj.core.api.Assertions.assertThat;
     14 import static org.junit.Assert.fail;
     15 import static org.mockito.Matchers.anyString;
     16 import static org.mockito.Mockito.mock;
     17 import static org.mockito.Mockito.when;
     18 
     19 public class IOOBExceptionShouldNotBeThrownWhenNotCodingFluentlyTest {
     20 
     21     @Test
     22     public void second_stubbing_throws_IndexOutOfBoundsException() throws Exception {
     23 
     24         @SuppressWarnings("unchecked")
     25         Map<String, String> map = mock(Map.class);
     26 
     27         OngoingStubbing<String> mapOngoingStubbing = when(map.get(anyString()));
     28 
     29         mapOngoingStubbing.thenReturn("first stubbing");
     30 
     31         try {
     32             mapOngoingStubbing.thenReturn("second stubbing");
     33             fail();
     34         } catch (MockitoException e) {
     35             assertThat(e.getMessage())
     36                     .contains("Incorrect use of API detected here")
     37                     .contains(this.getClass().getSimpleName());
     38         }
     39     }
     40 }
     41