Spring Boot Junit5: How to fix receiving 405 when testing GETMapping

Im working on a Travel Blog project in Spring Boot and Im trying to do TDD. Im in the process of writing the tests for my BlogEntryController class which handles adding, deleting etc of BlogEntries. BlogEntryControllerTest package com.example.server; import com.example.server.controller.BlogEntryController; import com.example.server.models.user.BlogEntry; import com.example.server.repositories.BlogEntryRepository; import com.example.server.services.BlogEntryService; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import… Read More Spring Boot Junit5: How to fix receiving 405 when testing GETMapping

Maven does not find my test files that ends with "Test"?

I added the jupiter, mockito and jupiter engine to the pom.xml file as you can see in the following clipboard: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt; <modelVersion>4.0.0</modelVersion> <groupId>com.example.myapp</groupId> <artifactId>testingit</artifactId> <version>1.0</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.9.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> <version>4.6.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.4.0</version> </dependency> </dependencies> <build> <plugins> <plugin>… Read More Maven does not find my test files that ends with "Test"?

Unable to run any Junit4 tests – InvalidTestClassError: Invalid test class

I am trying to run Junit4 tests and I am unable to run it. I have the following dependency installed <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> My test class looks like this package model.validators; import org.junit.Assert; import org.junit.Test; import java.util.Arrays; import java.util.List; class UserValidatorTest { @Test public void shouldReturnTrueForValidPhoneNumbers() { List<String> phoneNumbers = Arrays.asList( "9876543210",… Read More Unable to run any Junit4 tests – InvalidTestClassError: Invalid test class

How to check the type returned by ResponseEntity<?>

I have a Spring REST Api that adds users to a db: @PostMapping(value = "/adduser", produces = "application/json") public ResponseEntity<?> addUser(@RequestBody User user){…} Now I’m creating it’s unit test where I placed this code: ResponseEntity<?> user = userController.addUser(userTest); The addUser method will either return a ResponseEntity<User> containing the json of the added user (when it’s… Read More How to check the type returned by ResponseEntity<?>

Auto static import in IntelliJ

In below piece of code I have used Class name to import static methods in IntelliJ IDEA 2022 Community Edition BDDMockito.given(employeeRepository.findByEmail(employee.getEmail())) .willReturn(Optional.empty()); BDDMockito.given(employeeRepository.save(employee)).willReturn(employee); Is there any way or keyboard shortcut that can remove the class name and use static import like this: import static org.mockito.BDDMockito.given; given(employeeRepository.findByEmail(employee.getEmail())) .willReturn(Optional.empty()); given(employeeRepository.save(employee)).willReturn(employee); I googled lot and read IntelliJ articles… Read More Auto static import in IntelliJ