android - PowerMockito doThrow when call static method return UnfinishedStubbingException -


latest use cache lib disklrucache developed jakewharton https://github.com/jakewharton/disklrucache , writing test piece of code

public void initdisklrucache() {         try {             disklrucache = disklrucache.open(context.getfilesdir(), 1, 1, max_cache_size);         } catch (ioexception e) {             e.printstacktrace();         }     }  

and wanna test when open file failed , throw exception, used powermockito according doc : https://github.com/powermock/powermock/wiki/mockitousage#how-to-stub-void-static-method-to-throw-exception

@test(expected = ioexception.class)     public void testinitdisklrucachefailed() throws ioexception {         powermockito.mockstatic(disklrucache.class);         powermockito.dothrow(new ioexception("error")).when(disklrucache.open(any(file.class), anyint(), anyint(), anylong()));         service.initdisklrucache();     } 

i add @preparefortest(disklrucache.class)and@runwith(powermockrunner.class), failed error

java.lang.exception: unexpected exception, expected<java.io.ioexception> was<org.mockito.exceptions.misusing.unfinishedstubbingexception 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -