Comments (1)
The reason your test doesn't work as you've written it is because you are trying to verify interactions on the Logger
mock instead of the LogService
mock. When you write:
verify(logger, times(1)).warn("Test message {}", 15);
You are trying to verify interactions directly on the logger
mock, but in your test, you are calling the warn
method on a mock of LogService
. In other words, you are verifying interactions on the wrong mock.
To make the test work, you should change your verification to reflect the interactions on the correct mock. In this case, you should verify that the warn
method of the LogService
mock has been called, not the logger's method.
Change the code as following:
final LogService logService = mock(LogService.class);
logService.warn("Test message {}", 15);
verify(logger, times(1)).warn("Test message {}", 15);`
With this modification, you are verifying that the warn
method of the LogService
mock has been called correctly with the specified parameters.
However, the explanation for why your test doesn't work in the suite is provided in this issue:
from mockito.
Related Issues (20)
- How to mock private static method in Mockito HOT 1
- Release job is broken on out-of-date publish plugin HOT 5
- Method `Only.verify` throws `NullPointerException`
- Is `Boolean.TRUE` really equal to `true` ? HOT 2
- Mockito is calling real function instead of calling mocked function
- Mockito bom missing artifact in maven central for java21 HOT 3
- Unable to @InjectMocks on instance of android.app.Activity HOT 1
- Mockito's deep-stub mocking doesn't do well when lambda arguments are involved
- Adding @MockitoSettings to field with @RegisterExtension makes test fail with PreconditionViolationException
- Adding @MockitoSettings to class changes order of extensions in @ExtendWith
- MockSettings.strictness() not observed HOT 2
- Mockito verify message not accurate if type is fields are of Object
- when does not throw MissingMethodInvocationException HOT 1
- Spy annotation does not seem to work after switching from Mockito 4.8.1 to 5.10.0 HOT 1
- `mockStatic` fails with `class redefinition failed: invalid class` HOT 5
- mockito
- Field with generics is not injected using @InjectMocks HOT 1
- Possible race condition HOT 3
- MissingMethodInvocationException is thrown when mocking native method in 5.x HOT 1
- ByteBuddy agent fails to install on GraalVM HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockito.