I was looking at the Specs wiki and ran into a very impressive example:
http://code.google.com/p/specs/wiki/MatchersGuide#Matchers_composition_for_object_graphs
Unable to understand the example, I tried to make use of the code. What I tried was this:
class ObjectGraphTest extends SpecificationWithJUnit with ObjectGraphMatchers {
val f1 = Foo("hello")
f1.singlebar = Bar(10)
//Test 1
"f1 one macth" in {
val f2 = Foo("hello")
f2.singlebar = Bar(10)
f1 must matchFoo(f2)
}
// Test 2
"f1 not match partial" in {
f1 mustNot matchFoo(Foo("hello"))
}
}
Test 1 runs perfectly. And not matching also reportos ok:
- Issues 1: While Test 2 I get a NullPointerException. Like so:
f1 not match partial
java.lang.NullPointerException
at other.ObjectGraphMatchers$matchBar$$anonfun$apply$13.apply(ObjectGraph.scala:51)
Line 51:
((beEqualTo(_:Long)) ^^^ ((_: Bar).id))(bar)(other)
- Issue 2: This is a funny thing, IDEA reports a type mismatch:
(matchBar(_)).toSet ^^^ ((_:Foo).bars))(foo)(other)
Curly red line on the foo, message: Type mismatch, expected: Nothing, actual: ObjectGraphMatchers.this.type#Foo
I compiles and works ok, and runs fine. Maybe this is an IDEA issue;
My question, did I miss something on the example? How do I avoid the NullPointerException?
Thomas