Home | History | Annotate | Download | only in stacktrace
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockitousage.stacktrace;
      7 
      8 import org.junit.After;
      9 import org.junit.Test;
     10 import org.mockito.Mock;
     11 import org.mockito.exceptions.misusing.InvalidUseOfMatchersException;
     12 import org.mockito.exceptions.misusing.UnfinishedStubbingException;
     13 import org.mockito.exceptions.misusing.UnfinishedVerificationException;
     14 import org.mockitousage.IMethods;
     15 import org.mockitoutil.TestBase;
     16 
     17 import static junit.framework.TestCase.fail;
     18 import static org.assertj.core.api.Assertions.assertThat;
     19 import static org.mockito.Mockito.*;
     20 
     21 public class ClickableStackTracesWhenFrameworkMisusedTest extends TestBase {
     22 
     23     @Mock private IMethods mock;
     24 
     25     @After
     26     public void resetState() {
     27         super.resetState();
     28     }
     29 
     30     private void misplacedArgumentMatcherHere() {
     31         anyString();
     32     }
     33 
     34     @Test
     35     public void shouldPointOutMisplacedMatcher() {
     36         misplacedArgumentMatcherHere();
     37         try {
     38             verify(mock).simpleMethod();
     39             fail();
     40         } catch (InvalidUseOfMatchersException e) {
     41             assertThat(e)
     42                 .hasMessageContaining("-> at ")
     43                 .hasMessageContaining("misplacedArgumentMatcherHere(");
     44         }
     45     }
     46 
     47     private void unfinishedStubbingHere() {
     48         when(mock.simpleMethod());
     49     }
     50 
     51     @Test
     52     public void shouldPointOutUnfinishedStubbing() {
     53         unfinishedStubbingHere();
     54 
     55         try {
     56             verify(mock).simpleMethod();
     57             fail();
     58         } catch (UnfinishedStubbingException e) {
     59             assertThat(e)
     60                 .hasMessageContaining("-> at ")
     61                 .hasMessageContaining("unfinishedStubbingHere(");
     62         }
     63     }
     64 
     65     @Test
     66     public void shouldShowWhereIsUnfinishedVerification() throws Exception {
     67         unfinishedVerificationHere();
     68         try {
     69             mock(IMethods.class);
     70             fail();
     71         } catch (UnfinishedVerificationException e) {
     72             assertThat(e).hasMessageContaining("unfinishedVerificationHere(");
     73         }
     74     }
     75 
     76     private void unfinishedVerificationHere() {
     77         verify(mock);
     78     }
     79 }
     80