[wp_ad_camp_1] Sometimes you may not have access to a repository and may need to go around it. If your colleagues have local copies of jar files needed to compile a whole Maven project, you may simply replace the content of
Parse CSV file uploaded as MultipartFile using Apache Commons CSV
From MultiPartFile to Reader object [wp_ad_camp_5] The parse method only accepts a single java.io.Reader object and you may need to convert the MultipartFile object to a Reader object. The MultipartFile class has the getInputStream() whose return value can be passed
JavaScript scope in functions vs Java scope in methods
For years, JavaScript to me was a mere validation tool or script for web applications. I hated it. I avoided using it. This time JavaScript gets the same respect from me as Java does. If you plan to “own” (or master if you can) JavaScript and you are coming from blocked-scoped languages like Java, C#, C and C++, this is one of key things you need to keep in mind…
Three ways to mock an object using Mockito
If you’re new to Mockito and have only seen a sample or two on the Internet, you might find other examples create mock objects in different ways using the same framework. As a matter of fact, there are three (3) ways to create mock objects in Mockito.
Void methods and Mockito in Java
When we talk about unit tests, we think about input values and return values to/from methods. Returned values are checked against expected values as a way to verify behavior of codes. But how would you test codes that do not return any values? Essentially, we resort to stubbing out void methods. That is easy in Mockito!
Capture Argument To Method in Mockito
This post shows how to capture arguments our codes passed to a mock’s method. To do this, a method must accept reference types. Then, we use Mockito.verify() method. Then, pass an instance of ArgumentCaptor to the mock’s method. Capture Argument
Using JDK 9 with Eclipse Luna
JDK 9 works with Eclipse Mars [wp_ad_camp_5] First and foremost, Eclipse Luna does not work with JDK 9 because of JEP 220: Modular Run-Time Images. There is Eclipse Mars for that. Updating eclipse.ini to use JDK 9 JEP 220 changed
Find out if an object is a mock or spy in Mockito
The need for it [wp_ad_camp_5] Finding out if an object is a mock or spy in Mockito may not (or never) be part of your usual automated unit tests but in some cases (advanced usage of JUnit/Mockito) you may need
Mockito Spy
Spy Objects [wp_ad_camp_5] A Mockito spy allows us to create a spy object from a real object with similar behavior where each method can be stubbed out when needed. It is ideal for testing legacy code as you cannot invoke
Execute Tests in Order in JUnit 4
Using @FixMethodOrder [wp_ad_camp_5] To execute tests in a order in JUnit 4, annotate the class with @FixedMethodOrder passing one of enum MethodSorters items as parameter. Either one of the following can be used are parameter to @FixMethodOrder. MethodSorters.NAME_ASCENDING: This sorts