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

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -