如何使用EasyMock在Java中测试受保护的最终方法?

我想使用EasyMock在Java中为以下受保护的最终方法编写测试用例。有什么方法可以使用EasyMock编写受保护的最终方法的测试用例吗?

我尝试使用反射方法编写TC,但是没有用。

Class < ? extends Entity > type;
private Filter filter;
private Input input;
private transient Service access;
private transient ConfigDao confdao;

protected final Limitation getBaseLimitation() {
    Validate.notNull(type);
    GroupClass Group = new GroupClass(GroupTypeclass.SELECTOR);
    if (A.class.isAssignableFrom(type)) {
        filter = new Simple(A.ATTRIBUTE_actIVE,Operator.EQUALS,Boolean.TRUE); //A class has static final static String ATTRIBUTE_actIVE = "active";
    }
    if (G.class.isAssignableFrom(type)) {
        filter = new Simple("position",Position.actIVE);
    }
    if (Boolean.TRUE.equals(confdao.getconfdao().getarea())) {
        if (U.class.isAssignableFrom(type)) {
            Validate.notNull(input,"switched on.");
            Object Inputobj = input.getInput();
            return access.getBaseLimitation(type,Inputobj,Group,filter);
        }
    }
    return access.getBaseLimitation(type,filter);
}

public Simple(String path,Operator operator,Object value) {
    this(Path,operator,new Object[]{value});
}

任何帮助将不胜感激。

wangsl002 回答:如何使用EasyMock在Java中测试受保护的最终方法?

如果您在嘲笑getBaseLimitation(),则不会,EasyMock无法为您提供帮助,因为无法覆盖最终方法。 PowerMock可以为您提供帮助,但我个人只是放弃final

如果要测试它,则可以从同一包中的一个类中进行。但是不需要EasyMock。

然后,protected final没什么用。如果不想过载,为什么要受到保护?您最好是包范围的或私有的。

本文链接:https://www.f2er.com/3103395.html

大家都在问