I am making an assumption that a code path is only executed once within the JVM. However, when writing complex, multi-threaded system sometimes the assumption can be wrong.
Are there any one liner assertion I can use to assert this. Something like Guava's Preconditions.checkState(expr)
but more like assertAtMostTimes(1, "Should not be executing more than once")
. Prefer something simple rather than tracking number of times in a class variable.
This is similar to how test cases can be written but I am looking for something in production code.