Detecting or Preventing Calls to a Method from a Specific Method <p>I am writing a JUnit test for code submitted to a competition. The rules of the competition require that certain methods not be called from other methods. (I unfortunately can not change the rules.)</p> <p>The contestants are all implementing an interface we supplied which includes an <code>add(K key, V value)</code> method and a <code>delete(K key)</code> method. We need to test that entries do not implement delete by adding every other element to a new object and return that object.</p> <p>We are also trying to avoid adding dependencies outside of the Java core since we are using a lot of automated tools (like the <a href="http://marmoset.cs.umd.edu/index.shtml" rel="nofollow">Marmoset Project</a>) to test the hundreds of submissions.</p> <p>I read through the documentation for Java Reflection and Instrumentation and nothing jumped out at me.</p> <p>We are using Java 8 if it makes a difference.</p>