How to use Mockito in a simple java project without Maven and Gradle - mockito

Can we use the Mockito framework in a simple Java project without maven and Gradle? I saw many youtube videos but all of them use either Maven or Gradle. I do not understand why they do not use it in a simple java project.

Can we use the Mockito framework in a simple Java project without maven and Gradle? I saw many youtube videos but all of them use either Maven or Gradle. I do not understand why they do not use it in a simple java project.
Yes. People do this every day as this. It's the 'normal' way to use Mockito.
Here is an example project that uses an older version of mockito, but the concept is still the same: https://java2blog.com/mockito-junit/

Related

Does Kotlin provide any additional security?

When we develop an Android app in Java, we have the option to obfuscate the code and built the APK.
Is there any advance feature in Kotlin to do the same?
Code obfuscation is neither a Java feature nor a Kotlin one.
Since Kotlin is compiled to the same bytecode as Java, you can use the same tools (for example Proguard). Those tools obfuscate the bytecode and not the sources, I think you misunderstood that.
Suppose you're running gradle build on your Kotlin Android project. Then you'll find following tasks being run:
:app:compileReleaseKotlin
:app:compileReleaseJavaWithJavac
:app:copyReleaseKotlinClasses
:app:compileReleaseSources
:app:transformResourcesWithMergeJavaResForRelease
:app:transformClassesAndResourcesWithProguardForRelease
:app:transformClassesWithDexForRelease
As you can see Kotlin sources are compiled first, then the Java sources. This results in only one collection of Java classes which are processed with Proguard; just at the end. There is no differentiation between Java and Kotlin anymore at this step.

How do I incorporate robolectric into an existing Android Studio project?

The android ecosystem, particularly Android Studio, has been changing a lot over the last year or so. I've found many sets of instructions for incorporating robolectric into a project, written at many points during that period. And I haven't yet made one work on my project.
Which commands do I need to add to my app build.gradle?
Which commands do I need to add to my project build.gradle?
Do I need to use Junit 4 in order to use robolectric?
Are there other libraries needed? What versions?
Do my tests need to be in src/test rather than src/androidTest?
What other information do I need?
I'm using:
Android Studio 1.1.0
gradle 1.1.0
junit 4.12
hamcrest-library 1.3
mockito-core 1.10.19
dexmaker 1.0
dexmaker-mockito 1.0
I suppose that you expect to run tests from Android Studio in addition to be able run them from command line only.
I think the most up to date example of usage Robolectric with latest android gradle plugin is this.
One note: I see dependencies to dexmaker and dexmaker-mockito that gives me assumption that you use Instrumental tests instead of plain junit tests.
It is quite dumb answer with just reference but I can not be more specific until you have specific issue

How to give reference to Platform SDK from Groovy IntelliJ project?

I am new to Groovy and InteliJ. I need to create a project with Groovy script. It is dependent on Axeda platform SDK from here
Using intellij, I have created a New project - Groovy Module. Used project SDK as Java JDK 1.7
I need to import some classes from Axeda SDK now. How can I give the reference to this SDK now?
You will need to add the relevant .jar files from the SDK as module dependencies.
Assuming you will need more than one .jar file and may need to reuse it for other project, you might want to create a global library for the SDK as described here. Then you can use this library for any project which needs the SDK.

Is it possible to use Groovy with Spring Roo?

Is there a way to use Groovy in a Spring Roo project?
I'm using STS (Eclipse) and I'd like to be able to write some code in Groovy
and use Spock framework for unit testing.
But it seems, there are some problems with AspectJ and Groovy intergation.
Has anyone successfully used Roo and Groovy together?
Thanks.
Unfortunately you cannot mix those two languages in the same project.
When you installed Groovy-Eclipse you install a patched eclipse java compiler that is then able to build java and groovy code. When you install AspectJ you get an alternative compiler that can build java and AspectJ source (your Roo projects are AspectJ projects).
In a Roo project it will be using the AspectJ compiler and not the patched java compiler installed via Groovy-Eclipse, so it won't understand groovy code.
The proper solution is to patch AspectJ in the same way Groovy-Eclipse is done so AspectJ can build groovy+java+aspectj but we still haven't gotten around to that.
The easiest thing for you to do is split the tests into a separate Groovy test project that depends on the Roo project containing the main sources. That should work.

How to use groovy inside a Eclipse RCP project?

I have a Eclipse RCP project, and I want to use Groovy inside it. what I try to do is :
1) add "Groovy Nature"
2) create Groovy files under the "src" folder
3) call the groovy class from the "View"'s createPartControl() method.
But I got the “java.lang.ClassNotFoundException: fly.island.jface.Test”, and the "fly.island.jface.Test" is a groovy class.
What should I do to use groovy inside the Eclipse RCP project?
Use the latest version of Groovy-Eclipse 2.1.0 (or one of the dev builds). Update site is here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
Additionally, there are some steps you need to do to compile the groovy plugins when you the PDE build. I'd recommend reading:
http://contraptionsforprogramming.blogspot.com/2010/08/groovy-pde-redux.html
Essentially, you need to include the org.codehaus.groovy bundle in your rcp app, and then you need to make some changes to the build.properties file of your Groovy plugins (explained in detail on the blog post).
Are you using the latest Version of eclipse (3.6) and the groovy plugin? I recall occasionally having problems with the Java and Groovy compilers not finding each other's classes (in the first version of the plugin, it took a lot of fiddling and luck to get it to work at all). The most recent version seems to be pretty good in that regard, though I've been using it only for a few days myself.

Resources