khan7
khan7

Reputation: 47

How to mock a Scala Seq?

I basically need to test an edge-case where I have a Seq[Foo] with 100 Foo objects. Instead of manually initializing 100 unique Foo objects and adding them to a Seq, is there some functionality of mockito I can use?

What I'm basically trying to do is: val mockSeq = mock(Seq) when(mockSeq).length.thenReturn(100)

Upvotes: 0

Views: 536

Answers (1)

James Whiteley
James Whiteley

Reputation: 3474

As cchantep says, you're probably better off just creating a Seq and filling it, something like this:

object Foo
Seq.fill(100)(Foo)

This will fill the Seq with 100 Foo objects. I don't see any benefit to using Mockito for something like this.

Read more about it in the docs.

Upvotes: 4

Related Questions