|
19 | 19 | import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
20 | 20 | import io.fabric8.kubernetes.client.KubernetesClient; |
21 | 21 | import io.fabric8.kubernetes.client.dsl.base.PatchContext; |
| 22 | +import org.assertj.core.api.InstanceOfAssertFactories; |
22 | 23 | import org.junit.jupiter.api.BeforeEach; |
23 | 24 | import org.junit.jupiter.api.Test; |
24 | 25 | import org.junit.jupiter.api.function.Executable; |
|
28 | 29 | import java.time.ZonedDateTime; |
29 | 30 | import java.util.Collections; |
30 | 31 |
|
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
31 | 33 | import static org.junit.jupiter.api.Assertions.assertEquals; |
32 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
33 | 34 | import static org.junit.jupiter.api.Assertions.assertThrows; |
34 | 35 | import static org.mockito.ArgumentMatchers.any; |
35 | 36 | import static org.mockito.Mockito.RETURNS_DEEP_STUBS; |
@@ -76,16 +77,18 @@ void getWithExistingConfigMapShouldReturnLeaderElectionRecord() { |
76 | 77 | cm.setMetadata(new ObjectMetaBuilder() |
77 | 78 | .withAnnotations( |
78 | 79 | Collections.singletonMap("control-plane.alpha.kubernetes.io/leader", |
79 | | - "{\"holderIdentity\":\"1337\",\"leaseDuration\":15,\"acquireTime\":1445401740,\"renewTime\":1445412480}")) |
| 80 | + "{\"holderIdentity\":\"1337\",\"leaseDuration\":15,\"acquireTime\":\"2015-10-21T04:29:00.000000Z\",\"renewTime\":\"2015-10-21T07:28:00.000000Z\"}")) |
80 | 81 | .withResourceVersion("313373").build()); |
81 | 82 | final ConfigMapLock lock = new ConfigMapLock("namespace", "name", "1337"); |
82 | 83 | // When |
83 | 84 | final LeaderElectionRecord result = lock.toRecord(cm); |
84 | 85 | // Then |
85 | | - assertNotNull(result); |
86 | | - assertEquals("1337", result.getHolderIdentity()); |
87 | | - assertEquals(15, result.getLeaseDuration().getSeconds()); |
88 | | - assertEquals(ZonedDateTime.of(2015, 10, 21, 4, 29, 0, 0, ZoneId.of("UTC")), result.getAcquireTime()); |
| 86 | + assertThat(result) |
| 87 | + .hasFieldOrPropertyWithValue("holderIdentity", "1337") |
| 88 | + .returns(15L, ler -> ler.getLeaseDuration().getSeconds()) |
| 89 | + .extracting(LeaderElectionRecord::getAcquireTime) |
| 90 | + .asInstanceOf(InstanceOfAssertFactories.ZONED_DATE_TIME) |
| 91 | + .isEqualTo(ZonedDateTime.of(2015, 10, 21, 4, 29, 0, 0, ZoneId.of("UTC"))); |
89 | 92 | } |
90 | 93 |
|
91 | 94 | @Test |
|
0 commit comments