Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InjectMock does not work on observer method #11079

Closed
mickroll opened this issue Jul 30, 2020 · 6 comments · Fixed by #11122
Closed

InjectMock does not work on observer method #11079

mickroll opened this issue Jul 30, 2020 · 6 comments · Fixed by #11122
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@mickroll
Copy link
Contributor

Describe the bug
Mocking a bean with @io.quarkus.test.junit.mockito.InjectMock does not work for methods that use @Observes.
Example:
public void onExampleEvent(@Observes ExampleEvent event) {...}
This method is called when ExampleEvent is fired, even if the bean containing this method is mocked by using @InjectMock.
Hint: any other method of the same bean is mocked successfully.

Expected behavior

  • observer methods of a mocked bean should not be called when event is fired

Actual behavior

  • observer methods of a mocked bean are called when event is fired

To Reproduce
Steps to reproduce the behavior:

  1. git clone -b quarkus-observer-mock https://github.com/mickroll/demonstrator.git
  2. run mvn clean install

Configuration
none

Screenshots
none

Environment (please complete the following information):

  • Output of uname -a or ver: Microsoft Windows [Version 10.0.18363.959]
  • Output of java -version: openjdk version "11.0.7" 2020-04-14
  • GraalVM version (if different from Java): /
  • Quarkus version or git rev: 1.6.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3

Additional context
the demonstrator was built similar to https://github.com/quarkusio/quarkus-quickstarts/tree/master/getting-started-testing

@mickroll mickroll added the kind/bug Something isn't working label Jul 30, 2020
@geoand
Copy link
Contributor

geoand commented Jul 30, 2020

From @mkouba

I think that this is expected behavior - a bean that declares an observer is not removed and thus will be notified when a relevant event is fired, it's very similar to CDI @Alternatives - the beans are still there but cannot be injected

@famod
Copy link
Member

famod commented Jul 30, 2020

I don't want to repeat the discussion from the zulip chat.
It's just that from a very user centric (not at all spec centric) view, you mock a bean (class). You expect the entire "class" to be mocked. 🤷‍♂️

I'll convert this to an enhancement instead of closing it (via the discussed documentation update PR) because that would look misleading in the next changelog.

@famod
Copy link
Member

famod commented Jul 30, 2020

I'll convert this to an enhancement instead of closing it (via the discussed documentation update PR) because that would look misleading in the next changelog.

It seems I am not allowed to do that. @geoand WDYT?

@geoand
Copy link
Contributor

geoand commented Jul 30, 2020

You mean you can't change labels?

@geoand geoand added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Jul 30, 2020
@geoand
Copy link
Contributor

geoand commented Jul 30, 2020

I don't really now what the exact permissions are (I'm not an admin of the repo)

@mkouba
Copy link
Contributor

mkouba commented Jul 31, 2020

You expect the entire "class" to be mocked.

@famod I get your point. I think that we could try to temporarily disable all observers declared on mocked beans. I'll do some POC and we'll see how it goes...

mkouba added a commit to mkouba/quarkus that referenced this issue Jul 31, 2020
mkouba added a commit to mkouba/quarkus that referenced this issue Jul 31, 2020
- also rename MockableProxy to Mockable and remove it from the public API
- resolves quarkusio#11079
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 3, 2020
- also rename MockableProxy to Mockable and remove it from the public API
- resolves quarkusio#11079
@gsmet gsmet added this to the 1.7.0.CR2 milestone Aug 4, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 4, 2020
- also rename MockableProxy to Mockable and remove it from the public API
- resolves quarkusio#11079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants