Posts

Showing posts from May, 2024

Spring Boot 3 Astra DB CRUD Example

Image
In this section,  we will learn how to build REST CRUD APIs with Spring Boot , and Astra DB . Astra DB DataStax Astra DB is a cloud-native, scalable Database-as-a-Service built on Apache Cassandra . Create a Database First, Sign into the datastax at https://astra.datastax.com . Then click on the "Databases" button. You will be taken to a page like the below image, then click on the " Create Database " button. Then enter Database name , Provider , and, Region , then click on the " Create Database " button. Now, You can see "Your database is initializing..." like the below image. You will be taken to a page like the below image. Copy " Database ID " and " region name " and keep them for future purposes. Generate Application Token Mocking Then click on " Tokens " button. You will be taken to a page like the below image, Then select role, for demo purpose here we selected role " Administrator User ". Then clic...

Spring Boot Mockito - @Mock & @InjectMocks Example

Image
In this tutorial, we will learn about the  @Mock and @InjectMocks  annotation of Mockito framework, and at the end, we will see how the Spring Boot application can utilize these  annotation for unit testing with JUnit 5 . Therefore, read the post till the end. Mockito Mocking framework Mockito is used for efficient unit testing in Java-based applications. It is used in conjunction with  testing framework JUnit. We construct a mock with Mockito, instruct it on what to do when certain methods are called on it, and then utilize the mock instance rather than the real one in our test. @Mock A mock object is created for a specified class or interface using the @Mock annotation. It gives Mockito instructions on how to make a proxy object that behaves just like the original object. We can mimic the actions of dependencies without calling their real methods by using @Mock . Here’s an example of using @Mock : @ExtendWith(MockitoExtension. class ) public class UserSe...