@Test public void signTest() { ECKeyPair keyPair = mock(ECKeyPair.class); ECDSASignature ecSignature = mock(ECDSASignature.class); EUID euid = mock(EUID.class); when(keyPair.sign(any(Hash.class))).thenReturn(ecSignature); when(keyPair.euid()).thenReturn(euid); Atom signedAtom = mock(Atom.class); when(signedAtom.getSignature(any())).thenReturn(Optional.of(ecSignature)); Hash hash = mock(Hash.class); Atom atom = mock(Atom.class); when(atom.addSignature(any(), any())).thenReturn(signedAtom); when(atom.getHash()).thenReturn(hash); LocalRadixIdentity identity = new LocalRadixIdentity(keyPair); TestObserver<Atom> testObserver = TestObserver.create(); identity.addSignature(atom).subscribe(testObserver); verify(keyPair, never()).getPrivateKey(); testObserver.assertValue(a -> a.getSignature(euid).get().equals(ecSignature)); }
@Override public Single<Atom> addSignature(Atom atom) { return Single.create(emitter -> { final Atom signedAtom = syncAddSignature(atom); emitter.onSuccess(signedAtom); }); }
LocalRadixIdentity implements RadixIdentity { @Override public Single<Atom> addSignature(Atom atom) { return Single.create(emitter -> { final Atom signedAtom = syncAddSignature(atom); emitter.onSuccess(signedAtom); }); } }
LocalRadixIdentity implements RadixIdentity { @Override public Single<Atom> addSignature(Atom atom) { return Single.create(emitter -> { final Atom signedAtom = syncAddSignature(atom); emitter.onSuccess(signedAtom); }); } LocalRadixIdentity(ECKeyPair myKey); }
LocalRadixIdentity implements RadixIdentity { @Override public Single<Atom> addSignature(Atom atom) { return Single.create(emitter -> { final Atom signedAtom = syncAddSignature(atom); emitter.onSuccess(signedAtom); }); } LocalRadixIdentity(ECKeyPair myKey); Atom syncAddSignature(Atom atom); @Override Single<Atom> addSignature(Atom atom); @Override Single<UnencryptedData> decrypt(Data data); @Override ECPublicKey getPublicKey(); }
LocalRadixIdentity implements RadixIdentity { @Override public Single<Atom> addSignature(Atom atom) { return Single.create(emitter -> { final Atom signedAtom = syncAddSignature(atom); emitter.onSuccess(signedAtom); }); } LocalRadixIdentity(ECKeyPair myKey); Atom syncAddSignature(Atom atom); @Override Single<Atom> addSignature(Atom atom); @Override Single<UnencryptedData> decrypt(Data data); @Override ECPublicKey getPublicKey();  }