I’m trying to mock an interface that has methods u...
# arrow
k
I’m trying to mock an interface that has methods using the RaiseDSL approach, however, the mocking part looks terrible and is probably wrong. What’s a more elegant approach to doing this? I don’t want to have to wrap my
whenever
parameter in an either, and then also have to turn the returning option into an either also. I included the method signature as a comment within the snippet.
Copy code
// context(Raise<Error>) getScopedMethod(value: String): Option<Foo>
      val mocked = mock<SomeScope> {
        whenever(either { it.getScopedMethod(any()) }).thenReturn(Foo("foo").some().right())
      }
r
s
I think it's time we form an official answer about this on the website. Are some people up for collaborating on this? cc\\ @CLOVIS @Olaf Gottschalk
I think this would also fit in perfectly with the FAQ @Kev
c
I'm up for it 🙂 Though I wouldn't recommend mocks
2
k
@simon.vergauwen give your talk on how to effectively do mocking using context receivers /s
😂 2
r
I guess the best way to mocking them is not to use mocking at all 😜
1
s
Teaching people FP, and not using mocks? I'm going to leave that to RockTheJvm 😂 😉
😅 1
mind blown 2
thank you color 1
😆 1
r
We’ll keep the topic into consideration for next articles 😜
👌 1
s
If you ever need someone to review something feel free to reach out 😉
r
cc @Daniel Ciocirlan
d
Would be much appreciated @simon.vergauwen! Will reach out when ready
🙌 2