Diffblue cover was unable to write a spring test

Diffblue cover was unable to write a spring test. How to fix that problem.
I tried everything.

Hi @pindarew

Thank you for reaching out - I’m sorry to hear you haven’t been able to get a Spring test from Cover as of yet.
We can certainly have a look into why you aren’t getting Spring tests. After every run of Cover we produce a log file containing output codes with reasons why Cover was unable to write a test. To do this are you able to upload a support log file for us to investigate?
(Instructions on how to obtain log files for; CLI, IntelliJ plugin)

Kind regards,

Jane @ Diffblue

19:20:13.593 [INFO] [Checking] Diffblue Cover IntelliJ Plugin 2023.07.02-2022.3
19:20:25.105 [INFO] [Checking] Detected classpath from module
19:20:25.327 [INFO] [Checking] Detected test framework: JUnit 4.13.2
19:20:25.328 [INFO] [Checking] Detected build system: Maven
19:20:25.375 [INFO] [Checking] Detected test framework: JUnit Jupiter 5.9.3
19:20:25.416 [INFO] [Checking] Detected JUnit Jupiter Engine version 5.9.3
19:20:25.458 [INFO] [Checking] Detected JUnit Jupiter Params version 5.9.3
19:20:25.503 [INFO] [Checking] Detected JUnit Vintage Engine version 5.9.3
19:20:25.585 [INFO] [Checking] Detected Java version 17.0.5
19:20:25.610 [INFO] [Checking] Detected Mockito version 5.3.1
19:20:26.258 [INFO] [Checking] Detected working directory G:\Programing\JourneyMate from module
19:20:26.260 [INFO] [Checking] User-specified testing framework: one of JUnit 4.7-4.12 or JUnit 4.13
19:20:26.260 [INFO] [Checking] Selected test output directory: G:\Programing\JourneyMate\src\test\java
19:20:26.262 [INFO] [Checking] Selected test framework: JUnit
19:20:26.263 [INFO] [Checking] Detected Spring Core version 6.0.10
19:20:26.263 [INFO] [Checking] Detected Spring Web version 6.0.10
19:20:26.263 [INFO] [Checking] Detected Spring Test version 6.0.10
19:20:26.264 [INFO] [Checking] Detected Spring Security Web version 6.1.1
19:20:26.264 [INFO] [Checking] Detected Spring Boot version 3.1.1
19:20:26.264 [INFO] [Checking] Detected Spring Boot Test version 3.1.1
19:20:26.315 [INFO] [Checking] Detected Hamcrest 2 version 2.2
19:20:26.457 [INFO] [Checking] Detected JVM architecture: 64-Bit
19:20:26.457 [INFO] [Checking] Detected language level 17 - Sealed types, always-strict floating-point semantics from module
19:20:26.503 [INFO] [Checking] Selected Java language compliance level: 17
19:20:26.507 [INFO] [Reporting]
19:20:26.507 [INFO] [Reporting] Environment summary:
19:20:26.507 [INFO] [Reporting] --------------------
19:20:26.507 [INFO] [Reporting] Build system Maven SUCCESS
19:20:26.507 [INFO] [Reporting] Java version 17.0.5 SUCCESS
19:20:26.507 [INFO] [Reporting] Mocking Framework Mockito 5.3.1 SUCCESS
19:20:26.507 [INFO] [Reporting] Testing framework JUnit 4.13 SUCCESS
19:20:26.508 [INFO] [Reporting] Hamcrest Hamcrest 2 2.2 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Core 6.0.10 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Boot 3.1.1 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Boot Test 3.1.1 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Web 6.0.10 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Security Web 6.1.1 SUCCESS
19:20:26.508 [INFO] [Reporting] Spring Test 6.0.10 SUCCESS
19:20:26.508 [INFO] [Reporting]
19:20:26.508 [INFO] [Reporting] Environment check status: SUCCESS
= Creating tests for ‘bg.journey.demo.api.v1.UserController.getMyProfile:(Lbg/journey/demo/security/UserPrincipal;)Lorg/springframework/http/ResponseEntity;’ using ‘SCo[SB] (sp, !fnm, df, !ris)’

19:21:20.373 [INFO] [Creating]

= Creating tests for ‘bg.journey.demo.api.v1.UserController.getMyProfile:(Lbg/journey/demo/security/UserPrincipal;)Lorg/springframework/http/ResponseEntity;’ using ‘SCo[SB] (sp, !fnm, df, !ris)’

19:21:26.879 [INFO] [Creating]

= Creating tests for ‘bg.journey.demo.api.v1.UserController.getMyProfile:(Lbg/journey/demo/security/UserPrincipal;)Lorg/springframework/http/ResponseEntity;’ using ‘SiM (!sp, !fnm, df, !ris)’

19:21:59.048 [INFO] [Creating] Created 3+3 tests and partial tests via ‘SiM (!sp, !fnm, df, !ris)’, 3/3, returning all 6
19:21:59.054 [INFO] [Creating]

= Creating skeleton for ‘bg.journey.demo.api.v1.UserController.getMyProfile:(Lbg/journey/demo/security/UserPrincipal;)Lorg/springframework/http/ResponseEntity;’ using ‘SCo[SB] (sp, !fnm, df, !ris)’

