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.Before; 9 import org.junit.Test; 10 import org.junit.runner.RunWith; 11 import org.mockito.Mock; 12 import org.mockito.exceptions.verification.NeverWantedButInvoked; 13 import org.mockito.junit.MockitoJUnitRunner; 14 import org.mockitousage.IMethods; 15 import org.mockitoutil.TestBase; 16 17 import static org.junit.Assert.fail; 18 import static org.assertj.core.api.Assertions.assertThat; 19 import static org.mockito.Mockito.times; 20 import static org.mockito.Mockito.verify; 21 22 //This is required to make sure stack trace is well filtered when runner is ON 23 @RunWith(MockitoJUnitRunner.class) 24 public class PointingStackTraceToActualInvocationTest extends TestBase { 25 26 @Mock private IMethods mock; 27 @Mock private IMethods mockTwo; 28 29 @Before setup()30 public void setup() { 31 first(); 32 second(); 33 third(); 34 fourth(); 35 } 36 first()37 private void first() { 38 mock.simpleMethod(1); 39 } second()40 private void second() { 41 mockTwo.simpleMethod(2); 42 } third()43 private void third() { 44 mock.simpleMethod(3); 45 } fourth()46 private void fourth() { 47 mockTwo.simpleMethod(4); 48 } 49 50 @Test shouldPointToTooManyInvocationsChunkOnError()51 public void shouldPointToTooManyInvocationsChunkOnError() { 52 try { 53 verify(mock, times(0)).simpleMethod(1); 54 fail(); 55 } catch (NeverWantedButInvoked e) { 56 assertThat(e).hasMessageContaining("first("); 57 } 58 } 59 60 @Test shouldNotPointStackTracesToRunnersCode()61 public void shouldNotPointStackTracesToRunnersCode() { 62 try { 63 verify(mock, times(0)).simpleMethod(1); 64 fail(); 65 } catch (NeverWantedButInvoked e) { 66 assertThat(e.getMessage()).doesNotContain(".runners."); 67 } 68 } 69 } 70