Now when Elisha had fallen sick with the illness of which he was to die, King Joash of Israel went down to him, and wept before him, crying, "My father, my father! The chariots of Israel and its horsemen! " Elisha said to him, "Take a bow and arrows"; so he took a bow and arrows. Then he said to the king of Israel, "Draw the bow"; and he drew it. Elisha laid his hands on the king's hands. Then he said, "Open the window eastward"; and he opened it. Elisha said, "Shoot"; and he shot. Then he said, "The Lord's arrow of victory, the arrow of victory over Aram! For you shall fight the Arameans in Aphek until you have made an end of them. " He continued, "Take the arrows"; and he took them. He said to the king of Israel, "Strike the ground with them"; he struck three times, and stopped. Then the man of God was angry with him, and said, "You should have struck five or six times; then you would have struck down Aram until you had made an end of it, but now you will strike down Aram only three times." (NRSV 13:14-19)
Now Elisha was fallen sick of his sickness whereof he died. And Joash the king of Israel came down unto him, and wept over his face, and said, O my father, my father, the chariot of Israel, and the horsemen thereof. And Elisha said unto him, Take bow and arrows. And he took unto him bow and arrows. And he said to the king of Israel, Put thine hand upon the bow. And he put his hand upon it: and Elisha put his hands upon the king's hands. And he said, Open the window eastward. And he opened it. Then Elisha said, Shoot. And he shot. And he said, The arrow of the Lord's deliverance, and the arrow of deliverance from Syria: for thou shalt smite the Syrians in Aphek, till thou have consumed them. And he said, Take the arrows. And he took them. And he said unto the king of Israel, Smite upon the ground. And he smote thrice, and stayed. And the man of God was wroth with him, and said, Thou shouldest have smitten five or six times; then hadst thou smitten Syria till thou hadst consumed it: whereas now thou shalt smite Syria but thrice. (KJV 13:14-19)
Even though Joash of Israel isn't technically a "good" king, he's apparently not bad enough to earn the disrespect of prophets. The loyalty of God towards his people transcends Joash's flaws, leading to this guarantee of a qualified victory over Aram.