19:22:17.028 [INFO] [Creating] [1/1] bg.journey.demo.api.v1.UserController.getMyProfile
19:22:17.028 [INFO] [Creating] [1/1] Tests created: 3
19:22:17.028 [INFO] [Creating] [1/1] Partial tests created: 3
19:22:17.028 [INFO] [Creating] [1/1] Reasons for partial tests:
19:22:17.028 [INFO] [Creating] [1/1] R013: No inputs found that don’t throw a trivial exception
19:22:17.028 [INFO] [Creating] [1/1] Diffblue Cover tried to run the arrange/act section, but the test threw
19:22:17.028 [INFO] [Creating] [1/1] bg.journey.demo.exception.NotAuthorizedException: You are not authorized to view this resource
19:22:17.028 [INFO] [Creating] [1/1] at bg.journey.demo.service.UserService.getMyProfile(UserService.java:35)
19:22:17.029 [INFO] [Creating] [1/1] at bg.journey.demo.api.v1.UserController.getMyProfile(UserController.java:35)
19:22:17.029 [INFO] [Creating] [1/1] In order to prevent getMyProfile(UserPrincipal)
19:22:17.029 [INFO] [Creating] [1/1] from throwing NotAuthorizedException, add constructors or factory
19:22:17.029 [INFO] [Creating] [1/1] methods that make it easier to construct fully initialized objects used in
19:22:17.029 [INFO] [Creating] [1/1] getMyProfile(UserPrincipal).
19:22:17.029 [INFO] [Creating] [1/1] See Working with code R013 | Diffblue Docs to resolve this issue.
19:22:17.029 [INFO] [Creating] [1/1] R013: No inputs found that don’t throw a trivial exception
19:22:17.029 [INFO] [Creating] [1/1] Diffblue Cover tried to run the arrange/act section, but the test threw
19:22:17.029 [INFO] [Creating] [1/1] bg.journey.demo.exception.NotAuthorizedException: You are not authorized to view this resource
19:22:17.029 [INFO] [Creating] [1/1] at java.util.Optional.orElseThrow(Optional.java:403)
19:22:17.029 [INFO] [Creating] [1/1] at bg.journey.demo.service.UserService.getMyProfile(UserService.java:39)
19:22:17.029 [INFO] [Creating] [1/1] at bg.journey.demo.api.v1.UserController.getMyProfile(UserController.java:35)
19:22:17.029 [INFO] [Creating] [1/1] In order to prevent getMyProfile(UserPrincipal)
19:22:17.029 [INFO] [Creating] [1/1] from throwing NotAuthorizedException, add constructors or factory
19:22:17.029 [INFO] [Creating] [1/1] methods that make it easier to construct fully initialized objects used in
19:22:17.029 [INFO] [Creating] [1/1] getMyProfile(UserPrincipal).
19:22:17.029 [INFO] [Creating] [1/1] See Working with code R013 | Diffblue Docs to resolve this issue.
19:22:17.029 [INFO] [Creating] [1/1] R013: No inputs found that don’t throw a trivial exception
19:22:17.029 [INFO] [Creating] [1/1] Diffblue Cover tried to run the arrange/act section, but the test threw
19:22:17.029 [INFO] [Creating] [1/1] java.lang.NullPointerException: Cannot invoke “org.modelmapper.ModelMapper.map(Object, java.lang.Class)” because “this.mapper” is null
19:22:17.029 [INFO] [Creating] [1/1] at bg.journey.demo.service.UserService.getMyProfile(UserService.java:41)
19:22:17.029 [INFO] [Creating] [1/1] at bg.journey.demo.api.v1.UserController.getMyProfile(UserController.java:35)
19:22:17.029 [INFO] [Creating] [1/1] In order to prevent getMyProfile(UserPrincipal)
19:22:17.030 [INFO] [Creating] [1/1] from throwing NullPointerException, add constructors or factory
19:22:17.030 [INFO] [Creating] [1/1] methods that make it easier to construct fully initialized objects used in
19:22:17.030 [INFO] [Creating] [1/1] getMyProfile(UserPrincipal).
19:22:17.030 [INFO] [Creating] [1/1] See Working with code R013 | Diffblue Docs to resolve this issue.
19:22:17.036 [INFO] [Creating] [1/1] bg.journey.demo.api.v1.UserController
19:22:17.036 [INFO] [Creating] [1/1] Tests created: 3
19:22:17.036 [INFO] [Creating] [1/1] Partial tests created: 3
19:22:17.037 [INFO] [Reporting]
19:22:17.037 [INFO] [Reporting] Summary:
19:22:17.037 [INFO] [Reporting] --------
19:22:17.037 [INFO] [Reporting] Total: 1 method
19:22:17.037 [INFO] [Reporting] 3 tests created for: 1 method
19:22:17.037 [INFO] [Reporting] 3 partial tests created for: 1 method
19:22:17.037 [INFO] [Reporting]
19:22:17.747 [INFO] [Reporting] License doesn’t allow multiple classes
19:22:17.747 [INFO] [Reporting] License doesn’t allow creating report.json

Thank you for sending - it looks like you are using Spring 6, and Springboot 3. The version of Cover you are using (2023.07.02) provides basic support for these Spring/Springboot versions. Our newest version of Cover released yesterday provides additional support for Spring 6, and Springboot 3. Therefore, I would recommend to update to the latest version, and re-run Cover.
Please let me know how this goes.

Kind regards,

Jane @ Diffblue

I updated everything and exception is the same. Wrtites only non Spring tests.

Hi @pindarew

Are you using Spring profiles in your project? If so, the relevant profiles will need to be declared to Cover, we have documentation here on how to do this.
This might be causing Cover to be unable to instantiate UserService and UserController.
Please let me know how this goes

Kind regards,
Jane @ Diffblue