Genesis 39:21
"But the LORD was with Joseph, and shewed him mercy, and gave him favour in the sight of the keeper of the prison."
The first thirty years of Joseph's life were certainly unpleasant years. It didn't matter what Joseph did, he always found himself in unpleasant circumstances that were beyond his control. When he did right, it seemed as if circumstances got worse. No doubt he could have easily become discouraged with all that he faced.