Skip to content
Advertisement

Tag: mockito

Ignoring only embedded member in AssertJ

I have two classes to test with JUnit/Mockito: Then in my test class, using AssertJ: The problem is that the name sk is in both classes, and I need to ignore it only in ClassA, not in ClassB. Is this possible in AssertJ? Answer According to the ignoringFields javadoc: Nested fields can be specified like this: home.address.street. …so with your

How to tests and mock mapstruct converter?

I’m using MapStruct framework on my java Gradle project, and it works perfectly but I just want to test : MapStruct generated sources (converter) service class (calls MapStruct’s converter) I have tried to use another topic to do this but it is not working for me. This is my MapStruct interface : This is my service class : When I’m

Are Java Mockito mocked method invocations thread safe?

I am writing unit tests that test the thread safety of individual Java classes. I use Mocktio to set up the tests and verify the interactions in a multithreaded environment are done as per the expectations, and threads do not interfere with business expectations. Are Mockito mocks thread-safe in that context? Can the mocked methods be called by many threads

Mocking Unirest with mockito

I am in my starting programming phase and I wanted to ask about mocking Objects with Mockito, more specifically is the Unirest response. Let’s say I have a database, and I dont what to bother it every time I do testing, and I want to use Mockito for that, but the problem is I am not sure how to create

What is mockito-inline and how does it work to mock final methods?

Javadocs in Mockito says – “Starting with version 2.7.6, we offer the ‘mockito-inline’ artifact that enables inline mock making without configuring the MockMaker extension file”. What does this mean? How does mockito-inline works ? Why a separate artifact for mockito-inline? Answer I stumbled upon this too and the answer is buried quite deep in the docs, so here it is.

Mockito thenReturn returns null when coming from generic function

I want to mock the ResultSet in a class, whose parameters come from a generic return function (getSQLValue): The table class with the signature method: And this is the unit test class: The problem is that the ResultSet is always null, I can confirm when debugging. Answer Turns out that Mockito, after “accepting” the first argument as Integer, fails to

Advertisement