### Question:
KeyStoreImpl implements KeyStore { @NonNull @Override public List<KeyPair> loadAccounts() throws LoadAccountException { ArrayList<KeyPair> accounts = new ArrayList<>(); try { JSONArray jsonArray = loadJsonArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject accountJson = jsonArray.getJSONObject(i); String seed = accountJson.getString(JSON_KEY_ENCRYPTED_SEED); accounts.add(KeyPair.fromSecretSeed(seed)); } } } catch (JSONException e) { throw new LoadAccountException(e.getMessage(), e); } return accounts; } KeyStoreImpl(@NonNull Store store, @NonNull BackupRestore backupRestore); @NonNull @Override List<KeyPair> loadAccounts(); @Override void deleteAccount(int index); @Override KeyPair newAccount(); @Override KeyPair importAccount(@NonNull String json, @NonNull String passphrase); @Override void clearAllAccounts();  }### Answer:
@Test public void loadAccounts_OldVersionData_DropOldData() throws Exception { FakeStore fakeStore = new FakeStore(); fakeStore.saveString(KeyStoreImpl.VERSION_KEY, "some_version"); fakeStore.saveString(KeyStoreImpl.STORE_KEY_ACCOUNTS, "{&quot;accounts&quot;:[{&quot;seed&quot;:&quot;{\\&quot;iv\\&quot;:\\&quot;nVGsoEHgjW4xw2gx\\\\n\\&quot;,\\&quot;cipher\\&quot;:\\&quot;kEC64vaQu\\\\\\/erpFvvnrY+sWm\\\\\\/o4GjmjPfgG31zQTwvp0taxo\\\\\\/04PoaisjfEQxrydRwBGFvG\\\\\\/nG345\\\\ntXMn+x2H0jnaPWWCznPA\\\\n\\&quot;}&quot;,&quot;public_key&quot;:&quot;GBYPGYWPWHWSVTQGTUCH2IICIP2PRLN3QYSUX5NOHHMNDQW26A4WK2IK&quot;}]}"); KeyStoreImpl keyStore = new KeyStoreImpl(fakeStore, new FakeBackupRestore()); keyStore.loadAccounts(); assertThat(fakeStore.getString(KeyStoreImpl.VERSION_KEY), equalTo(KeyStoreImpl.ENCRYPTION_VERSION_NAME)); assertThat(fakeStore.getString(KeyStoreImpl.STORE_KEY_ACCOUNTS), nullValue()); }
@Test public void loadAccounts() throws Exception { KeyStoreImpl keyStore = new KeyStoreImpl(new FakeStore(), new FakeBackupRestore()); KeyPair account1 = keyStore.newAccount(); KeyPair account2 = keyStore.newAccount(); List<KeyPair> accounts = keyStore.loadAccounts(); KeyPair actualAccount1 = accounts.get(0); KeyPair actualAccount2 = accounts.get(1); assertEquals(String.valueOf(account1.getSecretSeed()), String.valueOf(actualAccount1.getSecretSeed())); assertEquals(String.valueOf(account2.getSecretSeed()), String.valueOf(actualAccount2.getSecretSeed())); }
@Test public void loadAccounts_JsonException_LoadAccountException() throws Exception { Store mockStore = mock(Store.class); when(mockStore.getString(anyString())) .thenReturn(KeyStoreImpl.ENCRYPTION_VERSION_NAME) .thenReturn("not a real json"); KeyStoreImpl keyStore = new KeyStoreImpl(mockStore, new FakeBackupRestore()); expectedEx.expect(LoadAccountException.class); expectedEx.expectCause(isA(JSONException.class)); keyStore.loadAccounts(); }