I have a MockBean in my test:
@MockBean(SomeClient.class)
SomeClient client;
I'm starting up a spring-boot test:
@ExtendWith(SpringExtension.class)
@ActiveProfiles("test")
@SpringBootTest(properties = { "spring.jpa.hibernate.ddl-auto=create-drop" })
On spring startup, one of my services is trying to call a method that returns an object, then gets the ID from the returned object:
@Service
public class SomeService {
public SomeService(final SomeClient someClient) {
this.someClient = someClient;
this.clientId = someClient.clientMetadata().getId(); << NullPointerException Here
}
}
However, I'm getting a NullPointerException because .clientMetadata() returns null.
How do I go about setting up the mock bean so that it returns a Metadata object with the ID populated on it?
Using:
- Java 8
- JUnit 5
- spring-boot-starter-test 2.2.9.RELEASE
PS - I can't use @BeforeEach
because it tries to boot the app before it executes the beforeEach method.