-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1523 from mockito/next-ann
Added 'lenient' annotation toggle
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/mockitousage/strictness/LenientMockAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2007 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
|
||
package org.mockitousage.strictness; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.assertj.core.api.ThrowableAssert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.exceptions.misusing.PotentialStubbingProblem; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
import org.mockito.quality.Strictness; | ||
import org.mockitousage.IMethods; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
public class LenientMockAnnotationTest { | ||
|
||
public @Rule MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); | ||
@Mock(lenient = true) IMethods lenientMock; | ||
@Mock IMethods regularMock; | ||
|
||
@Test | ||
public void mock_is_lenient() { | ||
when(lenientMock.simpleMethod("1")).thenReturn("1"); | ||
when(regularMock.simpleMethod("2")).thenReturn("2"); | ||
|
||
//then lenient mock does not throw: | ||
lenientMock.simpleMethod("3"); | ||
|
||
//but regular mock throws: | ||
Assertions.assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { | ||
public void call() { | ||
regularMock.simpleMethod("4"); | ||
} | ||
}).isInstanceOf(PotentialStubbingProblem.class); | ||
} | ||
} |