@ UnstableApi @ SuppressWarnings ( "CheckReturnValue" ) public static void spyOn ( Object toSpy ) { if ( onSpyInProgressInstance . get ( ) != null ) { throw new IllegalStateException ( "Cannot set up spying on an existing object while " + "setting up spying for another existing object" ) ; } onSpyInProgressInstance . set ( toSpy ) ; try { spy ( toSpy ) ; } finally { onSpyInProgressInstance . remove ( ) ; } }
Make an existing object a spy .