Come Michael, ha detto, è possibile utilizzare ScalaTest's matchers. Assicurati di estendere lo Matchers
nella tua classe di test. Possono benissimo sostituire la funzionalità di Hamcrest, sfruttare le funzionalità di Scala e sembrare più naturale in Scala per me.
Qui, è possibile confrontare Hamcrest e ScalaTest matchers su alcuni esempi:
val x = "abc"
val y = 3
val list = new util.ArrayList(asList("x", "y", "z"))
val map = Map("k" -> "v")
// equality
assertThat(x, is("abc")) // Hamcrest
x shouldBe "abc" // ScalaTest
// nullity
assertThat(x, is(notNullValue()))
x should not be null
// string matching
assertThat(x, startsWith("a"))
x should startWith("a")
x should fullyMatch regex "^a..$" // regex, no native support in Hamcrest AFAIK
// type check
assertThat("a", is(instanceOf[String](classOf[String])))
x shouldBe a [String]
// collection size
assertThat(list, hasSize(3))
list should have size 3
// collection contents
assertThat(list, contains("x", "y", "z"))
list should contain theSameElementsInOrderAs Seq("x", "y", "z")
// map contents
map should contain("k" -> "v") // no native support in Hamcrest
// combining matchers
assertThat(y, both(greaterThan(1)).and(not(lessThan(3))))
y should (be > (1) and not be <(3))
... e molto di più si può fare con ScalaTest (ad esempio, utilizzare pattern matching Scala, affermare ciò che può/non può compilare , ...)
Non posso parlare per questa particolare domanda, ma: Nella mia esperienza generale, trovo che le librerie Java che mirano a fornire espressività sono di solito ovviate dalle librerie Scala (o semplicemente dalle caratteristiche del linguaggio Scala). –