So, James is exhorting us to count it all joy even when it is not all joy, not because it is joyous to be involved in pain and suffering, but because God can bring good through that pain and suffering. He is working in even the difficult situations for our sanctification.