Running JUnit tests in IntelliJ, getting: java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull - intellij-idea

I'm trying to run unit tests in IntelliJ, and I'm getting the stack trace:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object;
at org.junit.platform.launcher.core.DefaultLauncher.registerTestExecutionListeners(DefaultLauncher.java:71)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:44)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Googling the error message doesn't help - all of the hits I get back have to do with Gradle dependencies, but I'm using Maven (and I've triple-checked my dependencies). Here is my pom:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.0-M3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
And what's frustrating is that this does actually work in a different project, so I'm not sure what's gone wrong here.

Never mind, I figured it out - in case anybody else has the same problem: It turned out that my unit test was importing org.junit.Test, rather than org.junit.jupiter.api.Test, but I didn't declare a dependency on junit-vintage in my pom.xml. The solution was to either explicitly declare the correct version of junit-vintage in my pom (4.12.0-M3 in my case), or switch my unit tests over to import org.junit.jupiter.api.Test.

Related

java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jdk8.Jdk8Module not found

==============
When I run my API automation test I get the below error. But able to run the test completely without any issue when the cucumber-java
version is 7.2.3 How do I resolve this issue?
Note few other details below. Using JDK 11 JRE 1.8
==============
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.3.4</version>
</dependency>
Note the Trace and pom.xml below.
==============
[Trace][1]
java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jdk8.Jdk8Module not found
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1105)
at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1089)
at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1139)
at io.restassured.path.json.mapper.factory.DefaultJackson2ObjectMapperFactory.create(DefaultJackson2ObjectMapperFactory.java:29)
at io.restassured.path.json.mapper.factory.DefaultJackson2ObjectMapperFactory.create(DefaultJackson2ObjectMapperFactory.java:27)
at io.restassured.common.mapper.factory.ObjectMapperFactory$create.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
at io.restassured.internal.mapping.Jackson2Mapper.createJackson2ObjectMapper(Jackson2Mapper.groovy:44)
at io.restassured.internal.mapping.Jackson2Mapper.this$2$createJackson2ObjectMapper(Jackson2Mapper.groovy)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:198)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:62)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:50)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194)
at io.restassured.internal.mapping.Jackson2Mapper.serialize(Jackson2Mapper.groovy:50)
at io.restassured.internal.mapping.Jackson2Mapper.serialize(Jackson2Mapper.groovy)
at io.restassured.mapper.ObjectMapper$serialize.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
at io.restassured.internal.mapping.ObjectMapping.serializeWithJackson2(ObjectMapping.groovy:217)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:153)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:240)
at io.restassured.internal.mapping.ObjectMapping.serialize(ObjectMapping.groovy:154)
at io.restassured.internal.mapping.ObjectMapping$serialize.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at io.restassured.internal.RequestSpecificationImpl.body(RequestSpecificationImpl.groovy:756)
**POM.xml**
==========================================================================================================================================================
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<!-- <scope>test</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.1.0</version>
<!-- <scope>test</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.3.4</version>
<!-- <scope>test</scope> -->
</dependency>
</dependencies>
I had same issue with "testImplementation 'io.cucumber:cucumber-java8:7.3.3'" (gradle).
I changed to "testImplementation 'io.cucumber:cucumber-java8:7.0.0'" and when I changed it and ran again test then I got a correct error message about the real problem that was "Unrecognized field 'programId'" (for example) and then I can fix the problem (that was a missing field in my class).
I installed Jackson JDK8 repository in my pom.xml file and it fixed this problem:
https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8

how to resolve java.lang.NoClassDefFoundError: org/openqa/selenium/remote/AbstractDriverOptions?

I am trying to run a basic geb program on my new laptop and I am continuously getting this error. Below is the error and pom I am using. Please help me if I am doing something wrong.
POM:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.0-M3-groovy-3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-core</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0-alpha-6</version>
</dependency>
Error:
Java HotSpot(TM) 64-Bit Server VM warning: Archived non-system classes
are disabled because the java.system.class.loader property is
specified (value = "groovy.lang.GroovyClassLoader"). To use archived
non-system classes, this property must not be set Caught:
java.lang.NoClassDefFoundError:
org/openqa/selenium/remote/AbstractDriverOptions
java.lang.NoClassDefFoundError:
org/openqa/selenium/remote/AbstractDriverOptions at
org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.lambda$compute$0(ConcurrentLinkedHashMap.java:788)
at
org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.compute(ConcurrentLinkedHashMap.java:800)
at
org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap.computeIfAbsent(ConcurrentLinkedHashMap.java:777)
at GebExample1.run(GebExample1.groovy:5) at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: java.lang.ClassNotFoundException:
org.openqa.selenium.remote.AbstractDriverOptions ... 7 more

Mock Apache ActiveMq with amqp protocol

