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

Spy does not see method called in feedback call #3302

Open
3 tasks done
misczu opened this issue Mar 22, 2024 · 3 comments
Open
3 tasks done

Spy does not see method called in feedback call #3302

misczu opened this issue Mar 22, 2024 · 3 comments

Comments

@misczu
Copy link

misczu commented Mar 22, 2024

check that

  • The problematic code (if that's possible) is copied here;

         class A {
               B callee;
               public A(B callee) {
                 this.callee = callee;
                 callee.setCallback(this);
               }
               public void call(String val) {
                 callee.executeAndCallback(val);
               }
               public void receive(String val) {
                 System.out.println("Received: " + val);
               }
         }
         
         class B {
             A callback;
             public void setCallback(A callback) {
               this.callback = callback;
             }
             public void executeAndCallback(String val) {
               callback.receive(val);
             }
         }
         
         @Test
         void test() {
               //given
               B b = new B();
               A a = new A(b);
               A spyA = spy(a);
               //when
               spyA.call("123");
               //then
               verify(spyA, times(1)).receive(anyString());
         }
    
  • Provide versions (mockito / jdk / os / any other relevant information)

  • mockito-core - 5.11.0
    junit-jupiter - 5.10.2
    java 17
    W10

  • Error

Wanted but not invoked:
a.receive();
-> at dk.bec.mortgage.resultclient.service.POC_Test$A.receive(POC_Test.java:24)

However, there was exactly 1 interaction with this mock:
a.call("123");
-> at dk.bec.mortgage.resultclient.service.POC_Test.test(POC_Test.java:47)

@misczu
Copy link
Author

misczu commented Mar 25, 2024

@raphw can you look into this, please? :)

@raphw
Copy link
Member

raphw commented Mar 25, 2024

Shouldn't you specify that the real method should be invoked?

@misczu
Copy link
Author

misczu commented Apr 5, 2024

but it is spy, so it is calling real method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants