This scripture is one I have had many opportunities to ponder. When I was young and life was free and easy, I never gave it much thought. It was just one of those scriptures I grew up with and didn't question. As life became more complicated and trials appeared, I had to dig a little deeper to live out this scripture.
I am glad it doesn't say to "be happy" when you encounter various trials. Or "put a smile on your face" when you encounter various trials. Joy is completely independent of the fleeting feeling called happiness. Joy does not require a smile at all times. I have found joy is internal and allows me to live day to day with peace despite the circumstances.
Losing a loved one is not a time of happiness but can bring joy when you know they are in the presence of God. Having a chronic disease will not make your heart happy but can bring joy in the knowledge that our Lord will walk with us on our worst days and provide endurance to live through the struggle. Losing a job is not a happy circumstance but can be a time of learning the joy of God's provision.
God has not asked us to be happy in our trials but rather to trust in Him and have faith in Him. The joy comes when you realize He's got your back!