### Question:
ProtectedStorageEntry implements NetworkPayload, PersistablePayload { public boolean isValidForRemoveOperation() { boolean result = this.isValidForAddOperation(); if (!result) { String res1 = this.toString(); String res2 = "null"; if (protectedStoragePayload.getOwnerPubKey() != null) res2 = Utilities.encodeToHex(protectedStoragePayload.getOwnerPubKey().getEncoded(), true); log.warn("ProtectedStorageEntry::isValidForRemoveOperation() failed. Entry owner does not match Payload owner:\n" + "ProtectedStorageEntry={}\nPayloadOwner={}", res1, res2); } return result; } ProtectedStorageEntry(@NotNull ProtectedStoragePayload protectedStoragePayload,
                                 @NotNull PublicKey ownerPubKey,
                                 int sequenceNumber,
                                 byte[] signature,
                                 Clock clock); protected  ProtectedStorageEntry(@NotNull ProtectedStoragePayload protectedStoragePayload,
                                    byte[] ownerPubKeyBytes,
                                    @NotNull PublicKey ownerPubKey,
                                    int sequenceNumber,
                                    byte[] signature,
                                    long creationTimeStamp,
                                    Clock clock); private  ProtectedStorageEntry(@NotNull ProtectedStoragePayload protectedStoragePayload,
                                  byte[] ownerPubKeyBytes,
                                  int sequenceNumber,
                                  byte[] signature,
                                  long creationTimeStamp,
                                  Clock clock); Message toProtoMessage(); protobuf.ProtectedStorageEntry toProtectedStorageEntry(); static ProtectedStorageEntry fromProto(protobuf.ProtectedStorageEntry proto,
                                                  NetworkProtoResolver resolver); void backDate(); boolean isExpired(Clock clock); boolean isValidForAddOperation(); boolean isValidForRemoveOperation(); boolean matchesRelevantPubKey(ProtectedStorageEntry protectedStorageEntry); @Override String toString();  }### Answer:
@Test public void isValidForRemoveOperation() throws NoSuchAlgorithmException, CryptoException { KeyPair ownerKeys = TestUtils.generateKeyPair(); ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry(ownerKeys, ownerKeys, 1); Assert.assertTrue(protectedStorageEntry.isValidForRemoveOperation()); }
@Test public void isValidForRemoveOperation_Mismatch() throws NoSuchAlgorithmException, CryptoException { KeyPair ownerKeys = TestUtils.generateKeyPair(); KeyPair notOwnerKeys = TestUtils.generateKeyPair(); ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry(ownerKeys, notOwnerKeys, 1); Assert.assertFalse(protectedStorageEntry.isValidForRemoveOperation()); }
@Test public void isValidForRemoveOperation_invalidMailboxPayloadSender() throws NoSuchAlgorithmException, CryptoException { KeyPair senderKeys = TestUtils.generateKeyPair(); KeyPair receiverKeys = TestUtils.generateKeyPair(); ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry( buildMailboxStoragePayload(senderKeys.getPublic(), receiverKeys.getPublic()), senderKeys, 1); Assert.assertTrue(protectedStorageEntry.isValidForRemoveOperation()); }
@Test public void isValidForRemoveOperation_invalidMailboxPayloadReceiver() throws NoSuchAlgorithmException, CryptoException { KeyPair senderKeys = TestUtils.generateKeyPair(); KeyPair receiverKeys = TestUtils.generateKeyPair(); ProtectedStorageEntry protectedStorageEntry = buildProtectedStorageEntry( buildMailboxStoragePayload(senderKeys.getPublic(), receiverKeys.getPublic()), receiverKeys, 1); Assert.assertFalse(protectedStorageEntry.isValidForRemoveOperation()); }
@Test public void isValidForRemoveOperation_BadSignature() throws NoSuchAlgorithmException { KeyPair ownerKeys = TestUtils.generateKeyPair(); ProtectedStoragePayload protectedStoragePayload = new ProtectedStoragePayloadStub(ownerKeys.getPublic()); ProtectedStorageEntry protectedStorageEntry = new ProtectedStorageEntry(protectedStoragePayload, ownerKeys.getPublic(), 1, new byte[] { 0 }, Clock.systemDefaultZone()); Assert.assertFalse(protectedStorageEntry.isValidForRemoveOperation()); }