1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Thread.sleep の Exception catch のカバレッジ対応

Last updated at Posted at 2018-06-12

Thread.sleep している箇所で Exception catch のカバレッジが通っていない
どうにか通したいと思い試行錯誤
interrupt の前に sleep 入れたら sleep に入って、Exception 発生するようになった

Test
public class SleepActionTest() {
    @Test
    public void testSleep() throws Exception {
        Thread th = new Thread( ()-> {
            SleepAction.sleep(1000000000);
        });

        th.start();
        TimeUnit.MILLISECONDS.sleep(100);
        th.interrupt();
    }
}
SleepAction
public class SleepAction {
    public static void sleep(int i) {
        try {
            TimeUnit.MILLISECONDS.sleep(i);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?