Tim Cooke wrote:The most fun way to learn why this code snip is a problem for testing is to try and write the tests for it yourself. You're quite right that you can instantiate both of those classes and you can call embarkOnQuest() but how will you assert that quest.embark(); is called?
What’s more, it’d be terribly difficult to write a unit test for DamselRescuingKnight.
In such a test, you’d like to be able to assert that the quest’s embark() method
is called when the knight’s embarkOnQuest() method is called. But there’s no clear
way to accomplish that here. Unfortunately, DamselRescuingKnight will remain
untested.