Children of Israel Are Never Alone

Joseph is only a teenager when he is sold as a slave. How was he able to develop enough strength of character to pass so many tests while still so young?