Sorry, me again. Is there any way of listing all t...
# mockk
v
Sorry, me again. Is there any way of listing all the declared mocks? As in, you're convinced that you've set up a mock correctly but
coVerify
insists it was not called.
Copy code
no answer provided for DynamoDBService(#8).upsertContentNode(eq(domain.com/sources/posts/my-post.md), eq(domain.com), eq(Posts), any(), eq({}), any()))
And yet...
Copy code
declareMock<DynamoDBService> {
            every { mockDynamoDBService.logger = any() } just runs
            every { mockDynamoDBService.logger } returns mockLogger
            coEvery {
                mockDynamoDBService.upsertContentNode(
                    "domain.com/sources/posts/my-post.md", "domain.com", 
                        SOURCE_TYPE.Posts,
                    any<ContentNode.PostNode>()
                )
            }
        }
e
eq({})
looks suspicious. are there any optional arguments you aren't passing?
v
Yes, there's an optional Map<String,String> parameter... in the interface, which has a default value of emptyMap(). I've changed it now to remove the default value. Still not working, of course 🙂
Possibly because I am using koin's
declareMock
as well as mockk?
e
I have no idea what koin's declareMock does, sorry
I was concerned
{}
might be a lambda, in which case it wouldn't be equal across calls, but Map uses structural equality so it's fine
v
The class will be the death of me. Junie/AI completely made a mess of trying to add tests; I'm not doing much better. The class I am trying to mock is injected using the koin DI framework.
Oh my. The mock declaration wasn't specifying the return object.
Copy code
declareMock<DynamoDBService> {
            every { mockDynamoDBService.logger = any() } just runs
            every { mockDynamoDBService.logger } returns mockLogger
            coEvery {
                mockDynamoDBService.upsertContentNode(
                    "<http://domain.com/sources/posts/my-post.md|domain.com/sources/posts/my-post.md>", "<http://domain.com|domain.com>",
                    SOURCE_TYPE.Posts, any<ContentNode.PostNode>(), emptyMap()
                )
            } returns true  // <----- I hadn't added this bit
        }
🙈 1
Now I seem to have broken everything! gradle is just sitting at "Executing test..." It's been like that for 7 minutes now. Probably a me problem not a koin or mockk problem though.
Finally working. I am fairly certain that I have made so many changes that the code won't actually work in real life, but at least the unit test passes and that's the main thing, surely...