'Mockk anonymous class

I'm trying to mock anonymous class created in testInstance Sample:

 class SomeClass(val someValue:SomeType) :SomeAnotherClass(){
        val anonymousClass = object : AnotherClass{
        override anotherMethod() { }
        }

        override fun someMethod(someValue) = anonymousClass.someMethod(someValue) 
  }

And test class:

   class SomeClassTest {
    private val someValue: SomeType = mockk()
    private val testInstance = spyk(SomeClass(someValue), recordPrivateCalls = true)
    
        @Test
        fun `test method`(){
            mockkConstructor(CustomTlsSocketFactory::class)
            every { anyConstructed<AnotherClass>().someMethod(someValue) } returns mockk()
    
            testInstance.someMethod(someValue)
    
            verify { anyConstructed<AnotherClass>().someMethod(someValue) }
          }
        }

And for some reason anonymousClass.someMethod(someValue) is trying to call original method not mockk. Calling testInstance.anonymousClass.isMock is false



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source