Skip to content

Releases: lupuuss/Mokkery

3.3.0

18 Mar 00:18
ffb2524

Choose a tag to compare

Changelog

🐛 Bug fixes

  • #125 Fix compatibility broken by Kotlin 2.3.20
  • #131 Fix memory leak in Mokkery Gradle plugin

✨ Improvements

  • Make Mokkery generated output reproducible

3.2.0

11 Feb 18:35
90d9dad

Choose a tag to compare

Changelog

🚀 Features

  • #15 Now it's possible to use every and everySuspend with 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-plugin is 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

17 Dec 23:30
f6e24dc

Choose a tag to compare

Changelog

🐛 Bug fixes

  • #122 Fix FIR reporting error for classes to mock that accept enum as a parameter in the constructor

3.1.0

17 Dec 00:05
e641e91

Choose a tag to compare

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
  • not matcher 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 ClassCastException when mocking classes with constructors that accepts complex types

3.0.0

23 Nov 16:27
f478623

Choose a tag to compare

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 1

The 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 / verify misuses 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 an AutofillProvider to mock a method that accepts or returns a value class.
  • Now, it's allowed to call every and verify on 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 containsAll for Iterable and array types. Matches a collection in which all elements satisfy the predicate.
  • Added containsAny for Iterable and array types. Matches a collection in which any element satisfies the predicate.

⚠️ Breaking changes

  • ArgMatchersScope (renamed to MokkeryMatcherScope) no longer contains the method fun <T> matches(argType: KClass<*>, matcher: ArgMatcher<T>): T.
    Its usage should be replaced with the extension function fun <T> MokkeryMatcherScope.matches(matcher: ArgMatcher<T>): T.
  • The registration process for composite matchers has changed. The compose, isFilled, and assertFilled methods have been removed from ArgMatcher.Composite. Refer to the dev.mokkery.matcher.matchesComposite documentation 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.ext and dev.mokkery.templating.ctx APIs to mock methods with extension receivers or context parameters.

🐛 Bug fixes

  • #100 #96 Unexpected errors during templating

♻️ Deprecations

All deprecated functions have suggestions for replacement set up, so migration should be straightforward.

  • ArgMatchersScope is renamed to MokkeryMatcherScope.
  • All vararg matcher declarations are deprecated: VarArgMatcher, varargsAny, varargsAll, anyVarargs.
    They should be replaced with equivalent regular matchers.
  • eq is deprecated - it can be omitted.
  • neq is deprecated - replace with not.
  • eqRef is renamed to ref.
  • neqRef is deprecated - replace with not(ref(...)).
  • matching and matchingBy are renamed to matches and matchesBy.
  • Removed the deprecated FunctionScope API.

✨ Improvements

  • Compiler plugin is no longer applied to KotlinMetadataTarget.

3.0.0-RC

10 Nov 17:38

Choose a tag to compare

3.0.0-RC Pre-release
Pre-release

Changelog

✨ Improvements

  • Optimize verify and verifySuspend
  • Improves templating IR transformation, so it's safer and better indicates misuse
  • Compiler plugin is no longer applied to KotlinMetadataTarget

🐛 Bug Fixes

  • Fix incorrect ReplaceWith for varargsAny

3.0.0-Beta3

28 Oct 20:10

Choose a tag to compare

3.0.0-Beta3 Pre-release
Pre-release

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 1

The 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 containsAll for Iterable and array types. Matches a collection in which all elements satisfy the predicate.
  • Added containsAny for Iterable and array types. Matches a collection in which any element satisfies the predicate.

⚠️ Breaking Changes

  • The VarArgMatcherBuilder annotation has been removed (introduced in Mokkery 3.0.0-Beta1).

🐛 Bug Fixes

  • Fixed a ClassCastException that occurred when changing argument order with Kotlin 2.3.0.
  • Fixed a ClassCastException that occurred when initializing a variable with a when expression 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.
  • eq is deprecated - it can be omitted.
  • neq is deprecated - replace with not.
  • eqRef is renamed to ref.
  • neqRef is deprecated - replace with not(ref(...)).
  • matching and matchingBy are renamed to matches and matchesBy.

2.10.2

25 Oct 11:38
472d813

Choose a tag to compare

Changelog:

🐛 Bug fixes

  • Fix MokkerySuiteScope.mocks returning incorrect reference for JS function mocks

🌳 Dependencies

  • Bump kotlinx.atomicfu to 0.29.0.
  • Bump Kotlin to 2.2.21.
  • [jvm] Bump ByteBuddy to 1.17.8

2.10.1

05 Oct 10:27
0f51773

Choose a tag to compare

Changelog

🐛 Bug fixes

  • #110 Fixes NoClassDefFoundErrror: dev/mokkery/plugin/core/Mokkery$Errors
    Note that if you are affected by this issue, you need to clear the Gradle caches for the fix to work. Please read the issue description for more details.

3.0.0-Beta2

15 Sep 21:01

Choose a tag to compare

3.0.0-Beta2 Pre-release
Pre-release

Changelog

Adds the changes from Mokkery 2.10.0 to Mokkery 3.0.0

🚀 Features

  • Add possibility to call spied function from calls using callSpied or callSpiedWith
  • Add MokkeryBlockingCallScope.callSpied and MokkerySuspendCallScope.callSpied

🐛 Bug fixes

  • #98 Fix compatibility broken by Kotlin 2.2.20
  • #97 Fix crash when creating a mock of a class with abstract type parameters for Android instrumented test.
  • #106 Fix CallArgument constructor resolution by the compiler plugin