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