You could also add .anyNumberOfTimes after the returning call but it’s unnecessary.
There’s no way to distinguish the intention of allowing and ignoring interactions in Scalamock.
JMock will return a default value (as a dynamic proxy) if you set up an expectation but leave off a returnValue. In the example below, we don’t care if it returns anything so if the code under test relies on a value, but the test does not, we don’t have to express anything in the test.
Default Values: JMock / Java
If the underlying code were to check, say, that the result of factory.create() was not an empty list with if (result.isEmpty()), JMock would return something sensible and we’d avoid a NullPointerException. You might argue that this side affect should be captured in a test but leaving it off makes the intention of expectation clearer; we only care that create is called, not what it returns.
Scalamock will return null by default. So the above example would give a NullPointerException and you’re required to do something like this. Notice we’re using a stub and not a mock here.
AnotherException is a subtype of SomeException but any will match on literally anything. Using subtypes like this in JMock is a bit of a smell as a test won’t fail if a different subtype is thrown at runtime. It may be useful to express intent.