You could tell some things from a sample gained that way. If he had Azoospermia which is the absence of sperm in the semen or Teratospermia which is malformed sperm. Those could be tested from such a sample. The doctor would have to be breaking ethical rules though (but it's not a tough test, most competent doctors with a microscope could check the two above, so it could be someone who lost their license or even a good vet, or if she studied she could do it herself, especially if she had some history working with microscopes etc.). You can't legally just go and test someone else without their permission or a legal document.
Decreased sperm motility, small ejaculate and low sperm count might be tougher to diagnose.
http://en.wikipedia.org/wiki/Male_infertility#Sperm_sample
wiki is unreliable.
A semenalysis is a test fraught with problems when collected in suboptimal conditions. Each improper portion of collection results in a worse and worse reading. The OP is suggesting far worse than suboptimal condidtions. Not even azoospermia could be trusted in such a collection method.
To the OP: Short of drugging the guy so that he doesn't remember the "collection" and then using standard collection methods, there isn't a way for him to not know and still have a valid collection sample. The problem there is that the drugs required will also hamper the actual collection. If he had had a previous vasectomy, there can roughly 1 in 200 to 1 in 600 cases (depends whose articles you prefer) be once in a while an intermittent reconnection of the vas to explain a "miracle baby", such that most of the time the guy is shooting blanks, but once in a whi8le there are live rounds in the chamber. The chances of this drops with time as the sperm producing cells generally atrophy slowly after a vasectomy. Those who do vas reversals sometimes won't bother attempting it more than 5 years out from a vasectomy, and the longer after that, the less likely that it can be reversed.
Another option is that he had had some sort of radiation or chemo years ago that was expected to cause sterility. Most of the time, guys don't have true "infertility" but rather various degrees of subfertility. The sum of the discussion with such patients tends to be, "Well, if you try to get somebody pregnant, it probably won't work, but if you count on it as birth control, that might not work either."