1 Samuel - Chapter 27
In this chapter David does not show faith in God - rather than trusting God he thinks:
“One of these days I will be destroyed by the hand of Saul. The best thing I can do is to escape to the land of the Philistines."
He puts his trust in the Philistines rather than God, and living under the protection of Achish. He then uses his soldiers as bandits, destroying local villages, and lies to Achish about it. This is another chapter where it is difficult to see Jesus' presence. And yet despite all David's actions we still see Paul say, in Acts 13:
"After removing Saul, he made David their king. God testified concerning him: ‘I have found David son of Jesse, a man after my own heart; he will do everything I want him to do.’"
People that are "after God's own heart" are not perfect people who do no wrong - but are sinners who accept God's offer of forgiveness and salvation. As Jesus said on this in Mark 2:
“It is not the healthy who need a doctor, but the sick. I have not come to call the righteous, but sinners.”