コード例 #1
0
  @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();
  }
コード例 #2
0
  @Test
  public void openReturnsAutoSavingWallet() {
    // Arrange:
    final TestContext context = new TestContext();

    // Act:
    final Wallet wallet = context.walletServices.open(context.pair);
    wallet.addOtherAccount(new WalletAccount());

    // Assert:
    Mockito.verify(context.repository, Mockito.times(1))
        .save(context.descriptor, context.originalWallet);
  }
コード例 #3
0
  @Test
  public void createReturnsAutoSavingWallet() {
    // Arrange:
    final TestContext context = new TestContext();

    // Act:
    final Wallet wallet = context.walletServices.create(context.pair);
    wallet.addOtherAccount(new WalletAccount());

    // Assert:
    // TODO BR: Fix this
    // Mockito.verify(context.repository, Mockito.times(2)).save(context.descriptor, wallet);
    Mockito.verify(context.repository, Mockito.times(2)).save(Mockito.any(), Mockito.any());
  }
コード例 #4
0
  @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);
  }
コード例 #5
0
  @Test
  public void renamedWalletPreservesAccountInformation() {
    // Arrange:
    final WalletNamePasswordPair pair2 = createPair("n2", "p");
    final WalletDescriptor descriptor2 = createDescriptor("n2");
    final TestContext context = new TestContext();
    context.originalWallet.addOtherAccount(new WalletAccount());
    context.originalWallet.addOtherAccount(new WalletAccount());
    Mockito.when(context.descriptorFactory.createNew(pair2, FILE_EXTENSION))
        .thenReturn(descriptor2);

    // Act:
    context.walletServices.open(context.pair);
    context.walletServices.move(context.pair, pair2);

    // Assert:
    final Wallet updatedWallet = context.walletServices.get(new WalletName("n2"));
    Assert.assertThat(
        updatedWallet.getPrimaryAccount(),
        IsEqual.equalTo(context.originalWallet.getPrimaryAccount()));
    Assert.assertThat(
        updatedWallet.getOtherAccounts(),
        IsEquivalent.equivalentTo(context.originalWallet.getOtherAccounts()));
  }