Because expectedKey
is an instance of a subclass of Key, most probably. The error message you get from the failed assertion should tell you. Read it.
"s"
, for example is an instance of java.lang.Object, but its class is not java.lang.Object, it's java.lang.String.