I am trying to write integration test for one of the API in my application which is based on spring webflux. I have integrated an external library which is developed by my organisation and provides support for authentication using JWT tokens.
Custom Validator is defined as
open class CustomValidator {
//Some of the internal classes as fields
}
above class has a function validate which takes two arguments
fun validate(argumentOne: ArgumentOne, argumentTwo: ArgumentTwo? = null)
class which i have created for configuration of integration test is
@TestConfiguration
class TestSecurityConfig {
val customValidator: CustomValidator = mockkClass(CustomValidator::class)
}
The final integration test class is
@SpringBootTest(webEnvironment = RANDOM_PORT)
@ExtendWith(MockKExtension::class)
@TestInstance(PER_CLASS)
@AutoConfigureWebTestClient(timeout = "1d")
@Import(TestSecurityConfig::class)
class FunctionalTestClass {
** THIS IS GIVING ERROR (COULD NOT AUTOWIRE ) IN EDITOR
@Autowired
private lateinit var egTokenValidator: EGTokenValidator
}
@Test
fun `testing One` () {
//This function i am trying to mock
Mockito.`when`(customeValidator.validate(anyOrNull(), anyOrNull())).thenReturn(validationResult)
//Other code
}
Now when i am running the test case it is not able to mock the class CustomValidator and also giving warning near autowired.
Could you guys please help on how to accomplish this ?
I have not added complete implementation as it is orgranisation code.
I was expecting for the class CustomValidator to be mocked so that i could mock its validator function