@Override
  public void setUp() throws Exception {
    super.setUp();

    DependencyInjector.resetForIntegrationTesting(getContext());
    initMocks(this);
    DependencyInjector.setTotpClock(mockTotpClock);

    accountDb = DependencyInjector.getAccountDb();
    otpProvider = new OtpProvider(accountDb, mockTotpClock);
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check_code);
    mCodeTextView = (TextView) findViewById(R.id.code_value);
    mCheckCodeTextView = (TextView) findViewById(R.id.check_code);
    mCounterValue = (TextView) findViewById(R.id.counter_value);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String user = extras.getString("user");

    AccountDb accountDb = DependencyInjector.getAccountDb();
    AccountDb.OtpType type = accountDb.getType(user);
    if (type == AccountDb.OtpType.HOTP) {
      mCounterValue.setText(accountDb.getCounter(user).toString());
      findViewById(R.id.counter_area).setVisibility(View.VISIBLE);
    } else {
      findViewById(R.id.counter_area).setVisibility(View.GONE);
    }

    String secret = accountDb.getSecret(user);
    String checkCode = null;
    String errorMessage = null;
    try {
      checkCode = getCheckCode(secret);
    } catch (GeneralSecurityException e) {
      errorMessage = getString(R.string.general_security_exception);
    } catch (DecodingException e) {
      errorMessage = getString(R.string.decoding_exception);
    }
    if (errorMessage != null) {
      mCheckCodeTextView.setText(errorMessage);
      return;
    }
    mCodeTextView.setText(checkCode);
    String checkCodeMessage =
        String.format(getString(R.string.check_code), TextUtils.htmlEncode(user));
    CharSequence styledCheckCode = Html.fromHtml(checkCodeMessage);
    mCheckCodeTextView.setText(styledCheckCode);
    mCheckCodeTextView.setVisibility(View.VISIBLE);
    findViewById(R.id.code_area).setVisibility(View.VISIBLE);
  }
 @Override
 protected void tearDown() throws Exception {
   DependencyInjector.close();
   super.tearDown();
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   DependencyInjector.resetForIntegrationTesting(getInstrumentation().getTargetContext());
   TestUtilities.withLaunchPreventingStartActivityListenerInDependencyResolver();
 }