In 1 Samuel Chapter 30, we see a few interesting things. David found himself in a difficult situation. When he and his men had gone to battle, the Amalekites had come and destroyed the city where the families of his people were staying and taken their families captive. The situation was so bad that all the men began to weep and also to blame David for their problems. They wanted to stone him to death (1 Sam. 30:6). And then we read these lovely words: "But David encouraged himself (and strengthened himself) in the Lord" (1 Sam. 30:6). What an example for us to follow, when even our friends turn against us.
David sought the Lord and the Lord told him to pursue after the Amalekites and assured him that he would recover everything (1 Sam. 30:8). But David did not know in which direction to go to find these Amalekites. It is wonderful to see how God led him to them. It was through a simple act of kindness to a dying stranger. David and his men saw an Egyptian lying in the desert in a coma, half-dead. They cared for him and gave him something to eat and drink. When he revived, they discovered that he had been forsaken by the Amalekites in the desert, because he was sick (1 Sam. 30:11-13). He was the one who then led David to the Amalekites. This teaches us how God rewards us when we are kind to strangers. Thus David found and defeated the Amalekites. Then it is written thrice, that "David recovered all" that had been stolen by the Amalekites (1 Sam. 30:18-20) - a beautiful picture of Jesus recovering all that Satan had stolen from us!
When the battle was over and David returned to the camp, there were 200 of his men there who had been too exhausted to follow David into battle, and who had stayed behind to look after David's goods. Some of David's worthless men then said that the spoils of the battle should not be shared with these men who did not fight. But we see the largeness of David's heart there. He said that those who stayed at home to look after the baggage should get an equal share of the spoils of war, as those who went out to battle and fought. And this became a law in Israel from that day onwards.
It was through all those difficulties and trials that David faced (over a period of about 13 years), that he finally became a man of God and a successful king. Years later, he wrote these words: "You have tested me O God. You have refined me as silver is refined. You allowed me to be trapped in nets. You allowed heavy, oppressive burdens to be laid on my back. You allowed men to ride over my head. You took me through the burning fire and then through icy-cold water. But finally, You brought me out into a place of spiritual abundance and anointing, where my cup is now overflowing with blessing to multitudes of people. Praise the Lord" ( Psa. 66:10-13 - free paraphrase).