java - How to throw `InterruptedException` while junit testing my class? -


i trying write junit class using countdownlatch , using jmockit library junit testing.

public class mappeddata {      private static final atomicreference<map<string, map<integer, string>>> mapped1 = new atomicreference<map<string, map<integer, string>>>();     private static final atomicreference<map<string, map<integer, string>>> mapped2 = new atomicreference<map<string, map<integer, string>>>();     private static final countdownlatch firstset = new countdownlatch(1);      public static map<string, map<integer, string>> getmapped1table() {     try {         firstset.await();     } catch (interruptedexception e) {         throw new illegalstateexception(e);     }     return mapped1.get();     }      public static map<string, map<integer, string>> getmapped2table() {     try {         firstset.await();     } catch (interruptedexception e) {         throw new illegalstateexception(e);     }     return mapped2.get();     } } 

what easiest way make sure in getmapped1table , getmapped2table method - able throw interruptedexception can cover scenario well. if take 2 methods, have catch block not able cover.

mappeddata.getmapped1table() 

is there way can make sure above 2 methods throwing interruptedexception?

update:-

what trying - how firstset.await() throw interruptedexception when junit testing.

here simplest way write test jmockit:

public class mappeddatatest {     @test     public void getmappedtablehandlesinterruptedexception(         @mocked final countdownlatch anylatch) throws exception     {         final interruptedexception interrupt = new interruptedexception();         new nonstrictexpectations() {{ anylatch.await(); result = interrupt; }};          try {             mappeddata.getmapped1table();             fail();         }         catch (illegalstateexception e) {             assertsame(interrupt, e.getcause());         }     } } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -