There are different versions of the Christmas Story from different gospels. Matthew relates the story from the perspective of Joseph. Luke relates the story from the perspective of Mary. John is more theological and Mark goes right past it and starts with Jesus baptism. We are dealing with Matthew 1:18-25.
From start to finish we see in Joseph the highest quality and character; that which we all ought to emulate. But Joseph, in all his self restraint and godliness, still needed a revelation, a dream from God to go the right, but counterintuitive path.