James Comey. AP Photo/Cliff Owen James Comey, the former FBI director, said he told President Donald Trump on three occasions that he wasn't the subject of a counterintelligence investigation, but Trump was upset that Comey would not say so publicly, according to Comey's prepared written testimony, released ahead of his blockbuster hearing on Thursday.

In the testimony, published by the Senate Intelligence Committee on Wednesday, Comey also said the main reason he did not publicly announce that Trump was not part of the bureau's Russia probe was that "it would create a duty to correct, should that change."

Comey wrote in his testimony that he first assured Trump that he was not personally under FBI investigation during his first meeting with the president-elect, during which he and other intelligence officials briefed him on the intelligence community's conclusions about Russia's interference in the 2016 election.

"Prior to the January 6 meeting, I discussed with the FBI's leadership team whether I should be prepared to assure President-Elect Trump that we were not investigating him personally," Comey said. "That was true; we did not have an open counter-intelligence case on him. We agreed I should do so if circumstances warranted. During our one-on-one meeting at Trump Tower, based on President-Elect Trump's reaction to the briefing and without him directly asking the question, I offered that assurance."

Comey's next assurance came during a dinner with Trump on January 27. Trump mentioned what Comey referred to as the "salacious material" he had briefed Trump about on January 6, most likely meaning the dossier of information, collected by a former British spy, that claimed the Russians had compromising information about Trump.

Trump, "as he had done previously, expressed his disgust for the allegations and strongly denied them," Comey wrote in the testimony. "He said he was considering ordering me to investigate the alleged incident to prove it didn't happen. I replied that he should give that careful thought because it might create a narrative that we were investigating him personally, which we weren't, and because it was very difficult to prove a negative.

"He said he would think about it and asked me to think about it," Comey continued. "As was my practice for conversations with President Trump, I wrote a detailed memo about the dinner immediately afterwards and shared it with the senior leadership team of the FBI."

The final assurance came in March, after Comey's hearing before the House Intelligence Committee, when he publicly announced the FBI was investigating whether the Trump campaign colluded with Russians during the election. That investigation began in late July.

"I explained that we had briefed the leadership of Congress on exactly which individuals we were investigating and that we had told those congressional leaders that we were not personally investigating President Trump," Comey said in the testimony. "I reminded him I had previously told him that."

Trump seemed agitated that Comey did not publicly confirm he was not under investigation, according to the testimony.

"He repeatedly told me, 'We need to get that fact out,'" Comey said. "I did not tell the president that the FBI and the Department of Justice had been reluctant to make public statements that we did not have an open case on President Trump for a number of reasons, most importantly because it would create a duty to correct, should that change."

But Trump also seemed to welcome the FBI's investigation into his associates, while denying personal responsibility.

"The president went on to say that if there were some 'satellite' associates of his who did something wrong, it would be good to find that out, but that he hadn't done anything wrong and hoped I would find a way to get it out that we weren't investigating him," Comey wrote.

Comey said in his testimony that Trump later said the Russia-related "cloud" hanging over his administration "was interfering with his ability to make deals for the country."

After firing Comey in early May, Trump told NBC News' Lester Holt that Comey had assured him on three occasions that he was not under investigation.

Here's Comey's full written testimony: