zoukankan      html  css  js  c++  java
  • PowerMock.expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments)

    1:PowerMock.expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments)

    如果你要Mock的类有多个构造方法,在你exceptNew的时候会要求你指定参数类型,此时就会用到上面说的方法其中第二个为参数类型

    如果参数是String类型parameterTypes应该填new Class[]{String.class} 如果有多个参数,在大括号内按顺序添加。

    2:当我们要测的类的构造方法是private的或者是protected的的时候,要想调用构造方法的时候就要用到Whitebox.invokeConstructor()这个方法,如果要指定参数类型的话,如果参数是String类型,正确的填写应该是Whitebox.invokeConstructor(xxx.class,new Class[]{String.class},new Object[]{"xxx"});

  • 相关阅读:
    344.反正字符串
    125.验证回文串
    167.两数之和 II
    278.第一个错误的版本
    缓冲流
    Windows10剪贴板不能用
    chapter_21【字节流、字符流】
    属性集
    IO异常的处理
    字符流
  • 原文地址:https://www.cnblogs.com/xiaotianyu/p/3288538.html
Copyright © 2011-2022 走看看