Book-Microservices-v3 / chapter03

Learn Microservices with SpringBoot 3 (3rd edition) - Chapter 3
2 stars 2 forks source link

org.mockito.exceptions.base.MockitoException: Unable to initialize @Spy annotated field 'random'. #7

Closed gliderguy closed 5 months ago

gliderguy commented 5 months ago

when running test ChallengeGeneratorServiceTest received error

org.mockito.exceptions.base.MockitoException: Unable to initialize @Spy annotated field 'random'.

Mockito cannot mock this class: class java.util.Random.

gliderguy commented 5 months ago

Cause was in the chapter when creating spring boot project the picture figure 3-1 shows 3.0.5 If you forget to follow the written instructions and don't update springframework.boot version to 3.1.0 you will get the error.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>