Initializing Jmockit with Intellij idea WARNING - java

I am having issue running jmockit on idea.
I have testng test case that uses jmockit to mock.
I am getting:
WARNING: JMockit was initialized on demand, which may cause certain tests to fail;
please check the documentation for better ways to get it initialized.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:108)
Caused by: java.lang.NullPointerException
at mockit.internal.startup.Startup.redefineMethods(Startup.java:184)
at mockit.internal.startup.Startup.redefineMethods(Startup.java:176)
at mockit.internal.annotations.MockClassSetup.applyClassModifications(MockClassSetup.java:190)
at mockit.internal.annotations.MockClassSetup.redefineMethodsInClassHierarchy(MockClassSetup.java:151)
at mockit.internal.annotations.MockClassSetup.redefineMethods(MockClassSetup.java:140)
at mockit.Mockit.setUpMocks(Mockit.java:249)
at mockit.integration.testng.internal.TestNGRunnerDecorator.<init>(TestNGRunnerDecorator.java:67)
at mockit.integration.testng.internal.TestNGRunnerDecorator.registerWithTestNG(TestNGRunnerDecorator.java:60)
at mockit.integration.testng.Initializer.<init>(Initializer.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.testng.internal.ClassHelper.newInstance(ClassHelper.java:48)
at org.testng.TestNG.setListenerClasses(TestNG.java:637)
at org.testng.TestNG.configure(TestNG.java:1372)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:187)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:111)
Here is the order of jars:
Here in part 4 it is telling what is the order and i am making this order but still getting warning which later is causing problem.
Anyone knows what is the problem?
I am using
jdk1.6.0_25
Intellij idea 11.1.2
testng-6.3.1
jmockit-0.999.16

You are using incomplete TestNG jar from Maven, you need to use the full distribution from the TestNG site (testng.org/testng-xxx.zip), see this answers for the details:
How to update IntelliJ IDEA testing-plugin to TestNG version 6.8?

Related

Test with Coverage Intellij Error

I can run all test and they passed but when i run with coverage i got error
FATAL ERROR in native method: processing of -javaagent
failedjava.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
com.intellij.rt.coverage.main.CoveragePremain.
premain(CoveragePremain.java:66)
... 6 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
at
com.intellij.rt.coverage.instrumentation.Instrumentator.premain(Instrumentator.j
ava:65)
... 11 more
Process finished with exit code 1
Exception in thread "main"
Why without coverage option they passed but with coverage not? And how can i fix this ?
The java.lang.reflect.InvocationTargetException is occur when underlying method throws the exception. if method which has been invoked/call with reflection API, throwing an exception. and reflection API will wrap exception in to InvocationTargetException which throw by underlying method. for more understanding you can refer below link of stackover flow Question Asked by : user550413 and Answer by many java experts. i think you can get suitable answer on this link.
What could cause java.lang.reflect.InvocationTargetException?
In my case it was casued by non-ASCII characters in Intellij path. The solution is to change directory in Intellij properties:
Workaround:
Add this line
-Djava.io.tmpdir=C:\Temp to the idea.exe.vmoptions file (in C:\Program Files\ideaIU-11.1.4\bin)
And make sure the C:\Temp exists.
Source : https://youtrack.jetbrains.com/issue/IDEABKL-5941#u=1401303711495

NoSuchMethodError com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity

