Releases: lupuuss/Mokkery
3.3.0
3.2.0
Changelog
🚀 Features
- #15 Now it's possible to use
everyandeverySuspendwith function references.
every(foo::getAt) returns 10
every(foo::values::get) returns listOf(2, 3)
every(foo::values::set) returns Unit
foo.values // returns listOf(2, 3)
foo.values = emptyList() // returns Unit
foo.getAt(0) // returns 10
foo.getAt(1) // returns 10
foo.getAt(2) // returns 10- #126 Now it's possible to configure annotations that are copied from a type to a mock implementation.
import dev.mokkery.options.AnnotationSelector.Companion.all
import dev.mokkery.options.AnnotationSelector.Companion.none
import dev.mokkery.options.AnnotationSelector.Companion.named
mokkery {
annotations {
copyToMock = none // No annotations
copyToMock = all - named("example.A") // All annotations except "example.A"
copyToMock = named("example.A") // Only "example.A"
}
}✨ Improvements
mokkery-pluginis now published as a fat JAR. This makes compiler plugin setup without the Gradle plugin easier.- Improved compiler options syntax. Another step toward setup without the Gradle plugin.
🐛 Bug fixes
- Avoid trying to access non-public constructors while stubbing
- Fix incorrectly listing open types as problematic when only one of stub types is raised
🌳 Dependencies
- Bump Kotlin to 2.3.10
- Bump atomicfu to 0.31.0
3.1.1
3.1.0
Changelog
This release focuses on improving mocking classes with parameterized constructors. You can read more about it here.
🚀 Features
- #108 Mocking classes with constructors that access their parameters should no longer cause runtime exceptions
notmatcher accepts more than one matcher
⚠️ Breaking changes
- Bump minimum Kotlin version to 2.3.0
🐛 Bug fixes
- Fix compatibility broken by Kotlin 2.3.0
- #118 Fix
ClassCastExceptionwhen mocking classes with constructors that accepts complex types
3.0.0
Changelog
This major update introduces a full refactor of the templating mechanism - everything that happens inside every and verify blocks.
It addresses a wide range of bugs that previously caused unexpected errors when setting up a behavior for a method,
and it now provides compile-time validation for these blocks.
Also, this version deprecates vararg matchers. Now, any matcher that accepts array can be used with spread operator (*).
// Mokkery 2
every { mock.callWithVarargs(1, *anyIntVarargs(), 10) } returns 1
every { mock.callWithVarargs(1, *varargsIntAll { it % 2 == 0 }, 10) } returns 1
// Mokkery 3
every { mock.callWithVarargs(1, *any(), 10) } returns 1
every { mock.callWithVarargs(1, *containsAllInts { it % 2 == 0 }, 10) } returns 1The new approach allows you to easily create custom matchers and use them with the spread operator:
every { mock.callWithVarargs(1, *matches { it.size > 2 }, 10) } returns 1
// Matches a call with varargs that starts with 1, ends with 10, and has at least two elements in between.🚀 Features
- Most
every/verifymisuses are now reported at compile time. - Full support for default arguments.
Previously, only methods with constant default values could be mocked.
Now, Mokkery correctly verifies default values computed from other arguments, provided these computations are deterministic.
If the default value is non-deterministic (e.g., random), it cannot be verified because it’s not possible to predict the correct value for the call. - Literals can be mixed with matchers in any scenario - for example, when passed to composite matchers.
- Support for methods with context parameters.
- Removes the WASM value classes limitation.
It is no longer necessary to set up anAutofillProviderto mock a method that accepts or returns a value class. - Now, it's allowed to call
everyandverifyon the same mock in parallel. - Matchers can be extracted to variables.
- It’s now possible to use any matcher that accepts an array as a vararg matcher (with the spread operator).
- Added
containsAllforIterableand array types. Matches a collection in which all elements satisfy the predicate. - Added
containsAnyforIterableand array types. Matches a collection in which any element satisfies the predicate.
⚠️ Breaking changes
ArgMatchersScope(renamed toMokkeryMatcherScope) no longer contains the methodfun <T> matches(argType: KClass<*>, matcher: ArgMatcher<T>): T.
Its usage should be replaced with the extension functionfun <T> MokkeryMatcherScope.matches(matcher: ArgMatcher<T>): T.- The registration process for composite matchers has changed. The
compose,isFilled, andassertFilledmethods have been removed fromArgMatcher.Composite. Refer to thedev.mokkery.matcher.matchesCompositedocumentation and existing implementations for the new approach to implementing composite matchers. - Scope functions can no longer be used to call mock methods inside templating blocks. Use the new
dev.mokkery.templating.extanddev.mokkery.templating.ctxAPIs to mock methods with extension receivers or context parameters.
🐛 Bug fixes
♻️ Deprecations
All deprecated functions have suggestions for replacement set up, so migration should be straightforward.
ArgMatchersScopeis renamed toMokkeryMatcherScope.- All vararg matcher declarations are deprecated:
VarArgMatcher,varargsAny,varargsAll,anyVarargs.
They should be replaced with equivalent regular matchers. eqis deprecated - it can be omitted.neqis deprecated - replace withnot.eqRefis renamed toref.neqRefis deprecated - replace withnot(ref(...)).matchingandmatchingByare renamed tomatchesandmatchesBy.- Removed the deprecated
FunctionScopeAPI.
✨ Improvements
- Compiler plugin is no longer applied to
KotlinMetadataTarget.
3.0.0-RC
Changelog
✨ Improvements
- Optimize
verifyandverifySuspend - Improves templating IR transformation, so it's safer and better indicates misuse
- Compiler plugin is no longer applied to KotlinMetadataTarget
🐛 Bug Fixes
- Fix incorrect
ReplaceWithforvarargsAny
3.0.0-Beta3
Changelog
The main focus of this version is deprecating all vararg matcher declarations and allowing the use of any regular matcher that accepts an array with the spread operator. It’s easier to show with an example:
// Mokkery 2
every { mock.callWithVarargs(1, *anyIntVarargs(), 10) } returns 1
every { mock.callWithVarargs(1, *varargsIntAll { it % 2 == 0 }, 10) } returns 1
// Mokkery 3
every { mock.callWithVarargs(1, *any(), 10) } returns 1
every { mock.callWithVarargs(1, *containsAllInts { it % 2 == 0 }, 10) } returns 1The new approach allows you to easily create custom matchers and use them with the spread operator:
every { mock.callWithVarargs(1, *matches { it.size > 2 }, 10) } returns 1
// Matches a call with varargs that starts with 1, ends with 10, and has at least two elements in between.🚀 Features
- It’s now possible to use any matcher that accepts an array as a vararg matcher (with the spread operator).
- Added
containsAllforIterableand array types. Matches a collection in which all elements satisfy the predicate. - Added
containsAnyforIterableand array types. Matches a collection in which any element satisfies the predicate.
⚠️ Breaking Changes
- The
VarArgMatcherBuilderannotation has been removed (introduced in Mokkery 3.0.0-Beta1).
🐛 Bug Fixes
- Fixed a
ClassCastExceptionthat occurred when changing argument order with Kotlin 2.3.0. - Fixed a
ClassCastExceptionthat occurred when initializing a variable with awhenexpression that returns a matcher.
♻️ Deprecations
All deprecated functions have suggestions for replacement set up, so migration should be straightforward.
- All vararg matcher declarations are deprecated:
VarArgMatcher,varargsAny,varargsAll,anyVarargs.
They should be replaced with equivalent regular matchers. eqis deprecated - it can be omitted.neqis deprecated - replace withnot.eqRefis renamed toref.neqRefis deprecated - replace withnot(ref(...)).matchingandmatchingByare renamed tomatchesandmatchesBy.
2.10.2
2.10.1
3.0.0-Beta2
Changelog
Adds the changes from Mokkery 2.10.0 to Mokkery 3.0.0
🚀 Features
- Add possibility to call spied function from
callsusingcallSpiedorcallSpiedWith - Add
MokkeryBlockingCallScope.callSpiedandMokkerySuspendCallScope.callSpied