LeaseLock implements Lock { @Override public <C extends Namespaceable<C> & KubernetesClient> void create( C client, LeaderElectionRecord leaderElectionRecord) throws LockException { try { client.inNamespace(leaseNamespace).leases().withName(leaseName).createNew() .withNewMetadata().withNamespace(leaseNamespace).withName(leaseName).endMetadata() .withNewSpec() .withHolderIdentity(leaderElectionRecord.getHolderIdentity()) .withLeaseDurationSeconds((int)leaderElectionRecord.getLeaseDuration().get(ChronoUnit.SECONDS)) .withAcquireTime(leaderElectionRecord.getAcquireTime()) .withRenewTime(leaderElectionRecord.getRenewTime()) .withLeaseTransitions(leaderElectionRecord.getLeaderTransitions()) .endSpec() .done(); } catch (Exception e) { throw new LockException("Unable to create LeaseLock", e); } } LeaseLock(String leaseNamespace, String leaseName, String identity); @Override LeaderElectionRecord get(C client); @Override void create(
    C client, LeaderElectionRecord leaderElectionRecord); @Override void update(
    C client, LeaderElectionRecord leaderElectionRecord); @Override String identity(); @Override String describe();  }
@Test void createWithValidLeaderElectionRecordShouldSendPostRequest() throws Exception { when(metadata.withNamespace("namespace").withName("name").endMetadata()).thenReturn(doneableLease); when(spec .withHolderIdentity(eq("1")) .withLeaseDurationSeconds(eq(1)) .withAcquireTime(any()) .withRenewTime(any()) .withLeaseTransitions(anyInt()) .endSpec() ).thenReturn(doneableLease); final LeaderElectionRecord record = new LeaderElectionRecord( "1", Duration.ofSeconds(1), ZonedDateTime.now(), ZonedDateTime.now(), 0); final LeaseLock lock = new LeaseLock("namespace", "name", "1337"); lock.create(kc, record); verify(doneableLease, times(1)).done(); }