I am running a Java test program to establish a connection to OrientDB and keep getting these exceptions when I run the code from within IntelliJ IDEA or OpenFire (xmpp server):
java.lang.NoSuchMethodError:
com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity(J)Lcom/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder;
at
com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManagerAbstract.(OSBTreeCollectionManagerAbstract.java:43)
at
com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManagerAbstract.(OSBTreeCollectionManagerAbstract.java:48)
at
com.orientechnologies.orient.client.remote.OSBTreeCollectionManagerRemote.(OSBTreeCollectionManagerRemote.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at
java.lang.Class.newInstance(Class.java:379) at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx$2.call(ODatabaseDocumentTx.java:2863)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx$2.call(ODatabaseDocumentTx.java:2854)
at
com.orientechnologies.common.concur.resource.OSharedContainerImpl.getResource(OSharedContainerImpl.java:64)
at
com.orientechnologies.orient.core.storage.OStorageAbstract.getResource(OStorageAbstract.java:143)
at
com.orientechnologies.orient.client.remote.OStorageRemoteThread.getResource(OStorageRemoteThread.java:658)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.initAtFirstOpen(ODatabaseDocumentTx.java:2853)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:260)
at
com.orientechnologies.orient.jdbc.OrientJdbcConnection.(OrientJdbcConnection.java:63)
at
com.orientechnologies.orient.jdbc.OrientJdbcDriver.connect(OrientJdbcDriver.java:52)
at java.sql.DriverManager.getConnection(DriverManager.java:571) at
java.sql.DriverManager.getConnection(DriverManager.java:187) at
com.momentum.orientdb.core.JdbcConnectionManager.getConnection(JdbcConnectionManager.java:87)
at
com.momentum.orientdb.core.JdbcConnectionManager.getConnection(JdbcConnectionManager.java:56)
at
com.momentum.orientdb.core.JdbcConnectionManager$getConnection.call(Unknown
Source) at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at
com.momentum.orientdb.core.test.JdbcConnectionManagerTest.testGetConnection(JdbcConnectionManagerTest.groovy:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Any idea why? How can I fix it?
UPDATE 1
It seems to me that it has to do with this library (from Google): concurrentlinkedhashmap-lru-1.4.1.jar.
But I searched the development computer's file system and found only the above mentioned version (1.4.1).
UPDATE 2 - Solution
After searching thoroughly I found that I had different version of concurrentlinkedhashmap-lru-xxxx.jar on my development machine's file system and somehow I "managed" to put two different versions in the build.
Meanwhile, I still get the same exceptions when using my library (which I've already tested) in order to establish a connection to OrientDb from within OpenFire since OpenFire uses another version of concurrentlinkedhashmap then the one being used by OrientDb (concurrentlinkedhashmap-lru-1.4.1.jar).
NoSuchMethodError happens because at runtime, Java tried to call a method on an object, and found it didn't exist, in particular:
com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.maximumWeightedCapacity(J)Lcom/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder;
Of course, you'd expect the code wouldn't compile if that was the case, so this almost always means you've built against a different version of the class than the one provided at runtime - it's usually a versioning issue.
So, you should figure out which library you're getting ConcurrentLinkedHashMap from, and compare this with the version being used at runtime (how are you deploying this? Is it running straight from IntelliJ?). You're likely to find that they have different versions, and you'll need to alter your version to match.
Please go to the below link and download the JAR file,
http://mvnrepository.com/artifact/com.googlecode.concurrentlinkedhashmap/concurrentlinkedhashmap-lru/1.4.2
The problem is with the version which you are trying, the correct version is 1.4.2.

Issues with accumulo 1.4.3 helloworld example on CDH4.3 QuickStart

I am trying to put together a accumulo/cloudera quickstart. Accumulo is running, but I am having problems attempting to execute samples, namely hellowworld.
It appears it is finding hadoop and not accumulo classes?
Following is execution and error messages. I appreciate your assistance!
./bin/accumulo org.apache.accumulo.examples.simple.helloworld.InsertWithOutputFormat "instance" localhost:2181 "username" "password" hellotable
Thread "org.apache.accumulo.examples.simple.helloworld.InsertWithOutputFormat" died nulljava.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.accumulo.start.Main$1.run(Main.java:89)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.JobContext, but class was expected
at org.apache.accumulo.core.util.ContextFactory.createTaskAttemptContext(ContextFactory.java:131)
at org.apache.accumulo.examples.simple.helloworld.InsertWithOutputFormat.run(InsertWithOutputFormat.java:56)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.accumulo.examples.simple.helloworld.InsertWithOutputFormat.main(InsertWithOutputFormat.java:76)
... 6 more
Problem solved by:
1) Using cdh4 accumulo-1.4.3 tar
2) adding additional users
3) ensuring write permissions on supporting jars

