JUnit: Misuse Of any() Matchers

For writing unit tests in JUnit, Mockito provides argument matchers that you can use to mock the arguments in a given() or when() statement. Among the matchers provided, the any() matcher lets you pass any argument to the method, ensuring that the test cases passes with any input. When any() matcher is used extensively, out of laziness of specifying the parameters, there are high chances that the test case is not really testing anything or it passes even with a wrong input....

July 23, 2021 · 2 min · Me

Internals Of Java Parallel Streams

The Stream API was introduced in Java 8 as an efficient way to operate on collections. Parallel streams were introduced as a part of it for parallel processing and to make the application run faster. Though parallel streams are supposed to increase your application performance by splitting the task between multiple threads and completing them faster than sequential execution, there are chances parallel streams can sometimes slow down the entire application....

June 3, 2021 · 3 min · Me

JPA EntityGraphs: A Solution to N+1 Query Problem

The N+1 query problem is said to occur when an ORM, like hibernate, executes 1 query to retrieve the parent entity and N queries to retrieve the child entities. As the number of entities in the database increases, the queries being executed separately can easily affect the performance of the application. This article will demonstrate how N+1 queries occur and their solution through an example in spring boot. The N+1 Query Problem Consider a Content Management System that stores a list of articles per publication....

March 11, 2021 · 3 min · Me

Mutables in a Set: Python vs Java

Set is a built-in data type present in both Python and Java but both of these languages handles the elements in a set differently. Though the underlying implementation of set is the same in both languages, Java lets you add mutable objects, such as a list to a set, whereas Python does not. Python Restricts Adding A List To A Set In python, when you try to add an entire list to a set, compiler throws an error:...

January 14, 2021 · 4 min · Me

Functional Programming In Java

If you have ever used Streams and Optionals in Java, you must have come across lambda expressions and functional interfaces. But how exactly are lambda expressions tied to functional interfaces? This article will talk about functional programming in Java and how Streams and Optionals make use of functional interfaces. What is a functional interface? An interface that has only one abstract method (unimplemented method) can qualify to be a functional interface....

October 12, 2020 · 3 min · Me

Using Mixins In Java

Often we like to attach abilities to our class but it is mostly done as a delegate and not as a mixin in Java. We will explore in this blog on implementing mixins in Java using first class collections. First class collection means a collective object is given domain importance. It has to behave as a collection as well as a domain object. Rule 4: Object Calisthenics by William Durand...

June 20, 2020 · 3 min · Me