how do I set up mocking using mockito in netbeans in a java maven project? - maven

how to I set up mocking using mockito in netbeans in a java maven project? I understand mocking but cant find mockito files in the maven repo
import static org.mockito.Mockito.*;

If you're manually setting up your pom.xml in NetBeans, I think this is what you want:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
I'm using Mockito in a Java project right now, but fair warning, I'm using Ivy for dependency management, not Maven.
http://mvnrepository.com/artifact/org.mockito/mockito-core/1.10.19

Related

Maven cannot find dependency from imported jar file

I have a service library that contains the Spring Starter Web dependency, e.g.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I name this service library "spring-boot-starter-service" and intend to use it in another API project, and this API project does not contain Spring Starter Web.
After making changes to this service library, I use maven install to create a jar file (and I can see that the code changes were reflected) in classes under /target directory
I use the following dependency in the API project, hoping to import the service library and its Spring Starter Web
<dependency>
<groupId>com.example.spring</groupId>
<artifactId>spring-boot-starter-service</artifactId>
<scope>system</scope>
<version>1.0.40</version>
<systemPath>
/Users/xxxxxx/IdeaProjects/spring-boot-starter-service/target/spring-boot-starter-services-1.0.40-SNAPSHOT.jar
</systemPath>
</dependency>
Unfortunately, I was not able to successfully import the Spring Starter Web (as well as other dependencies in the service library) using the above dependency in pom.xml
Anyone knows what I missed? Thanks

How to include kotlin.test properly via Maven?

Our team is making first steps into Kotlin and I'm about to to migrate a test. I tried a first example from mockk (https://github.com/mockk/mockk/blob/master/mockk/common/src/test/kotlin/io/mockk/it/InjectMocksTest.kt). For some reason it seems I'm not able to use kotlin.test although I have added it via maven. Do I have to include any other modules? Or do I have to change something else?
(the mockk example uses Gradle so it doesn't help me).
This is what I'd like to use in my Kotlin test file but it which can't be found (at least not the packages I need):
(Restarting Intellij doesn't help, neither running mvn seperately)
This is my maven dependancy (Intellij shows now error):
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version> <!-- kotlin.version == 1.7.0 -->
<scope>test</scope>
</dependency>
The solution was (see hotkey's answer) to add the following maven dependency:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
You need to add a dependency on one of kotlin-test-junit (for JUnit 4), kotlin-test-junit5 (for JUnit Jupiter), or kotlin-test-testng (for TestNG), depending on what test framework you are using.
The artifact kotlin-test contains only the common code, asserters and other stuff that can be reused across the frameworks.
The kotlin.test annotations like #Test or #BeforeTest are shipped in the test-framework-specific artifacts as typealiases to the actual annotations types of the test frameworks.

Issue running Kogito DMN TrafficViolationTest in my junit

I imported dmn-quarkus-example project into eclipse. the project compiles and shows no errors. when I run mvn clean quarkus:dev, I was able to test the rest endpoint through postman and it works.
but my junit in my eclipse fails with 404.
I read few blogs and updated my application.properties file with the following, still no luck
quarkus.http.port=9090
%dev.quarkus.http.port=9191
quarkus.http.test-port=8181
the other thing I had to do to get my junit working is added the following dependencies in the pom.xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
it working still not able to understand why?
it started working after
mvn clean install and tried maven update on eclipse.....
it random....
This sounds like Eclipse is not configured properly, in general; based on the provided information not possible to even say if it's something related to Quarkus, or just a general Eclipse configuration issue.
Moreover, tested locally with Eclipse 2019-12 and no special configuration and no special plugin, running the JUnit test works out of the box correctly, in the example screenshot below running the unit test of the REST interface for Kogito on Quarkus example:
Please ensure you have no Maven exclusion in your Eclipse configuration, and that Eclipse is allowing to run the necessary Maven phases with M2Eclipse (like running any Maven project with Eclipse)

How to include custom type converter using Maven and Grails

I am working on a Grails project that needs to compile with both Grails and Maven. Everything worked great except for my GSON converter I added (using the grails-gson plugin). Now I get the following when I run mvn install.
unable to resolve class grails.plugin.gson.converters.GSON
Anyone know how to overcome this
Plugin has to be added as a dependency in pom.xml too
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>gson</artifactId>
<version>1.1.4</version>
<type>zip</type>
</dependency>
Mavenized grails project refer pom file for all dependencies (including plugin dependencies).

Maven/Spring multi module project logging

I am trying to convert a huge maven/spring webapp to a multi module project.
Logging is implemented with this method (http://docs.spring.io/spring/docs/4.0.2.RELEASE/spring-framework-reference/htmlsingle/#overview-logging-slf4j) in the huge project. What is the correct way to do this in a maven multi module project? Is it necessary to define this in every pom.xml or only in my main pom.xml.
My main pom.xml defines this dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Is it possibly to exclude commons-logging on this dependency?
Update:
The project structure:
Parent Project:
Project A: jar
Project B: jar
Project C: war
Project D: war
All projects using parts of the Spring framework. I am using SLF4J for logging. What is the correct way for including SLF4J in this project setup with maven?
It should only be necessary to exclude commons-logging from "spring-core", but some third-party libraries also include it, so that isn't always enough. You could try using Spring Boot starters to build up your Spring dependencies (even if you aren't using other Boot features), since the default logging system is logback and commons-logging has been carefully excluded.

Resources