Java EE database Facade Connection Error

I am trying to connect to a database using Facade. I am using Netbeans 7.3.1 JDK 1.7 and JAva EE 7.
There is a Enterprise Application, a client application couple of beans and a class library. I mostly used the insert code method in netbeans to create the connections. I get the following error:
java.lang.reflect.InvocationTargetException
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.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
at org.glassfish.appclient.client.AppClientFacade.launch(AppClientFacade.java:183)
atorg.glassfish.appclient.client.AppClientGroupFacade.main(AppClientGroupFacade.java:65)
Caused by: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy299.count(Unknown Source)
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)
And
Caused by: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.javaee.test.db.Questions] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>com.javaee.test.db.Questions</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:173)
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:193)
at org.eclipse.persistence.internal.jpa.querydef.CommonAbstractCriteriaImpl.internalFrom(CommonAbstractCriteriaImpl.java:114)
at org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.from(AbstractQueryImpl.java:246)
I am not sure where exactly the problem might be so i didn't post any of the code. If you have a hint I can put down the code.
I had the same error last night. I think we are taking the same class! To fix it expand the ejb project -> Configuration Files -> persistence.xml
Under General, there is a checked checkbox "Include All Entity Classes in _ Module". I unchecked the box and then added each class manually. That took care of the exception. Hope this helps.

Jmockit NullPointerException with Junit

I'm trying to run a test that written by another programmer with JUnit in eclipse-indigo, and he is sure it works but when I try Jmockit there is a failure and I can't find a solution, yet.
I try to change jmockit.jar in classpath but not working. Do you have any idea about this problem?
Edit: When I use "ant test" in terminal there is no problem but if I click run as > JUnit test in my IDE I got this error.
Exception in thread "(Attach Listener)" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
Caused by: java.lang.NullPointerException
at mockit.internal.state.TestRun.getInstance(TestRun.java:40)
at mockit.internal.state.TestRun.mockFixture(TestRun.java:111)
at mockit.internal.ClassFile.createClassFileReader(ClassFile.java:33)
at mockit.internal.annotations.AnnotatedMockMethodCollector.collectMockMethods(AnnotatedMockMethodCollector.java:39)
at mockit.internal.RedefinitionEngine.<init>(RedefinitionEngine.java:86)
at mockit.internal.RedefinitionEngine.<init>(RedefinitionEngine.java:110)
at mockit.internal.startup.Startup.setUpInternalStartupMock(Startup.java:130)
at mockit.internal.startup.Startup.loadInternalStartupMocksForJUnitIntegration(Startup.java:112)
at mockit.internal.startup.Startup.initialize(Startup.java:79)
at mockit.internal.startup.Startup.agentmain(Startup.java:69)
... 6 more
Agent failed to start!
[WARN ][load ] agent library 'instrument' failed to init with result: 102
java.lang.RuntimeException: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at mockit.internal.startup.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:130)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:80)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:41)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:244)
at org.junit.runner.Runner.<clinit>(Runner.java:25)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:30)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:684)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:391)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:122)
at mockit.internal.startup.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:123)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:81)
... 16 more
java.lang.NoClassDefFoundError: org/junit/internal/runners/ErrorReportingRunner
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
As you stated in your comment you set an extra argument to the execution in ant.
Try setting
-javaagent:libtest/jmockit.jar
as a VM Argument (its the second input field on the Arguments tab) in the launch configuration for your junit test.
And make sure that the classpath is the same as in ant.
If you have the zip file of the distribution around, it should be pretty easy to just debug this and see why it's getting the NPE. Just add the source attachment as the zip file.

Categories

Resources