Question: I have a class implements Runnable like this 

```
  public Processor implements Runnable{

  public void run() {
     while (true) {
     //some code
     sendRequest(object);
      }
   }
}

 public void sendRequest(Object, object){
 // do something to send the event
  }
}

```

And in other pre-load class. I use 

```
Processor processor = new Processor();
ExecutorService executor = Executors.newCachedThreadPool();
executor.execute(processor)

```

So my question is how can I unit test sendRequest method is called or not?

Answer: 
i believe you want to test only implemented `run()` method, so you can call the method directly using `Processor` object or you can create a thread and pass runnable object to it and call `Thread.start()`

If `sendRequest(Object object)` method is doing any external operations i will suggest you to mock that method

```
public class ThreadTest {

@Test(//throws some exception)
public void shouldThrowSomeException() {
    Processor exThread = new Processor ();
    exThread.run(); //or
    Thread t = new Thread(exThread);
     t.start()

    }
}

```

**Mocking** for mocking [here](https://www.baeldung.com/mockito-exceptions)

```
@Test(//throws some exception)
public void shouldThrowSomeException() {
    Processor exThreadmock = mock(Processor.class);
    when(exThreadmock.sendRequest(anyObject))
    .thenThrow(SomeException.class)
    Thread t = new Thread(exThread);
     t.start()

    }

```
Use `Mockito.spy` for partial mocking.

```
Processor processor = spy(new Processor());

doCallRealMethod().when(processor).run();

verify(processor).sendRequest(mock1, mock2);

```