Home » Java » Enterprise Java

Enterprise Java

Mockito: Cannot instantiate @InjectMocks field: the type is an interface

Anyone who has used Mockito for mocking and stubbing Java classes, probably is familiar with the InjectMocks-annotation. Use this annotation on your class under test and Mockito will try to inject mocks either by constructor injection, setter injection, or property injection. This magic succeeds, it fails silently or a MockitoException is thrown. I’d like to explain what causes the “MockitoException: ...

Read More »

REST: Creating resources

java-interview-questions-answers

Resource creation is a common REST API operation. In this post we will see how single resource can be created. The client request Resources are typically created by sending a POST request to the parent collection resource. This creates a new subordinate resources with a newly generated id. For example, a POST request to /projects might be used to create ...

Read More »

Migrating Neo4j graph schemas in Kubernetes

When running enterprise applications with zero-downtime, we need to be able to perform database schema migrations without disrupting active users. This is important not just for relational databases, but also for graph databases such as Neo4J, which don’t enforce a schema on write. However, it still makes sense to refactor your graph and to keep your graph data model in ...

Read More »

RESTful services with HATEOAS: REST APIs and Hypermedia on JVM

java-interview-questions-answers

1. Introduction So far we have spent a fair amount of time talking about the role of the hypermedia and HATEOAS in the RESTful web services and APIs, glancing over different specifications and usability aspects. It sounded like supporting hypermedia and HATEOAS is not that difficult, just pick you favorites and you are good to go! As you may guess, ...

Read More »

How to restore a Neo4J backup on managed Kubernetes

In the following video I’ll explain how to restore backups of Neo4J instances to a fresh instance that runs in a managed Kubernetes environment. The backup contents will be taken from a persistent volume to which we previously wrote the backup. In this previous post you can see how to take backups in the first place. Try it yourself Again, ...

Read More »

How to backup Neo4J on managed Kubernetes

In the following video I’ll explain how to take full and incremental backups of Neo4J instances that run in a managed Kubernetes environment. We’ll use additional pods to take remote backups and store the backup data on persistent volumes which are provided by our managed environment. In case you’re wondering how to deploy Neo4J to managed Kubernetes, have a look ...

Read More »

Mock Void method with Mockito

Hey guys! After our previous blog on difference between thenReturn and thenAnswer mockito methods, we are back with yet another interesting blog on Mockito. Here, we shall discuss “How to Mock Void method with Mockito”. Let’s get started! When writing code, there is always at least one method that returns ‘void’, and at some point in time we need to ...

Read More »

Containerizing Spring Boot Applications with Buildpacks

In this article, we will see how to containerize the Spring Boot applications with Buildpacks. In one of the previous articles, I discussed Jib. Jib allows us to build any Java application as the docker image without Dockerfile. Now, starting with Spring Boot 2.3, we can directly containerize the Spring Boot application as a Docker image as Buildpacks support is ...

Read More »

REST: Managing Many-To-Many relations

java-interview-questions-answers

Introduction Managing relations between multiple resources can be an essential part of an RESTful API. In this post we will see how many-to-many relationships can be managed with a REST API. We use a simple user / group relation as an example. Let’s assume users and groups are two separate resources (e.g. /users and /groups) and we want to provide ...

Read More »