public synchronized static void clear ( ) { newSubstitutions . clear ( ) ; classMocks . clear ( ) ; instanceMocks . clear ( ) ; objectsToAutomaticallyReplayAndVerify . clear ( ) ; additionalState . clear ( ) ; suppressConstructor . clear ( ) ; suppressMethod . clear ( ) ; substituteReturnValues . clear ( ) ; suppressField . clear ( ) ; suppressFieldTypes . clear ( ) ; methodProxies . clear ( ) ; for ( Runnable runnable : afterMethodRunners ) { runnable . run ( ) ; } afterMethodRunners . clear ( ) ; }
Clear all state of the mock repository except for static initializers . The reason for not clearing static initializers is that when running in a suite with many tests the clear method is invoked after each test . This means that before the test that needs to suppress the static initializer has been reach the state of the MockRepository would have been wiped out . This is generally not a problem because most state will be added again but suppression of static initializers are different because this state can only be set once per class per CL . That s why we cannot remove this state .