Code Monkey home page Code Monkey logo

Comments (2)

p-dmitriy avatar p-dmitriy commented on June 10, 2024 1

I faced same issue with mocking final class after updating mockito kotlin from 4.1.0 to 5.1.0. I mock class that has such hierarchy:

  1. interface Interface
  2. abstract class BaseClass: Interface
  3. abstract class BaseTypedClass: BaseClass
  4. class ImplClass : BaseTypedClass

When I mock ImplClass I got this error:

Mockito cannot mock this class: class ru.gibdd_pay.app.utils.experimentalFeatureManager.experiments.KaskoTabExperiment.
Can not mock final classes with the following settings :
 - explicit serialization (e.g. withSettings().serializable())
 - extra interfaces (e.g. withSettings().extraInterfaces(...))

When I mock BaseTypedClass<Type> I got this error:

Mockito cannot mock this class: class ru.gibdd_pay.app.utils.experimentalFeatureManager.core.RemoteNewOldUsersExperiment.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java               : 17
JVM vendor name    : Amazon.com Inc.
JVM vendor version : 17.0.8.1+8-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 17.0.8.1+8-LTS
JVM info           : mixed mode, sharing
OS name            : Mac OS X
OS version         : 13.5.2
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

At the end of error message I saw this, seems it is a problem:
Mismatch of count of formal and actual type arguments in constructor of com.package.ImplClass$classField$1: 0 formal argument(s) 1 actual argument(s)

Successfully fixed this by explicitly specifying type of classField. Before it just was initialized with anonymous object of type BaseClass.

from mockito-kotlin.

HaliksaR avatar HaliksaR commented on June 10, 2024

Mockito cannot mock this class: interface

Java               : 21
JVM vendor name    : Amazon.com Inc.
JVM vendor version : 21.0.2+13-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.2+13-LTS
JVM info           : mixed mode, sharing
OS name            : Mac OS X
OS version         : 14.1.2

deps

'kotlinMockito'      : "org.mockito.kotlin:mockito-kotlin:5.2.1",
'mockitoJupiter'     : "org.mockito:mockito-junit-jupiter:5.10.0",

args

jvmArgs("-Dnet.bytebuddy.experimental=true")

from mockito-kotlin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.