Hmmm... there's the method Thread.holdsLock(Object), which sort of does what you ask. Almost. But since it only operates on the current
thread, not on an arbitrary Thread object, I have a hard time imagining a way to use it effectively as part of a unit test.
Still, if you need to verify that a particular block of code is synchronized, why not just make it synchronized? That way you're sure. Of the many complicated things to think about in concurrency, this one doesn't seem too tough. Knowing whether you
should sync a particular bit of code, and on what monitor - that's the hard part. Ensuring that is
is synchronized on that monitor - that's easy.