His resources are unlimited but He is not a wasteful God. He makes sure than nothing in our lives is wasted.
We can trust God because we know that no matter what we face, God is able to make it work for our good. He may not have caused it, but He has such amazing redemptive power beyond what we can comprehend.
Left on our own, there is no way we can look at our circumstances or Paul look at his wrongful imprisonment and write about joy. But with God, even though Paul was externally in chains, internally he was free and partaking of the joy of the Lord. He was allowing himself to receive the fruit of joy from the Holy Spirit and he was choosing to let it overflow through him despite his present circumstances.