Using a class

Let's have a look at how DoubledMultiplierIdentity, which we saw previously, would be tested. One would try to simply mix the trait into a test class and test the methods:

class DoubledMultiplierIdentityTest extends FlatSpec with ShouldMatchers with DoubledMultiplierIdentity

This, however, won't compile and will lead to the following error:

Error:(5, 79) illegal inheritance; superclass FlatSpec is not a subclass of the superclass MultiplierIdentity of the mixin trait DoubledMultiplierIdentityclass DoubledMultiplierIdentityTest extends FlatSpec with ShouldMatchers with DoubledMultiplierIdentity {^

We already talked about this before and the fact that a trait can only be mixed in a class that has the same super class as itself. ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.