Description
byte array is returned in mock for JpaRepository method while entity is expected
Test is not compiling
To Reproduce
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open
Medical-Web-App project, develop-new branch
- Generate Unit tests for
NotificationService with @SpringBootApplication configuration
Expected behavior
Compiling tests should be generated
Actual behavior
byte array is set to be returned from JpaRepository<T, ID> getById method mock,
while UserRepository extends it with T = User
3 similar tests are not compiling.
Screenshots, logs
@Repository
public interface UserRepository extends JpaRepository<User, Long>
public interface JpaRepository<T, ID>
@Test
@DisplayName("getAllNotifications: user = userRepository.getById(user_id) : True -> ThrowClassCastException")
public void testGetAllNotifications_ThrowClassCastException() {
byte[] byteArray = {};
(when(userRepositoryMock.getById(any()))).thenReturn(byteArray);
/* This test fails because method [com.app.medicalwebapp.services.NotificationService.getAllNotifications] produces [java.lang.ClassCastException: class [B cannot be cast to class com.app.medicalwebapp.model.User ([B is in module java.base of loader 'bootstrap'; com.app.medicalwebapp.model.User is in unnamed module of loader org.utbot.instrumentation.process.HandlerClassesLoader @10eb7238)]
com.app.medicalwebapp.repositories.UserRepository$MockitoMock$YIpF9DQ3.getById(Unknown Source)
com.app.medicalwebapp.repositories.UserRepository$MockitoMock$YIpF9DQ3.getById(Unknown Source)
com.app.medicalwebapp.services.NotificationService.getAllNotifications(NotificationService.java:54) */
notificationService.getAllNotifications(null);
}
Environment
IntelliJ IDEA version - Ultimate 2023.2
Project - Maven
JDK - 11
Description
byte array is returned in mock for JpaRepository method while entity is expected
Test is not compiling
To Reproduce
Medical-Web-Appproject, develop-new branchNotificationServicewith @SpringBootApplication configurationExpected behavior
Compiling tests should be generated
Actual behavior
byte array is set to be returned from JpaRepository<T, ID> getById method mock,
while UserRepository extends it with T = User
3 similar tests are not compiling.
Screenshots, logs
Environment
IntelliJ IDEA version - Ultimate 2023.2
Project - Maven
JDK - 11