We are using solace as the Messaging system in our application and while writing the unit test classes (using JUNIT )for listners i have to start the solcae in my local.
Instead i was trying to mock the broker (apache ActiveMq) to use amqp protocl and send messages to the listeners.
https://github.com/apache/activemq/blob/activemq-5.15.x/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/AmqpTransformerTest.java
But when i try to build the maven project i see the error
package org.apache.activemq.transport.amqp.client does not exist.
I have added the below dependencies but i still facing the same issue. Please suggest
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.15.12</version>
<!-- <scope>test</scope> -->
</dependency>
<!-- Testing Dependencies -->
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>0.51.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-jaas</artifactId>
<version>5.15.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.15.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-http</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-mqtt</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-leveldb-store</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-junit</artifactId>
<version>5.15.12</version>
<scope>test</scope>
</dependency>
I am not able to resolve the below compilation issues.
org.apache.activemq.transport.amqp.client can not be resolved since the dependecy for this package is not found,But i have added the above dependencies in the maven project.
import org.apache.activemq.transport.amqp.client.AmqpClient;
import org.apache.activemq.transport.amqp.client.AmqpConnection;
import org.apache.activemq.transport.amqp.client.AmqpMessage;
import org.apache.activemq.transport.amqp.client.AmqpSender;
import org.apache.activemq.transport.amqp.client.AmqpSession;
Please suggest.
thank you experts.
Not entirely clear what your test is doing but the classes it can't find are those of the AMQP test client that is implemented in the ActiveMQ 5.x AMQP module's test jar so you definitely won't find them with the dependencies you have there.
The AMQP test client in the ActiveMQ broker is not meant for general use by anyone as is was built specifically to test the AMQP stack in the broker. If you remove the usage of that from your tests you should have better luck.

Trying to test static method using powermock

I'm trying to do a test on a code which requires to mock some static methods. I found in the that using powermock, I will be able to mock the static methods being used.
I tried adding these dependencies power mock module-junit4 dependency as well as powermock-api-mockito and setting their versions explicitly to 1.7.1:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
#RunWith(PowerMockRunner.class)
#PrepareForTest({SystemParameterQueryHelper.class})
public class VccTemplateConvertorTest{}
Exception in thread "main" java.lang.NoSuchMethodError: org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getFrameworkReporterFactory()Lorg/powermock/core/reporter/MockingFrameworkReporterFactory;
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getMockingFrameworkReporter(JUnit4TestSuiteChunkerImpl.java:140)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:119)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
You are using a fairly dated version of PowerMock. Looking at the documentation:
PowerMock version 2.0.0 and upper has support of Mockito 2. PowerMock version 1.7.0 and upper has experimental support of Mockito 2.
In this case emphasis is on experimental.
I would suggest to try and update the PowerMock version you're using. This is my current configuration:
<properties>
...
<version.mockito>2.23.4</version.mockito>
<version.powermock>2.0.2</version.powermock>
</properties>
<dependencies>
...
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${version.mockito}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${version.powermock}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${version.powermock}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${version.powermock}</version>
<scope>test</scope>
</dependency>
</dependencies>

com.google.inject.ProvisionException: Unable to provision

I have created simple seedstack web project through guideline mentioned on http://seedstack.org/docs/basics/
Undertow is also started with seedstack:run.
However, while accessing "hello" resource undertow throws below exception:
ERROR 2018-07-25 21:37:34,468 XNIO-1 task-2 io.undertow.request
UT005023: Exception handling request to
/api/seed-w20/application/configuration
null returned by binding at
org.seedstack.w20.internal.W20Module.configure(W20Module.java:51) (via
modules: com.google.inject.util.Modules$OverrideModule ->
io.nuun.kernel.core.internal.injection.KernelGuiceModuleInternal ->
org.seedstack.w20.internal.W20Module) but the 3rd parameter of
org.seedstack.w20.internal.FragmentManagerImpl.(FragmentManagerImpl.java:32)
is not #Nullable at
org.seedstack.w20.internal.W20Module.configure(W20Module.java:51) (via
modules: com.google.inject.util.Modules$OverrideModule ->
io.nuun.kernel.core.internal.injection.KernelGuiceModuleInternal ->
org.seedstack.w20.internal.W20Module) while locating
org.seedstack.w20.internal.ConfiguredApplication
for the 3rd parameter of org.seedstack.w20.internal.FragmentManagerImpl.(FragmentManagerImpl.java:32)
while locating org.seedstack.w20.internal.FragmentManagerImpl while
locating org.seedstack.w20.FragmentManager
for field at org.seedstack.w20.internal.rest.application.ApplicationConfigurationResource.fragmentManager(ApplicationConfigurationResource.java:38)
while locating
org.seedstack.w20.internal.rest.application.ApplicationConfigurationResource
Any help please?
This is a bug introduced recently into the w20-bridge, which occurs when no w20.app.json configuration file is present.
You can workaround it by creating an empty-object w20.app.json file at the root of the classpath:
{}
You can also update the version of all w20-bridge dependencies to 3.2.4 which has a fix for it. This can be done by using the dependencyManagement section of your POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seedstack</groupId>
<artifactId>seedstack-bom</artifactId>
<version>18.4.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-bootstrap-3</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-business-theme</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-components</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-rest</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-specs</artifactId>
<version>3.2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
This fix will be included in the upcoming SeedStack 18.7.