1 package org.mockitousage.junitrule; 2 3 import org.junit.Rule; 4 import org.junit.Test; 5 import org.mockito.Mock; 6 import org.mockito.quality.Strictness; 7 import org.mockito.internal.junit.JUnitRule; 8 import org.mockito.internal.util.MockitoLogger; 9 import org.mockito.junit.MockitoRule; 10 import org.mockitousage.IMethods; 11 12 import static org.mockito.Mockito.when; 13 14 public class LenientJUnitRuleTest { 15 16 private MockitoLogger explosiveLogger = new MockitoLogger() { 17 public void log(Object what) { 18 throw new RuntimeException("Silent rule should not write anything to the logger"); 19 } 20 }; 21 @Mock private IMethods mock; 22 23 @Rule public MockitoRule mockitoRule = new JUnitRule(explosiveLogger, Strictness.LENIENT); 24 no_warning_for_unused_stubbing()25 @Test public void no_warning_for_unused_stubbing() throws Exception { 26 when(mock.simpleMethod(1)).thenReturn("1"); 27 } 28 no_warning_for_stubbing_arg_mismatch()29 @Test public void no_warning_for_stubbing_arg_mismatch() throws Exception { 30 when(mock.simpleMethod(1)).thenReturn("1"); 31 mock.simpleMethod(2); 32 } 33 no_warning_for_stubbing_arg_mismatch_on_failure()34 @Test(expected = IllegalStateException.class) public void no_warning_for_stubbing_arg_mismatch_on_failure() throws Exception { 35 when(mock.simpleMethod(1)).thenReturn("1"); 36 mock.simpleMethod(2); 37 throw new IllegalStateException("hey!"); 38 } 39 } 40