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

@MockContainer 注解对于继承类的void方法不能正常生效 #322

Open
jixf opened this issue Mar 31, 2023 · 0 comments
Open

@MockContainer 注解对于继承类的void方法不能正常生效 #322

jixf opened this issue Mar 31, 2023 · 0 comments

Comments

@jixf
Copy link

jixf commented Mar 31, 2023

被mock类:
/**

  • 演示使用@MockContainer注解实现Mock容器类的多重继承

  • Demonstrate multiple inherit of mock container class with @MockContainer annotation
    */
    public class DemoMultipleInherit {

    private String prefix() {
    return "ori_";
    }

    private String middle() {
    return "gin";
    }

    public void ss(){
    System.out.println("abd");
    }

    private String suffix(int some, String more, Object[] parameters) {
    return "_al";
    }

    public String entry() {
    return prefix() + middle() + suffix(0, null, null);
    }

}

mock类代码:

/**

  • 演示使用@MockContainer注解实现Mock容器类的多重继承

  • Demonstrate multiple inherit of mock container class with @MockContainer annotation
    */
    class DemoMultipleInheritTest {

    private DemoMultipleInherit demoMultipleInherit = new DemoMultipleInherit();

    public static class PrefixMock {
    @MockInvoke(targetClass = DemoMultipleInherit.class)
    private String prefix() {
    return "in_";
    }
    }

    public static class SuffixMock {
    @MockInvoke(targetClass = DemoMultipleInherit.class)
    private String suffix(int some, String more, Object[] parameters) {
    return "_it";
    }

     @MockInvoke(targetClass = DemoMultipleInherit.class)
     private void ss(){
         System.out.println("aaaddd");
     }
    

    }

    @MockContainer(inherits = { PrefixMock.class, SuffixMock.class })
    public static class Mock {
    @MockInvoke(targetClass = DemoMultipleInherit.class)
    private String middle() {
    return "her";
    }
    }

    @test
    public void should_use_mock_method_in_parent_class() {
    assertEquals("in_her_it", demoMultipleInherit.entry());
    demoMultipleInherit.ss();
    verifyInvoked("prefix").withTimes(1);
    verifyInvoked("middle").withTimes(1);
    verifyInvoked("suffix").withTimes(1);
    }
    }

异常提示:
java.lang.VerifyError: Operand stack underflow
Exception Details:
Location:
com/alibaba/demo/inherit/DemoMultipleInheritTest$Mock.ss(Lcom/alibaba/demo/inherit/DemoMultipleInherit;)V @7: areturn
Reason:
Attempt to pop empty stack.
Current Frame:
bci: @7
flags: { }
locals: { 'com/alibaba/demo/inherit/DemoMultipleInheritTest$Mock', 'com/alibaba/demo/inherit/DemoMultipleInherit' }
stack: { }
Bytecode:
0x0000000: b800 392b b600 3fb0

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

1 participant