PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/app/src/test/java/info/blockchain/wallet/viewModel/PinEntryViewModelTest.java

https://gitlab.com/github-cloud-corporation/My-Wallet-V3-Android
Java | 593 lines | 434 code | 59 blank | 100 comment | 0 complexity | dcb47003b041f65ae9c77b30a05bbfd0 MD5 | raw file
  1. package info.blockchain.wallet.viewModel;
  2. import android.app.Application;
  3. import android.content.Intent;
  4. import android.view.View;
  5. import android.widget.TextView;
  6. import info.blockchain.wallet.callbacks.DialogButtonCallback;
  7. import info.blockchain.wallet.datamanagers.AuthDataManager;
  8. import info.blockchain.wallet.payload.Account;
  9. import info.blockchain.wallet.payload.HDWallet;
  10. import info.blockchain.wallet.payload.Payload;
  11. import info.blockchain.wallet.payload.PayloadManager;
  12. import info.blockchain.wallet.util.AppUtil;
  13. import info.blockchain.wallet.util.CharSequenceX;
  14. import info.blockchain.wallet.util.PrefsUtil;
  15. import info.blockchain.wallet.util.StringUtils;
  16. import info.blockchain.wallet.view.PinEntryActivity;
  17. import org.junit.Before;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import org.mockito.Mock;
  21. import org.mockito.MockitoAnnotations;
  22. import org.robolectric.RobolectricGradleTestRunner;
  23. import org.robolectric.RuntimeEnvironment;
  24. import org.robolectric.annotation.Config;
  25. import java.util.ArrayList;
  26. import piuk.blockchain.android.BlockchainTestApplication;
  27. import piuk.blockchain.android.BuildConfig;
  28. import piuk.blockchain.android.di.ApiModule;
  29. import piuk.blockchain.android.di.ApplicationModule;
  30. import piuk.blockchain.android.di.DataManagerModule;
  31. import piuk.blockchain.android.di.Injector;
  32. import piuk.blockchain.android.di.InjectorTestUtils;
  33. import rx.Observable;
  34. import static info.blockchain.wallet.view.CreateWalletFragment.KEY_INTENT_EMAIL;
  35. import static info.blockchain.wallet.view.CreateWalletFragment.KEY_INTENT_PASSWORD;
  36. import static org.junit.Assert.assertEquals;
  37. import static org.junit.Assert.assertFalse;
  38. import static org.mockito.Matchers.any;
  39. import static org.mockito.Matchers.anyInt;
  40. import static org.mockito.Matchers.anyString;
  41. import static org.mockito.Mockito.doAnswer;
  42. import static org.mockito.Mockito.mock;
  43. import static org.mockito.Mockito.times;
  44. import static org.mockito.Mockito.verify;
  45. import static org.mockito.Mockito.verifyZeroInteractions;
  46. import static org.mockito.Mockito.when;
  47. @Config(sdk = 23, constants = BuildConfig.class, application = BlockchainTestApplication.class)
  48. @RunWith(RobolectricGradleTestRunner.class)
  49. public class PinEntryViewModelTest {
  50. private PinEntryViewModel mSubject;
  51. @Mock private PinEntryActivity mActivity;
  52. @Mock private AuthDataManager mAuthDataManager;
  53. @Mock private AppUtil mAppUtil;
  54. @Mock private PrefsUtil mPrefsUtil;
  55. @Mock private PayloadManager mPayloadManager;
  56. @Mock private StringUtils mStringUtils;
  57. @Before
  58. public void setUp() throws Exception {
  59. MockitoAnnotations.initMocks(this);
  60. InjectorTestUtils.initApplicationComponent(
  61. Injector.getInstance(),
  62. new MockApplicationModule(RuntimeEnvironment.application),
  63. new MockApiModule(),
  64. new MockDataManagerModule());
  65. TextView mockTextView = mock(TextView.class);
  66. when(mActivity.getPinBoxArray()).thenReturn(new TextView[]{mockTextView, mockTextView, mockTextView, mockTextView});
  67. mSubject = new PinEntryViewModel(mActivity);
  68. }
  69. @Test
  70. public void onViewReadyEmailAndPasswordInIntentCreateWalletSuccessful() throws Exception {
  71. // Arrange
  72. String email = "example@email.com";
  73. String password = "1234567890";
  74. Intent intent = new Intent();
  75. intent.putExtra(KEY_INTENT_EMAIL, email);
  76. intent.putExtra(KEY_INTENT_PASSWORD, password);
  77. when(mActivity.getPageIntent()).thenReturn(intent);
  78. when(mAuthDataManager.createHdWallet(anyString(), anyString())).thenReturn(Observable.just(new Payload()));
  79. // Act
  80. mSubject.onViewReady();
  81. // Assert
  82. assertEquals(false, mSubject.allowExit());
  83. verify(mActivity).showProgressDialog(anyInt(), anyString());
  84. verify(mActivity).dismissProgressDialog();
  85. verify(mPrefsUtil).setValue(PrefsUtil.KEY_EMAIL, email);
  86. verify(mPayloadManager).setEmail(email);
  87. verify(mPayloadManager).setTempPassword(new CharSequenceX(password));
  88. }
  89. @Test
  90. public void onViewReadyEmailAndPasswordInIntentCreateWalletFails() throws Exception {
  91. // Arrange
  92. String email = "example@email.com";
  93. String password = "1234567890";
  94. Intent intent = new Intent();
  95. intent.putExtra(KEY_INTENT_EMAIL, email);
  96. intent.putExtra(KEY_INTENT_PASSWORD, password);
  97. when(mActivity.getPageIntent()).thenReturn(intent);
  98. when(mAuthDataManager.createHdWallet(anyString(), anyString())).thenReturn(Observable.just(null));
  99. // Act
  100. mSubject.onViewReady();
  101. // Assert
  102. assertEquals(false, mSubject.allowExit());
  103. verify(mActivity).showProgressDialog(anyInt(), anyString());
  104. verify(mActivity, times(2)).dismissProgressDialog();
  105. //noinspection WrongConstant
  106. verify(mActivity).showToast(anyInt(), anyString());
  107. }
  108. @Test
  109. public void onViewReadyEmailAndPasswordInIntentCreateWalletThrowsError() throws Exception {
  110. // Arrange
  111. String email = "example@email.com";
  112. String password = "1234567890";
  113. Intent intent = new Intent();
  114. intent.putExtra(KEY_INTENT_EMAIL, email);
  115. intent.putExtra(KEY_INTENT_PASSWORD, password);
  116. when(mActivity.getPageIntent()).thenReturn(intent);
  117. when(mAuthDataManager.createHdWallet(anyString(), anyString())).thenReturn(Observable.error(new Throwable()));
  118. // Act
  119. mSubject.onViewReady();
  120. // Assert
  121. assertEquals(false, mSubject.allowExit());
  122. verify(mActivity).showProgressDialog(anyInt(), anyString());
  123. verify(mActivity, times(2)).dismissProgressDialog();
  124. //noinspection WrongConstant
  125. verify(mActivity).showToast(anyInt(), anyString());
  126. }
  127. @Test
  128. public void onViewReadyMaxAttemptsExceeded() throws Exception {
  129. // Arrange
  130. when(mActivity.getPageIntent()).thenReturn(new Intent());
  131. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_FAILS, 0)).thenReturn(4);
  132. when(mPayloadManager.getPayload()).thenReturn(mock(Payload.class));
  133. // Act
  134. mSubject.onViewReady();
  135. // Assert
  136. assertEquals(true, mSubject.allowExit());
  137. //noinspection WrongConstant
  138. verify(mActivity).showToast(anyInt(), anyString());
  139. verify(mActivity).showMaxAttemptsDialog();
  140. verify(mPayloadManager).getPayload();
  141. }
  142. @Test
  143. public void onDeleteClicked() throws Exception {
  144. // Arrange
  145. mSubject.mUserEnteredPin = "1234";
  146. // Act
  147. mSubject.onDeleteClicked();
  148. // Assert
  149. assertEquals("123", mSubject.mUserEnteredPin);
  150. verify(mActivity).getPinBoxArray();
  151. }
  152. @Test
  153. public void padClickedPinAlreadyFourDigits() throws Exception {
  154. // Arrange
  155. mSubject.mUserEnteredPin = "0000";
  156. // Act
  157. View mockView = mock(View.class);
  158. when(mockView.getTag()).thenReturn("0");
  159. mSubject.padClicked(mockView);
  160. // Assert
  161. verifyZeroInteractions(mActivity);
  162. }
  163. @Test
  164. public void padClickedAllZeros() throws Exception {
  165. // Arrange
  166. mSubject.mUserEnteredPin = "000";
  167. // Act
  168. View mockView = mock(View.class);
  169. when(mockView.getTag()).thenReturn("0");
  170. mSubject.padClicked(mockView);
  171. // Assert
  172. verify(mActivity).clearPinBoxes();
  173. //noinspection WrongConstant
  174. verify(mActivity).showToast(anyInt(), anyString());
  175. assertEquals("", mSubject.mUserEnteredPin);
  176. assertEquals(null, mSubject.mUserEnteredConfirmationPin);
  177. }
  178. @Test
  179. public void padClickedShowCommonPinWarning() throws Exception {
  180. // Arrange
  181. mSubject.mUserEnteredPin = "123";
  182. when(mPrefsUtil.getValue(anyString(), anyString())).thenReturn("");
  183. // Act
  184. View mockView = mock(View.class);
  185. when(mockView.getTag()).thenReturn("4");
  186. mSubject.padClicked(mockView);
  187. // Assert
  188. verify(mActivity).showCommonPinWarning(any(DialogButtonCallback.class));
  189. }
  190. @Test
  191. public void padClickedShowCommonPinWarningAndClickRetry() throws Exception {
  192. // Arrange
  193. mSubject.mUserEnteredPin = "123";
  194. when(mPrefsUtil.getValue(anyString(), anyString())).thenReturn("");
  195. doAnswer(invocation -> {
  196. ((DialogButtonCallback) invocation.getArguments()[0]).onPositiveClicked();
  197. return null;
  198. }).when(mActivity).showCommonPinWarning(any(DialogButtonCallback.class));
  199. // Act
  200. View mockView = mock(View.class);
  201. when(mockView.getTag()).thenReturn("4");
  202. mSubject.padClicked(mockView);
  203. // Assert
  204. verify(mActivity).showCommonPinWarning(any(DialogButtonCallback.class));
  205. verify(mActivity).clearPinBoxes();
  206. assertEquals("", mSubject.mUserEnteredPin);
  207. assertEquals(null, mSubject.mUserEnteredConfirmationPin);
  208. }
  209. @Test
  210. public void padClickedShowCommonPinWarningAndClickContinue() throws Exception {
  211. // Arrange
  212. mSubject.mUserEnteredPin = "123";
  213. when(mPrefsUtil.getValue(anyString(), anyString())).thenReturn("");
  214. doAnswer(invocation -> {
  215. ((DialogButtonCallback) invocation.getArguments()[0]).onNegativeClicked();
  216. return null;
  217. }).when(mActivity).showCommonPinWarning(any(DialogButtonCallback.class));
  218. // Act
  219. View mockView = mock(View.class);
  220. when(mockView.getTag()).thenReturn("4");
  221. mSubject.padClicked(mockView);
  222. // Assert
  223. verify(mActivity).showCommonPinWarning(any(DialogButtonCallback.class));
  224. assertEquals("", mSubject.mUserEnteredPin);
  225. assertEquals("1234", mSubject.mUserEnteredConfirmationPin);
  226. }
  227. @Test
  228. public void padClickedVerifyPinValidateCalled() throws Exception {
  229. // Arrange
  230. mSubject.mUserEnteredPin = "133";
  231. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("1234567890");
  232. when(mAuthDataManager.validatePin(anyString())).thenReturn(Observable.just(new CharSequenceX("")));
  233. // Act
  234. View mockView = mock(View.class);
  235. when(mockView.getTag()).thenReturn("7");
  236. mSubject.padClicked(mockView);
  237. // Assert
  238. verify(mActivity).setTitleVisibility(View.INVISIBLE);
  239. verify(mActivity, times(2)).showProgressDialog(anyInt(), anyString());
  240. verify(mAuthDataManager).validatePin(anyString());
  241. }
  242. @Test
  243. public void padClickedVerifyPinValidateCalledReturnsNullIncrementsFailureCount() throws Exception {
  244. // Arrange
  245. mSubject.mUserEnteredPin = "133";
  246. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("1234567890");
  247. when(mAuthDataManager.validatePin(anyString())).thenReturn(Observable.just(null));
  248. // Act
  249. View mockView = mock(View.class);
  250. when(mockView.getTag()).thenReturn("7");
  251. mSubject.padClicked(mockView);
  252. // Assert
  253. verify(mActivity).setTitleVisibility(View.INVISIBLE);
  254. verify(mActivity).showProgressDialog(anyInt(), anyString());
  255. verify(mAuthDataManager).validatePin(anyString());
  256. verify(mPrefsUtil).setValue(anyString(), anyInt());
  257. verify(mPrefsUtil).getValue(anyString(), anyInt());
  258. //noinspection WrongConstant
  259. verify(mActivity).showToast(anyInt(), anyString());
  260. verify(mActivity).restartPage();
  261. }
  262. @Test
  263. public void padClickedCreatePinCreateSuccessful() throws Exception {
  264. // Arrange
  265. mSubject.mUserEnteredPin = "133";
  266. mSubject.mUserEnteredConfirmationPin = "1337";
  267. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("");
  268. when(mAuthDataManager.createPin(any(CharSequenceX.class), anyString())).thenReturn(Observable.just(true));
  269. // Act
  270. View mockView = mock(View.class);
  271. when(mockView.getTag()).thenReturn("7");
  272. mSubject.padClicked(mockView);
  273. // Assert
  274. verify(mActivity, times(2)).showProgressDialog(anyInt(), anyString());
  275. verify(mAuthDataManager).createPin(any(CharSequenceX.class), anyString());
  276. }
  277. @Test
  278. public void padClickedCreatePinCreateFailed() throws Exception {
  279. // Arrange
  280. mSubject.mUserEnteredPin = "133";
  281. mSubject.mUserEnteredConfirmationPin = "1337";
  282. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("");
  283. when(mAuthDataManager.createPin(any(CharSequenceX.class), anyString())).thenReturn(Observable.just(false));
  284. // Act
  285. View mockView = mock(View.class);
  286. when(mockView.getTag()).thenReturn("7");
  287. mSubject.padClicked(mockView);
  288. // Assert
  289. verify(mActivity).showProgressDialog(anyInt(), anyString());
  290. verify(mAuthDataManager).createPin(any(CharSequenceX.class), anyString());
  291. //noinspection WrongConstant
  292. verify(mActivity).showToast(anyInt(), anyString());
  293. verify(mPrefsUtil).clear();
  294. verify(mAppUtil).restartApp();
  295. }
  296. @Test
  297. public void padClickedCreatePinWritesNewConfirmationValue() throws Exception {
  298. // Arrange
  299. mSubject.mUserEnteredPin = "133";
  300. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("");
  301. when(mAuthDataManager.createPin(any(CharSequenceX.class), anyString())).thenReturn(Observable.just(true));
  302. // Act
  303. View mockView = mock(View.class);
  304. when(mockView.getTag()).thenReturn("7");
  305. mSubject.padClicked(mockView);
  306. // Assert
  307. assertEquals("1337", mSubject.mUserEnteredConfirmationPin);
  308. assertEquals("", mSubject.mUserEnteredPin);
  309. }
  310. @Test
  311. public void padClickedCreatePinMismatched() throws Exception {
  312. // Arrange
  313. mSubject.mUserEnteredPin = "133";
  314. mSubject.mUserEnteredConfirmationPin = "1234";
  315. when(mPrefsUtil.getValue(PrefsUtil.KEY_PIN_IDENTIFIER, "")).thenReturn("");
  316. when(mAuthDataManager.createPin(any(CharSequenceX.class), anyString())).thenReturn(Observable.just(true));
  317. // Act
  318. View mockView = mock(View.class);
  319. when(mockView.getTag()).thenReturn("7");
  320. mSubject.padClicked(mockView);
  321. // Assert
  322. //noinspection WrongConstant
  323. verify(mActivity).showToast(anyInt(), anyString());
  324. verify(mActivity).dismissProgressDialog();
  325. }
  326. @Test
  327. public void clearPinBoxes() throws Exception {
  328. // Arrange
  329. // Act
  330. mSubject.clearPinBoxes();
  331. // Assert
  332. verify(mActivity).clearPinBoxes();
  333. assertEquals("", mSubject.mUserEnteredPin);
  334. }
  335. @Test
  336. public void validatePasswordSuccessful() throws Exception {
  337. // Arrange
  338. CharSequenceX password = new CharSequenceX("1234567890");
  339. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.just(null));
  340. // Act
  341. mSubject.validatePassword(password);
  342. // Assert
  343. verify(mActivity).showProgressDialog(anyInt(), anyString());
  344. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  345. verify(mPayloadManager).setTempPassword(new CharSequenceX(""));
  346. verify(mActivity).dismissProgressDialog();
  347. //noinspection WrongConstant
  348. verify(mActivity).showToast(anyInt(), anyString());
  349. verify(mPrefsUtil, times(2)).removeValue(anyString());
  350. verify(mActivity).restartPage();
  351. }
  352. @Test
  353. public void validatePasswordThrowsException() throws Exception {
  354. // Arrange
  355. CharSequenceX password = new CharSequenceX("1234567890");
  356. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.error(new Throwable()));
  357. // Act
  358. mSubject.validatePassword(password);
  359. // Assert
  360. verify(mActivity).showProgressDialog(anyInt(), anyString());
  361. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  362. verify(mPayloadManager).setTempPassword(new CharSequenceX(""));
  363. verify(mActivity).dismissProgressDialog();
  364. //noinspection WrongConstant
  365. verify(mActivity).showToast(anyInt(), anyString());
  366. verify(mActivity).showValidationDialog();
  367. }
  368. @Test
  369. public void updatePayloadSuccessfulVersionNotSupported() throws Exception {
  370. // Arrange
  371. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.just(null));
  372. Payload mockPayload = mock(Payload.class);
  373. when(mockPayload.getSharedKey()).thenReturn("1234567890");
  374. when(mPayloadManager.getPayload()).thenReturn(mockPayload);
  375. when(mPayloadManager.getVersion()).thenReturn(5.0d);
  376. // Act
  377. mSubject.updatePayload(new CharSequenceX(""));
  378. // Assert
  379. verify(mActivity).showProgressDialog(anyInt(), anyString());
  380. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  381. verify(mAppUtil).setSharedKey(anyString());
  382. verify(mActivity).showWalletVersionNotSupportedDialog(anyInt());
  383. }
  384. @Test
  385. public void updatePayloadSuccessfulSetLabels() throws Exception {
  386. // Arrange
  387. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.just(null));
  388. Payload mockPayload = mock(Payload.class);
  389. when(mockPayload.getSharedKey()).thenReturn("1234567890");
  390. HDWallet mockHdWallet = mock(HDWallet.class);
  391. when(mockPayload.getHdWallet()).thenReturn(mockHdWallet);
  392. Account mockAccount = mock(Account.class);
  393. when(mockAccount.getLabel()).thenReturn(null);
  394. ArrayList<Account> accountsList = new ArrayList<>();
  395. accountsList.add(mockAccount);
  396. when(mockHdWallet.getAccounts()).thenReturn(accountsList);
  397. when(mPayloadManager.getPayload()).thenReturn(mockPayload);
  398. when(mockPayload.isUpgraded()).thenReturn(true);
  399. when(mAppUtil.isNewlyCreated()).thenReturn(true);
  400. // Act
  401. mSubject.updatePayload(new CharSequenceX(""));
  402. // Assert
  403. verify(mActivity).showProgressDialog(anyInt(), anyString());
  404. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  405. verify(mAppUtil).setSharedKey(anyString());
  406. verify(mPayloadManager, times(5)).getPayload();
  407. verify(mStringUtils).getString(anyInt());
  408. }
  409. @Test
  410. public void updatePayloadSuccessfulUpgradeWallet() throws Exception {
  411. // Arrange
  412. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.just(null));
  413. Payload mockPayload = mock(Payload.class);
  414. when(mockPayload.getSharedKey()).thenReturn("1234567890");
  415. when(mPayloadManager.getPayload()).thenReturn(mockPayload);
  416. when(mockPayload.isUpgraded()).thenReturn(false);
  417. when(mAppUtil.isNewlyCreated()).thenReturn(false);
  418. // Act
  419. mSubject.updatePayload(new CharSequenceX(""));
  420. // Assert
  421. verify(mActivity).showProgressDialog(anyInt(), anyString());
  422. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  423. verify(mAppUtil).setSharedKey(anyString());
  424. verify(mActivity).goToUpgradeWalletActivity();
  425. }
  426. @Test
  427. public void updatePayloadSuccessfulVerifyPin() throws Exception {
  428. // Arrange
  429. when(mAuthDataManager.updatePayload(anyString(), anyString(), any(CharSequenceX.class))).thenReturn(Observable.just(null));
  430. Payload mockPayload = mock(Payload.class);
  431. when(mockPayload.getSharedKey()).thenReturn("1234567890");
  432. when(mPayloadManager.getPayload()).thenReturn(mockPayload);
  433. when(mockPayload.isUpgraded()).thenReturn(true);
  434. when(mAppUtil.isNewlyCreated()).thenReturn(false);
  435. // Act
  436. mSubject.updatePayload(new CharSequenceX(""));
  437. // Assert
  438. verify(mActivity).showProgressDialog(anyInt(), anyString());
  439. verify(mAuthDataManager).updatePayload(anyString(), anyString(), any(CharSequenceX.class));
  440. verify(mAppUtil).setSharedKey(anyString());
  441. verify(mAppUtil).restartAppWithVerifiedPin();
  442. }
  443. @Test
  444. public void incrementFailureCount() throws Exception {
  445. // Arrange
  446. // Act
  447. mSubject.incrementFailureCount();
  448. // Assert
  449. verify(mPrefsUtil).getValue(anyString(), anyInt());
  450. verify(mPrefsUtil).setValue(anyString(), anyInt());
  451. //noinspection WrongConstant
  452. verify(mActivity).showToast(anyInt(), anyString());
  453. verify(mActivity).restartPage();
  454. }
  455. @Test
  456. public void resetApp() throws Exception {
  457. // Arrange
  458. // Act
  459. mSubject.resetApp();
  460. // Assert
  461. verify(mAppUtil).clearCredentialsAndRestart();
  462. }
  463. @Test
  464. public void allowExit() throws Exception {
  465. // Arrange
  466. // Act
  467. boolean allowExit = mSubject.allowExit();
  468. // Assert
  469. assertEquals(mSubject.bAllowExit, allowExit);
  470. }
  471. @Test
  472. public void isCreatingNewPin() throws Exception {
  473. // Arrange
  474. when(mPrefsUtil.getValue(anyString(), anyString())).thenReturn("");
  475. // Act
  476. boolean creatingNewPin = mSubject.isCreatingNewPin();
  477. // Assert
  478. assertEquals(true, creatingNewPin);
  479. }
  480. @Test
  481. public void isNotCreatingNewPin() throws Exception {
  482. // Arrange
  483. when(mPrefsUtil.getValue(anyString(), anyString())).thenReturn("1234567890");
  484. // Act
  485. boolean creatingNewPin = mSubject.isCreatingNewPin();
  486. // Assert
  487. assertEquals(false, creatingNewPin);
  488. }
  489. @Test
  490. public void getAppUtil() throws Exception {
  491. // Arrange
  492. // Act
  493. AppUtil util = mSubject.getAppUtil();
  494. // Assert
  495. assertEquals(util, mAppUtil);
  496. }
  497. @Test
  498. public void destroy() throws Exception {
  499. // Arrange
  500. // Act
  501. mSubject.destroy();
  502. // Assert
  503. assertFalse(mSubject.mCompositeSubscription.hasSubscriptions());
  504. }
  505. private class MockApplicationModule extends ApplicationModule {
  506. MockApplicationModule(Application application) {
  507. super(application);
  508. }
  509. @Override
  510. protected AppUtil provideAppUtil() {
  511. return mAppUtil;
  512. }
  513. @Override
  514. protected PrefsUtil providePrefsUtil() {
  515. return mPrefsUtil;
  516. }
  517. @Override
  518. protected StringUtils provideStringUtils() {
  519. return mStringUtils;
  520. }
  521. }
  522. private class MockApiModule extends ApiModule {
  523. @Override
  524. protected PayloadManager providePayloadManager() {
  525. return mPayloadManager;
  526. }
  527. }
  528. private class MockDataManagerModule extends DataManagerModule {
  529. @Override
  530. protected AuthDataManager provideAuthDataManager() {
  531. return mAuthDataManager;
  532. }
  533. }
  534. }