It is narrated from the holy Prophet of Islam (PBUH) who said:
One day a man said: Swear to God, Allah (SWT) will not forgive such a person (another man whom he knew)! Then Allah (SWT) revealed: Who is certain that God will not forgive such a person? I (God) forgave such a person and instead invalidated the good deeds of that man (who presumed God would not forgive the person whom he knew); because he was certain that I (God) will not forgive such a person [1].
[1] Beharul Anwaar, Vol. 6, Page 4.
Source: en.shafaqna.com