[Git][java-team/mockito][master] 3 commits: New upstream version 3.3.3
Mechtilde Stehmann (@mechtilde)
gitlab at salsa.debian.org
Thu May 1 18:16:58 BST 2025
Mechtilde Stehmann pushed to branch master at Debian Java Maintainers / mockito
Commits:
fd089f68 by Mechtilde at 2025-05-01T17:50:33+02:00
New upstream version 3.3.3
- - - - -
1652d78c by Mechtilde at 2025-05-01T17:50:43+02:00
Update upstream source from tag 'upstream/3.3.3'
Update to upstream version '3.3.3'
with Debian dir c05c5f09830ee6440c61bdd6eb165827fef140a4
- - - - -
1ecbd0ac by Mechtilde at 2025-05-01T19:10:03+02:00
Prepared for uploading to experimental
- - - - -
13 changed files:
- debian/changelog
- doc/release-notes/official.md
- src/main/java/org/mockito/exceptions/misusing/UnnecessaryStubbingException.java
- src/main/java/org/mockito/internal/exceptions/Reporter.java
- src/main/java/org/mockito/internal/reporting/Pluralizer.java
- src/main/java/org/mockito/internal/stubbing/InvocationContainerImpl.java
- src/main/java/org/mockito/internal/stubbing/StubbedInvocationMatcher.java
- src/main/java/org/mockito/invocation/Invocation.java
- src/test/java/org/mockito/internal/reporting/PluralizerTest.java
- src/test/java/org/mockitousage/junitrule/StrictJUnitRuleTest.java
- src/test/java/org/mockitousage/junitrunner/UnusedStubsExceptionMessageTest.java
- src/test/java/org/mockitousage/stubbing/StrictStubbingTest.java
- version.properties
Changes:
=====================================
debian/changelog
=====================================
@@ -1,3 +1,11 @@
+mockito (3.3.3-1) experimental; urgency=medium
+
+ [ Mechtilde ]
+ * Team upload
+ * [fd089f6] New upstream version 3.3.3
+
+ -- Mechtilde Stehmann <mechtilde at debian.org> Thu, 01 May 2025 19:09:52 +0200
+
mockito (3.3.0-2) unstable; urgency=medium
* Team upload.
=====================================
doc/release-notes/official.md
=====================================
@@ -1,5 +1,17 @@
<sup><sup>*Release notes were automatically generated by [Shipkit](http://shipkit.org/)*</sup></sup>
+#### 3.3.3
+ - 2020-03-13 - [1 commit](https://github.com/mockito/mockito/compare/v3.3.2...v3.3.3) by [Tim van der Lippe](https://github.com/TimvdLippe) - published to [](https://bintray.com/mockito/maven/mockito/3.3.3)
+ - No pull requests referenced in commit messages.
+
+#### 3.3.2
+ - 2020-02-28 - [1 commit](https://github.com/mockito/mockito/compare/v3.3.1...v3.3.2) by [Jean-Michel Leclercq](https://github.com/LeJeanbono) - published to [](https://bintray.com/mockito/maven/mockito-development/3.3.2)
+ - Fix UnnecessaryStubbingException javadoc [(#1881)](https://github.com/mockito/mockito/pull/1881)
+
+#### 3.3.1
+ - 2020-02-26 - [1 commit](https://github.com/mockito/mockito/compare/v3.3.0...v3.3.1) by [Tim van der Lippe](https://github.com/TimvdLippe) - published to [](https://bintray.com/mockito/maven/mockito/3.3.1)
+ - Revert "Fixed undetected unused stubbing when matching previous stubbed call" [(#1878)](https://github.com/mockito/mockito/pull/1878)
+
#### 3.3.0
- 2020-02-21 - [1 commit](https://github.com/mockito/mockito/compare/v3.2.11...v3.3.0) by [Tim van der Lippe](https://github.com/TimvdLippe) - published to [](https://bintray.com/mockito/maven/mockito/3.3.0)
- No pull requests referenced in commit messages.
=====================================
src/main/java/org/mockito/exceptions/misusing/UnnecessaryStubbingException.java
=====================================
@@ -33,10 +33,11 @@ import org.mockito.exceptions.base.MockitoException;
* when(translator.translate("one")).thenReturn("jeden"); // <- stubbing realized during code execution
* when(translator.translate("two")).thenReturn("dwa"); // <- stubbing never realized
* ...
+ * </code>
* </pre>
* Notice that one of the stubbed methods were never realized in the code under test, during test execution.
* The stray stubbing might be an oversight of the developer, the artifact of copy-paste
- * or the effect not understanding the test/code.
+ * or the effect of not understanding the test/code.
* Either way, the developer ends up with unnecessary test code.
* In order to keep the codebase clean & maintainable it is necessary to remove unnecessary code.
* Otherwise tests are harder to read and reason about.
=====================================
src/main/java/org/mockito/internal/exceptions/Reporter.java
=====================================
@@ -5,7 +5,6 @@
package org.mockito.internal.exceptions;
import static org.mockito.internal.reporting.Pluralizer.pluralize;
-import static org.mockito.internal.reporting.Pluralizer.stubbings;
import static org.mockito.internal.reporting.Pluralizer.were_exactly_x_interactions;
import static org.mockito.internal.util.StringUtil.join;
@@ -883,9 +882,9 @@ public class Reporter {
public static UnnecessaryStubbingException formatUnncessaryStubbingException(Class<?> testClass, Collection<Invocation> unnecessaryStubbings) {
StringBuilder stubbings = new StringBuilder();
- int count = 0;
+ int count = 1;
for (Invocation u : unnecessaryStubbings) {
- stubbings.append("\n ").append(++count).append(". ").append(u.getLocation());
+ stubbings.append("\n ").append(count++).append(". ").append(u.getLocation());
}
String heading = (testClass != null)?
"Unnecessary stubbings detected in test class: " + testClass.getSimpleName() :
@@ -894,7 +893,7 @@ public class Reporter {
return new UnnecessaryStubbingException(join(
heading,
"Clean & maintainable test code requires zero unnecessary code.",
- "There are " + count + " unnecessary " + stubbings(count) + " (click to navigate to relevant line of code):" + stubbings,
+ "Following stubbings are unnecessary (click to navigate to relevant line of code):" + stubbings,
"Please remove unnecessary stubbings or use 'lenient' strictness. More info: javadoc for UnnecessaryStubbingException class."
));
}
=====================================
src/main/java/org/mockito/internal/reporting/Pluralizer.java
=====================================
@@ -17,8 +17,4 @@ public class Pluralizer {
return "were exactly " + x + " interactions";
}
}
-
- public static String stubbings(int number) {
- return number == 1 ? "stubbing" : "stubbings";
- }
}
=====================================
src/main/java/org/mockito/internal/stubbing/InvocationContainerImpl.java
=====================================
@@ -52,31 +52,10 @@ public class InvocationContainerImpl implements InvocationContainer, Serializabl
}
public void addAnswer(Answer answer, Strictness stubbingStrictness) {
- unmarkLastUsedStubIfNecessary();
-
registeredInvocations.removeLast();
addAnswer(answer, false, stubbingStrictness);
}
- /**
- * A stubbed call is marked as used when the method call is stubbed again, because the second
- * stub looks like an actual usage of the first stubbed call. When the second stub is set up,
- * the previous one is marked as unused again.
- */
- private void unmarkLastUsedStubIfNecessary() {
- synchronized (stubbed) {
- Invocation invocation = invocationForStubbing.getInvocation();
-
- for (StubbedInvocationMatcher s : stubbed) {
- if (s.matches(invocation)) {
- s.markStubUsed(null);
- invocation.markStubbed(null);
- return;
- }
- }
- }
- }
-
public void addConsecutiveAnswer(Answer answer) {
addAnswer(answer, true, null);
}
=====================================
src/main/java/org/mockito/internal/stubbing/StubbedInvocationMatcher.java
=====================================
@@ -43,10 +43,6 @@ public class StubbedInvocationMatcher extends InvocationMatcher implements Seria
answers.add(answer);
}
- /**
- * Marks the stub as used by the passed invocation. Passing null marks the stub as unused.
- * @param usedAt The invocation which uses this stub
- */
public void markStubUsed(DescribedInvocation usedAt) {
this.usedAt = usedAt;
}
=====================================
src/main/java/org/mockito/invocation/Invocation.java
=====================================
@@ -81,8 +81,7 @@ public interface Invocation extends InvocationOnMock, DescribedInvocation {
StubInfo stubInfo();
/**
- * Marks this invocation as stubbed. Passing null resets the invocation state back to not
- * stubbed.
+ * Marks this invocation as stubbed.
*
* @param stubInfo the information about stubbing.
*/
=====================================
src/test/java/org/mockito/internal/reporting/PluralizerTest.java
=====================================
@@ -25,11 +25,4 @@ public class PluralizerTest extends TestBase {
assertEquals("was exactly 1 interaction", Pluralizer.were_exactly_x_interactions(1));
assertEquals("were exactly 100 interactions", Pluralizer.were_exactly_x_interactions(100));
}
-
- @Test
- public void pluralizes_stubbings() {
- assertEquals("stubbings", Pluralizer.stubbings(0));
- assertEquals("stubbing", Pluralizer.stubbings(1));
- assertEquals("stubbings", Pluralizer.stubbings(100));
- }
}
=====================================
src/test/java/org/mockitousage/junitrule/StrictJUnitRuleTest.java
=====================================
@@ -140,7 +140,7 @@ public class StrictJUnitRuleTest {
assertEquals(filterLineNo("\n" +
"Unnecessary stubbings detected.\n" +
"Clean & maintainable test code requires zero unnecessary code.\n" +
- "There are 2 unnecessary stubbings (click to navigate to relevant line of code):\n" +
+ "Following stubbings are unnecessary (click to navigate to relevant line of code):\n" +
" 1. -> at org.mockitousage.junitrule.StrictJUnitRuleTest.unused_stubs_with_multiple_mocks(StrictJUnitRuleTest.java:0)\n" +
" 2. -> at org.mockitousage.junitrule.StrictJUnitRuleTest.unused_stubs_with_multiple_mocks(StrictJUnitRuleTest.java:0)\n" +
"Please remove unnecessary stubbings or use 'lenient' strictness. More info: javadoc for UnnecessaryStubbingException class."), filterLineNo(t.getMessage()));
=====================================
src/test/java/org/mockitousage/junitrunner/UnusedStubsExceptionMessageTest.java
=====================================
@@ -50,7 +50,7 @@ public class UnusedStubsExceptionMessageTest extends TestBase {
assertEquals("\n" +
"Unnecessary stubbings detected in test class: HasUnnecessaryStubs\n" +
"Clean & maintainable test code requires zero unnecessary code.\n" +
- "There are 2 unnecessary stubbings (click to navigate to relevant line of code):\n" +
+ "Following stubbings are unnecessary (click to navigate to relevant line of code):\n" +
" 1. -> at org.mockitousage.junitrunner.UnusedStubsExceptionMessageTest$HasUnnecessaryStubs.<init>(UnusedStubsExceptionMessageTest.java:0)\n" +
" 2. -> at org.mockitousage.junitrunner.UnusedStubsExceptionMessageTest$HasUnnecessaryStubs.<init>(UnusedStubsExceptionMessageTest.java:0)\n" +
"Please remove unnecessary stubbings or use 'lenient' strictness. More info: javadoc for UnnecessaryStubbingException class.",
=====================================
src/test/java/org/mockitousage/stubbing/StrictStubbingTest.java
=====================================
@@ -4,16 +4,11 @@
*/
package org.mockitousage.stubbing;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
-import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockitoutil.ThrowableAssert.assertThat;
-import org.assertj.core.api.Assertions;
-import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mock;
@@ -104,68 +99,4 @@ public class StrictStubbingTest {
}
}).throwsException(UnnecessaryStubbingException.class);
}
-
- private static void assertUnusedStubbingsWhen(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, int unusedStubbingsCount) {
- Assertions.assertThatThrownBy(shouldRaiseThrowable)
- .isInstanceOf(UnnecessaryStubbingException.class)
- .hasMessageContaining(unusedStubbingsCount + " unnecessary stubbing");
- }
-
- @Test public void repeated_unnecessary_stubbing() {
- given(mock.simpleMethod("1")).willReturn("one");
- given(mock.simpleMethod("2")).willReturn("three");
- given(mock.simpleMethod("1")).willReturn("two"); //repeat 1x
- given(mock.simpleMethod("1")).willReturn("four"); //repeat 2x
-
- mock.simpleMethod("1");
- mock.simpleMethod("2");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 2);
- }
-
- @Test public void repeated_unnecessary_stubbing_willReturn() {
- willReturn("one").given(mock).simpleMethod("1");
- willReturn("three").given(mock).simpleMethod("2");
- willReturn("two").given(mock).simpleMethod("1");
- willReturn("four").given(mock).simpleMethod("1");
-
- mock.simpleMethod("1");
- mock.simpleMethod("2");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 2);
- }
-
- @Test public void unnecessary_stubbing_with_any_matchers() {
- given(mock.simpleMethod((String) any())).willReturn("one");
- given(mock.simpleMethod(anyString())).willReturn("three");
-
- mock.simpleMethod("1");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 1);
- }
-
- @Test public void unnecessary_stubbing_with_mixed_matchers() {
- given(mock.simpleMethod(anyString())).willReturn("one");
- given(mock.simpleMethod("foo")).willReturn("three");
-
- mock.simpleMethod("1");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 1);
- }
-
- @Test public void unnecessary_stubbing_with_stubs_only() {
- given(mock.simpleMethod(anyString())).willReturn("one");
- given(mock.simpleMethod("foo")).willReturn("three");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 2);
- }
-
- @Test public void unnecessary_stubbing_with_mixed_matchers_willReturn() {
- willReturn("one").given(mock).simpleMethod(anyString());
- willReturn("three").given(mock).simpleMethod("foo");
-
- mock.simpleMethod("1");
-
- assertUnusedStubbingsWhen(() -> mockito.finishMocking(), 1);
- }
}
=====================================
version.properties
=====================================
@@ -1,5 +1,5 @@
#Currently building Mockito version
-version=3.3.1
+version=3.3.4
#Previous version used to generate release notes delta
-previousVersion=3.3.0
+previousVersion=3.3.3
View it on GitLab: https://salsa.debian.org/java-team/mockito/-/compare/471a2d89fc9cc28a7588028886e6572173f74144...1ecbd0acc6f798b42b046fe75c00fee13da5cc5e
--
View it on GitLab: https://salsa.debian.org/java-team/mockito/-/compare/471a2d89fc9cc28a7588028886e6572173f74144...1ecbd0acc6f798b42b046fe75c00fee13da5cc5e
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20250501/3f50d40d/attachment.htm>
More information about the pkg-java-commits
mailing list