简体   繁体   中英

java.lang.ClassCastException on Sonar

Recently I've been assigned to examine Java code coverage using Sonar with Maven. I run mvn sonar:sonar and the build comes out just fine, plus I can see the result from the dashboard.

However, the test cases come out as errors, which does not happen at all if I run it normally. Here is the error stack trace:

$Proxy11 cannot be cast to com.epsilon.agility.message.dao.MessageDAO
java.lang.ClassCastException: $Proxy11 cannot be cast to                    com.epsilon.agility.message.dao.MessageDAO
at  com.epsilon.agility.message.utils.MessageDBAdaptorService.getMessageDAO(MessageDBAdaptorSer vice.java:32)
at com.epsilon.agility.message.facade.MessageClassificationFacadeImpl.initilaizeDAOs(MessageClassificationFacadeImpl.java:91)
at com.epsilon.agility.message.facade.MessageClassificationFacadeImpl.<init>(MessageClassificationFacadeImpl.java:86)
at com.epsilon.agility.message.dao.test.TestMessageClassificationFacadeImpl.setUp(TestMessageClassificationFacadeImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:49)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:36)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

Here is the method involved in the error:

@BeforeClass
@Transactional(propagation = Propagation.REQUIRED, timeout = 10)
public static void setUp() throws IOException {
    conn = TestDBUtils.getDBConnection();

    MessageDBAdaptorService.init(conn);

    msgclassificationFacade = new MessageClassificationFacadeImpl(conn);

    messageDAO = MessageDBAdaptorService.getMessageDAO();
    messageAssetDAO = MessageDBAdaptorService.getMessageAssetDAO();
    channelDAO = MessageDBAdaptorService.getChannelDAO();
    folderItemDAO = MessageDBAdaptorService.getFolderItemDAO();
    folderDAO = MessageDBAdaptorService.getFolderDAO();


    Assert.assertNotNull(messageDAO);
    Assert.assertNotNull(messageAssetDAO);
    Assert.assertNotNull(channelDAO);
    Assert.assertNotNull(folderItemDAO);
    Assert.assertNotNull(folderDAO);

}

I've searched the solutions online but it seems that there is no similar solution for Sonar. I suspect that the problem might come from Sonar's different approach for test cases since the test cases run fine on normal basis.

I will post more code and information if the above are not enough. Thanks for any help.

It doesn't seem to be a Sonar problem. From the stack trace I assume that maven surefire plugin can't execute a particular test. If I were you I'd the following. - Verify that you custom build and Sonar are using the same maven surefire plugin version and have the same configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM