I am trying to mock a function to throw an exception like this
BigQueryIO mockb = mock(BigQueryIO.class);
when(mockb.getClass().getDeclaredField("SOME_FIELD"))
.thenThrow(new NoSuchFieldException());
it's throwing NoSuchFieldException in the test mock itself.
I have also tried this way
when(BigQueryIO.class.getDeclaredField("SOME_FIELD"))
.thenThrow(new NoSuchFieldException());
but this is also not working,
Am I missing some basic thing? Does mock work differently with .class?