JAVA: java.lang.IllegalArgumentException: 不能 subclass final class class [Lcom.package.testEntityDO;

JAVA: java.lang.IllegalArgumentException: Cannot subclass final class class [Lcom.package.testEntityDO;

我正在尝试在 class 以下进行模拟。

 public class testEntityDO extends BasetestDO {
    private String entityType;  
    private testCapabilityDO[] capabilities;
    private testEntityDO[] testDOs;
    public String getEntityType() {
        return entityType;
    }
    public void setEntityType(String entityType) {
        this.entityType = entityType;
    }
    public testCapabilityDO[] getCapabilities() {
        return capabilities;
    }
    public void setCapabilities(testCapabilityDO[] capabilities) {
        this.capabilities = capabilities;
    }
    public TestEntityDO[] getTestPortDOs() {
        return testPortDOs;
    }
    public void setTestPortDOs(TestEntityDO[] testPortDOs) {
        this.testPortDOs = testPortDOs;
    }
}

要模拟的代码:

TestEntityDO[] testEntityMock = testmethod.getTestEntityDO();

模拟我试过:

TestEntityDO[] testEntityDOMock  = PowerMock.createMock(TestEntityDO[].class); // exception is generating at this point
EasyMock.expect(testmethod.getTestEntityDO()).andReturn(testEntityDOMock);

异常跟踪:

java.lang.IllegalArgumentException: Cannot subclass final class class [Lcom.package.TestEntityDO;
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)

class 不是最终的 class。仍然将异常指向最终 class。 请帮我解决这个问题。

您正在尝试创建一个 subclass/mock 的 TestEntityDO 数组。数组是最终的。