java - JUnit4 : Test a shutdown hook is called -


i have method adds shutdown hook. need test (via junit) code executed in hook called :

public void mymethod(){     runtime.getruntime().addshutdownhook(new thread() {          @override         public void run() {             ... code test ...         }     }); } 

how can simulate shutdown in unit test ?

i don't think you'll able test that. instead, test code behaves correctly when invoked (by unit testing separately). then, trust java invoke code @ right time.

i.e. extract code separate class extends thread , test behaviour executing run() in unit test.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -