79447719

Date: 2025-02-18 09:30:00
Score: 1.5
Natty:
Report link

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
    }
Reasons:
  • Blacklisted phrase (1): this link
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Sopnil.Shinde