0

I have a statement shown below which i need to test/verify call to:

snmpDispatchDelegateExecutor.submit(() -> processRunFunctionException(exception));

now it contains many things at once (Async calls , lambda and private methods all in one ), so i have some questions : 1: for handling submit() call which return future tasks. do i have to do something like

when(snmpDispatchDelegateExecutorMock.submit(any()/Runnable)).thenReturn(any()/FutureTask). 

then the problem is how to achieve it (creating Runnable and Future). Tried creating both looks complex .

2: processRunFunctionException(exception) is a private method ,do we need to cover that , lot of "SO" posts says no need to cover private methods . In general if i focus on covering public methods private method should get covered as well . referred this

3: How to work with lambda expression here . went through link but no much help.

niranjan
  • 159
  • 1
  • 12

1 Answers1

0

It's often problematic to mock classes that you don't own, since you are hard-coding behavior in your test that may not match the actual behavior.

I suggest using a real ExecutorService implementation. For instance, you can use an implementation that does its work in the current thread (see Is there an ExecutorService that uses the current thread?) or an implementation that only does the work when you tell it to.

NamshubWriter
  • 23,549
  • 2
  • 41
  • 59