### Question:
AuthenticatorManager { void createMechanismFromUri(String uri, FRAListener<Mechanism> listener) { Logger.debug(TAG, "Creating new mechanism from URI: %s", uri); if(uri.startsWith(Mechanism.PUSH)) { if(pushFactory != null) { pushFactory.createFromUri(uri, listener); } else { Logger.warn(TAG, "Attempt to add a Push mechanism has failed. " + "FCM token was not provided during SDK initialization."); listener.onException(new MechanismCreationException("Cannot add Push mechanisms. " + "FCM token not provided during SDK initialization to handle Push Notifications.")); } } else if(uri.startsWith(Mechanism.OATH)) { oathFactory.createFromUri(uri, listener); } else { Logger.warn(TAG, "Invalid QR Code given for Mechanism initialization."); listener.onException(new MechanismCreationException("Invalid QR Code given for Mechanism initialization.")); } } AuthenticatorManager(Context context, StorageClient storageClient, String deviceToken);   }### Answer:
@Test public void testShouldCreateOathMechanismSuccessfully() throws Exception { String uri = "otpauth: authenticatorManager.createMechanismFromUri(uri, oathListenerFuture); OathMechanism oath = (OathMechanism) oathListenerFuture.get(); assertEquals(oath.getOathType(), OathMechanism.TokenType.TOTP); assertEquals(oath.getAccountName(), "user1"); }
@Test public void testFailToCreateMechanismInvalidQRCode() { try { authenticatorManager = new AuthenticatorManager(context, storageClient, null); String uri = "http: authenticatorManager.createMechanismFromUri(uri, oathListenerFuture); oathListenerFuture.get(); fail("Should throw MechanismCreationException"); } catch (Exception e) { assertTrue(e.getCause() instanceof MechanismCreationException); assertTrue(e.getLocalizedMessage().contains("Invalid QR Code given for Mechanism initialization")); } }
@Test public void testCreatePushMechanismFailureNoFcmTokenProvided() { try { authenticatorManager = new AuthenticatorManager(context, storageClient, null); server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)); String uri = "pushauth: "a=" + getBase64PushActionUrl(server,"authenticate") + "&" + "image=aHR0cDovL3NlYXR0bGV3cml0ZXIuY29tL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEzLzAxL3dlaWdodC13YXRjaGVycy1zbWFsbC5naWY&" + "b=ff00ff&" + "r=" + getBase64PushActionUrl(server,"register") + "&" + "s=dA18Iph3slIUDVuRc5+3y7nv9NLGnPksH66d3jIF6uE=&" + "c=Yf66ojm3Pm80PVvNpljTB6X9CUhgSJ0WZUzB4su3vCY=&" + "l=YW1sYmNvb2tpZT0wMQ==&" + "m=9326d19c-4d08-4538-8151-f8558e71475f1464361288472&" + "issuer=Rm9yZ2Vyb2Nr"; authenticatorManager.createMechanismFromUri(uri, pushListenerFuture); pushListenerFuture.get(); fail("Should throw MechanismCreationException"); } catch (Exception e) { assertTrue(e.getCause() instanceof MechanismCreationException); assertTrue(e.getLocalizedMessage().contains("FCM token not provided during SDK initialization")); } }