### Question:
SimpleHDKeyChain implements EncryptableKeyChain, KeyBag { @Override public SimpleHDKeyChain toEncrypted(CharSequence password) { checkNotNull(password, "Attempt to encrypt with a null password."); checkArgument(password.length() > 0, "Attempt to encrypt with an empty password."); checkState(!rootKey.isEncrypted(), "Attempt to encrypt a root key that is already encrypted."); checkState(!rootKey.isPubKeyOnly(), "Attempt to encrypt a watching chain."); KeyCrypter scrypt = new KeyCrypterScrypt(); KeyParameter derivedKey = scrypt.deriveKey(password); return toEncrypted(scrypt, derivedKey); } SimpleHDKeyChain(DeterministicKey rootkey);   SimpleHDKeyChain(DeterministicKey rootkey, @Nullable KeyCrypter crypter);   SimpleHDKeyChain(DeterministicKey rootkey, @Nullable KeyCrypter crypter,
                     @Nullable KeyParameter key); private  SimpleHDKeyChain(KeyCrypter crypter, KeyParameter aesKey, SimpleHDKeyChain chain); boolean isEncrypted(); DeterministicKey getCurrentUnusedKey(KeyPurpose purpose); @Nullable DeterministicKey getLastIssuedKey(KeyPurpose purpose); @Override DeterministicKey getKey(KeyPurpose purpose); @Override List<DeterministicKey> getKeys(KeyPurpose purpose, int numberOfKeys); DeterministicKey markKeyAsUsed(DeterministicKey k); @Override DeterministicKey findKeyFromPubHash(byte[] pubkeyHash); @Override DeterministicKey findKeyFromPubKey(byte[] pubkey); @Nullable @Override RedeemData findRedeemDataFromScriptHash(byte[] bytes); boolean markPubHashAsUsed(byte[] pubkeyHash); boolean markPubKeyAsUsed(byte[] pubkey); @Override boolean hasKey(ECKey key); DeterministicKey getWatchingKey(); @Override int numKeys(); DeterministicKey getRootKey(); int numLeafKeysIssued(); @Override long getEarliestKeyCreationTime(); @Override void addEventListener(KeyChainEventListener listener); @Override void addEventListener(KeyChainEventListener listener, Executor executor); @Override boolean removeEventListener(KeyChainEventListener listener); boolean isFollowing(); static SimpleHDKeyChain fromProtobuf(List<Protos.Key> keys); static SimpleHDKeyChain fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter); @Override List<org.bitcoinj.wallet.Protos.Key> serializeToProtobuf(); @Override SimpleHDKeyChain toEncrypted(CharSequence password); @Override SimpleHDKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey); @Override SimpleHDKeyChain toDecrypted(CharSequence password); @Override SimpleHDKeyChain toDecrypted(KeyParameter aesKey); @Override boolean checkPassword(CharSequence password); @Override boolean checkAESKey(KeyParameter aesKey); @Nullable @Override KeyCrypter getKeyCrypter(); @Override int numBloomFilterEntries(); @Override BloomFilter getFilter(int size, double falsePositiveRate, long tweak); int getLookaheadSize(); void setLookaheadSize(int lookaheadSize); void setLookaheadThreshold(int num); int getLookaheadThreshold(); void maybeLookAhead(); ArrayList<DeterministicKey> getIssuedExternalKeys(); int getNumIssuedExternalKeys(); int getNumIssuedInternalKeys(); List<DeterministicKey> getActiveKeys(); boolean isExternal(DeterministicKey key); int getAccountIndex(); static final int LOOKAHEAD; static final ChildNumber EXTERNAL_PATH_NUM; static final ChildNumber INTERNAL_PATH_NUM; static final ImmutableList<ChildNumber> EXTERNAL_PATH; static final ImmutableList<ChildNumber> INTERNAL_PATH; }### Answer:
@Test(expected = IllegalStateException.class) public void encryptTwice() { chain = chain.toEncrypted("once"); chain = chain.toEncrypted("twice"); }