Capture parameters with Mockito ArgumentCaptor

While creating test methods for a class, you might want to access some arguments passed to a specific method. Luckily, you can capture parameters with Mockito ArgumentCaptor. It is especially useful when you can’t access the argument from the outside of the method.

Let’s check it out on a basic example. Let’s say we have a class called Product and we create stock codes for these objects before saving them to the database. So we’ve created a method called generateProductCodeAndSave() which generates the code then passes the product to another method in order to insert it to the database.

Continue reading

Regular Expressions In Java

Regular Expressions are a key element in programming. There are times that you can save a lot of time with a simple Regex. As a lot of my teachers said while I was studying, it is an important thing that you should be familiar with. Regular Expressions are designed to help you define a pattern to search for in a String. You can use it to check whether a parameter is valid or to find a specific pattern of text in a large file. In Java, you’ll be using java.util.regex package to implement Regex logics to your project.

Continue reading