FingerprintApiWrapper { FingerprintManager getFingerprintManager() { if (!isAvailable()) { throw new IllegalStateException("Device does not support or use Fingerprint APIs. Call isAvailable() before getting FingerprintManager."); } return fingerprintManager; } FingerprintApiWrapper(@NonNull Context context);   }
@Test public void getFingerprintManager() throws Exception { TestHelper.setSdkLevel(23); when(context.checkSelfPermission(USE_FINGERPRINT)).thenReturn(PackageManager.PERMISSION_GRANTED); when(context.getSystemService(Context.FINGERPRINT_SERVICE)).thenReturn(fingerprintManager); when(fingerprintManager.hasEnrolledFingerprints()).thenReturn(true); when(fingerprintManager.isHardwareDetected()).thenReturn(true); FingerprintApiWrapper fingerprintApiWrapper = new FingerprintApiWrapper(context); assertEquals(fingerprintManager, fingerprintApiWrapper.getFingerprintManager()); }
@Test(expected = IllegalStateException.class) public void getFingerprintManagerThrowsWhenUnavailable() throws Exception { TestHelper.setSdkLevel(21); FingerprintApiWrapper fingerprintApiWrapper = new FingerprintApiWrapper(context); fingerprintApiWrapper.getFingerprintManager(); }