DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Ho to test failure condition of ListenableFuture? #1717

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to test onFailure(Throwable throwable){} condition using junit,
but it's not working, always control going to onSuccess() condition only.

I there any way I can achieve to test failure condition?

below is the example code I am trying,

final TimeoutException timeoutException = new TimeoutException("Processing 
Timeout");
        final ListenableFuture<MyClass> result = Futures.immediateFailedFuture(timeoutException);
        Mockito.when(MyAsynClass.callListenableFuture()).thenReturn(result);
        myAsynClass.deliver();

In above test case callListenableFuture() return ListenableFuture<MyClass>,

and deliver have the callback for the ListenableFuture.

Could you please help me to write test cases for failure methods.( Exceptions)

Original issue reported on code.google.com by chandu...@gmail.com on 8 Apr 2014 at 10:33

GoogleCodeExporter commented 9 years ago
This issue tracker isn't the place to ask for help when you're having a 
problem, it's for reporting issues or requesting enhancements. Try asking on 
StackOverflow: http://stackoverflow.com/questions/ask?tags=java+guava

Original comment by cgdecker@google.com on 8 Apr 2014 at 5:41

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:09

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07