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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -