So I got the solution
Basically the solution I found belongs to this link https://github.com/robolectric/robolectric/issues/8661
There was a problem with sdk 33 with respective to roboelectric. And I was testing on sdk 33
So Nfcadapter.getdefaultAdapter() was coming null
So I have to use MockStatic for NfcAdapter
try(MockedStatic<NfcAdapter> nfcMockAdapter = mockStatic(NfcAdapter.class)) {
nfcMockAdapter.when(() -> NfcAdapter.getDefaultAdapter(any()))
.thenReturn(mock(NfcAdapter.class));
// Your code here
}