@Test public void canChangeWalletNameAndPasswordIfWalletIsAlreadyOpen() { // Arrange: final WalletNamePasswordPair pair2 = createPair("n2", "p2"); final WalletDescriptor descriptor2 = createDescriptor("n2"); final TestContext context = new TestContext(); Mockito.when(context.descriptorFactory.createNew(pair2, FILE_EXTENSION)) .thenReturn(descriptor2); // Act: context.walletServices.open(context.pair); context.walletServices.move(context.pair, pair2); // Assert: // - the original is opened and the target is created Mockito.verify(context.descriptorFactory, Mockito.times(2)) .openExisting(context.pair, FILE_EXTENSION); Mockito.verify(context.descriptorFactory, Mockito.times(1)).createNew(pair2, FILE_EXTENSION); // - the original is loaded Mockito.verify(context.repository, Mockito.times(2)).load(context.descriptor); // - the target is saved final Wallet updatedWallet = context.walletServices.get(new WalletName("n2")); Assert.assertThat(updatedWallet.getName(), IsEqual.equalTo(new WalletName("n2"))); // TODO BR: Fix this // Mockito.verify(context.repository, Mockito.times(1)).save(descriptor2, updatedWallet); Mockito.verify(context.repository, Mockito.times(1)).save(Mockito.any(), Mockito.any()); // - the original wallet is deleted Mockito.verify(context.descriptor, Mockito.times(1)).delete(); }
@Test public void openLoadsWalletIfWalletIsNotOpened() { // Arrange: final TestContext context = new TestContext(); // Act: final Wallet wallet = context.walletServices.open(context.pair); // Assert: Assert.assertThat(wallet.getName(), IsEqual.equalTo(context.originalWallet.getName())); Assert.assertThat( context.walletServices.getOpenWalletNames(), IsEquivalent.equivalentTo(Collections.singletonList(context.originalWallet.getName()))); Mockito.verify(context.descriptorFactory, Mockito.times(1)) .openExisting(context.pair, FILE_EXTENSION); Mockito.verify(context.repository, Mockito.times(1)).load(context.descriptor); }