-
Notifications
You must be signed in to change notification settings - Fork 45
Closed as not planned
Closed as not planned
Copy link
Labels
comp-springIssue is related to Spring projects supportIssue is related to Spring projects supportcomp-symbolic-engineIssue is related to the symbolic execution engineIssue is related to the symbolic execution enginectg-bugIssue is a bugIssue is a bugstatus-duplicateThis issue or pull request already existsThis issue or pull request already exists
Milestone
Description
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>
T getById(ID 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
Metadata
Metadata
Assignees
Labels
comp-springIssue is related to Spring projects supportIssue is related to Spring projects supportcomp-symbolic-engineIssue is related to the symbolic execution engineIssue is related to the symbolic execution enginectg-bugIssue is a bugIssue is a bugstatus-duplicateThis issue or pull request already existsThis issue or pull request already exists
Type
Projects
Status
Done