Giter Site home page Giter Site logo

Comments (6)

asomers avatar asomers commented on July 21, 2024

Could you explain in more detail what spy! would do? I'm unfamiliar with this Java library.

from mockall.

iddm avatar iddm commented on July 21, 2024

Would this guide be of help? https://www.baeldung.com/mockito-spy

from mockall.

asomers avatar asomers commented on July 21, 2024

So it wraps a real object, but records all of its calls for later inspection? I'm sure there would be s lot of hard cases. What about static methods? Generic methods?

from mockall.

iddm avatar iddm commented on July 21, 2024

So it wraps a real object, but records all of its calls for later inspection? I'm sure there would be s lot of hard cases. What about static methods? Generic methods?

It is almost the same as a mock, but it has a real object inside, and yes, it records all the info for later inspection. As for the static methods, there are two ways:

  1. Code generation, where the static methods are also mocked the same way as an ordinary method.
  2. An error is thrown.

Both of these are utilised in different Java frameworks. For example, the Spring framework doesn't care about the types at all: if it sees that an object can be changed fully without the code generation, it does just that; if it sees that the object is impossible to replace without the code generation, it utilises the same interface of the needed object to generate the code which does the required job. This is the mechanism for the bean injection: by an interface of implementation. Various unit testing frameworks also do one thing or another, so it depends.

The generic types are flattened, the same as when the compiler flattens it for a single symbol name. The generics are always parametrised, so there must be a parametrised mock, there can't be a non-parametrised mock.

As for this crate, I suggest we have a more versatile method where we also generate the code in case it is required.

from mockall.

asomers avatar asomers commented on July 21, 2024

What do you mean "without the code generation"? How would any of this work without code generation?

from mockall.

iddm avatar iddm commented on July 21, 2024

What do you mean "without the code generation"? How would any of this work without code generation?

Without generating a completely new code for the same type, which does exactly what the original one does, with or without decorating. I meant the code generation in Java terms, not in Rust terms. Of course, we always generate code in Rust here, but in Java, for the mocks, we can implement the interface and exploit the difference in behaviour this way, while for a concrete type (or any other type that can't be mocked any other way), we can only regenerate the code and either wrap the real object inside and delegate the calls to it, or copy-paste the code from the original implementation using the language reflection mechanisms to inline it into the just-generated type. So, please, don't be confused with the "code generation" from Java, just ignore it then.

from mockall.

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.