• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unit Testing InterruptedException

 
aemilia Hunter
Greenhorn
Posts: 2
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone! This is going to be my first question here in this forum and I don't know if this question has already been raised way back here in codeRanch.

I wanted to know what are the best approaches in testing InterruptedException.
Let's take for example this code:



Thanks in advance!


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I'm going to move this to our Threads forum since it requires knowledge about how to interrupt a thread.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you're looking for with "best approaches", but as far as making it work, all you have to do is call the interrupt() method on the Thread that's running that code.

Can you be more specific about what you're looking for or what difficulty you're having?
 
aemilia Hunter
Greenhorn
Posts: 2
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code goes this way:



and my test goes this way:



Now, I am not sure if what I am doing is right or wrong, calling interrupt() before calling processThread() method.
When running the test method using djunit in eclipse, it is weird that there is no code coverage report. I am not
sure if this is a problem in eclipse or djunit.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic