Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

im trying to Mock below 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;
    }
}

Code to be Mocked:

TestEntityDO[] testEntityMock = testmethod.getTestEntityDO();

Mocking i tried:

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

exception trace:

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 is not a final class. still the exception is pointed as final class. please help me to solve this issue.

like image 407
Manjunath Avatar asked Oct 25 '15 15:10

Manjunath


1 Answers

You're trying to create a subclass/mock of an array of TestEntityDO. Arrays are final.

like image 143
Kayaman Avatar answered Nov 05 '22 19:11

Kayaman