New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example failing test for issue #2656 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,10 +45,12 @@ public static Object processAnnotationForMock( | |
if (annotation.stubOnly()) { | ||
mockSettings.stubOnly(); | ||
} | ||
mockSettings.strictness(annotation.strictness()); | ||
if (annotation.lenient()) { | ||
mockSettings.lenient(); | ||
} | ||
if (annotation.strictness() != Mock.Strictness.NOT_SET) { | ||
mockSettings.strictness(annotation.strictness().outer()); | ||
} | ||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we can not set strictness on the settings... |
||
|
||
// see @Mock answer default value | ||
mockSettings.defaultAnswer(annotation.answer()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,10 +247,10 @@ public MockSettings lenient() { | |
|
||
@Override | ||
public MockSettings strictness(Strictness strictness) { | ||
this.strictness = strictness; | ||
if (strictness == null) { | ||
throw strictnessDoesNotAcceptNullParameter(); | ||
} | ||
this.strictness = strictness; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved as we shouldn't be mutating state on a bad input... |
||
return this; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ public class CreationSettings<T> implements MockCreationSettings<T>, Serializabl | |
private boolean useConstructor; | ||
private Object outerClassInstance; | ||
private Object[] constructorArgs; | ||
protected Strictness strictness = Strictness.STRICT_STUBS; | ||
protected Strictness strictness = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we change the default to null... |
||
|
||
public CreationSettings() {} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.mockito; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(value = Parameterized.class) | ||
public class MockTest { | ||
|
||
public org.mockito.quality.Strictness strictness; | ||
|
||
public MockTest(org.mockito.quality.Strictness strictness) { | ||
this.strictness = strictness; | ||
} | ||
|
||
@Test | ||
public void shouldHaveMatchingEnumInMockStrictnessEnum() { | ||
final Mock.Strictness mockStrictness = Mock.Strictness.valueOf(this.strictness.name()); | ||
assertThat(mockStrictness.outer()).isEqualTo(strictness); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static org.mockito.quality.Strictness[] data() { | ||
return org.mockito.quality.Strictness.values(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ public class StrictnessMockAnnotationTest { | |
|
||
public @Rule MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); | ||
|
||
@Mock(strictness = Strictness.LENIENT) | ||
@Mock(strictness = Mock.Strictness.LENIENT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example of the breaking change... |
||
IMethods lenientMock; | ||
|
||
@Mock IMethods regularMock; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mockitousage; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class ProductionCode { | ||
|
||
@SuppressWarnings("ReturnValueIgnored") | ||
public static void simpleMethod(Predicate<String> mock, String argument) { | ||
mock.test(argument); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method now returns local
Strictness
enum with aNOT_SET
default.(This is a breaking change for any code written using the
strictness
value of the annotation though)