### Question:
KubernetesUtils { public static boolean isFirstNewer(V1ObjectMeta first, V1ObjectMeta second) { if (second == null) { return true; } if (first == null) { return false; } DateTime time1 = first.getCreationTimestamp(); DateTime time2 = second.getCreationTimestamp(); if (time1.equals(time2)) { return getResourceVersion(first).compareTo(getResourceVersion(second)) > 0; } else { return time1.isAfter(time2); } }  static boolean isFirstNewer(V1ObjectMeta first, V1ObjectMeta second); static BigInteger getResourceVersion(V1ObjectMeta metadata); static BigInteger getResourceVersion(String resVersion); static V1ObjectMeta withOperatorLabels(String uid, V1ObjectMeta meta);  }### Answer:
@Test public void whenCreationTimesDiffer_metadataWithLaterTimeIsNewer() { V1ObjectMeta meta1 = new V1ObjectMeta().creationTimestamp(new DateTime(2)).resourceVersion("2"); V1ObjectMeta meta2 = new V1ObjectMeta().creationTimestamp(new DateTime(1)).resourceVersion("1"); assertThat(KubernetesUtils.isFirstNewer(meta1, meta2), is(true)); assertThat(KubernetesUtils.isFirstNewer(meta2, meta1), is(false)); }
@Test public void whenCreationTimesMatch_metadataWithHigherResourceVersionIsNewer() { V1ObjectMeta meta1 = new V1ObjectMeta().creationTimestamp(new DateTime(1)).resourceVersion("2"); V1ObjectMeta meta2 = new V1ObjectMeta().creationTimestamp(new DateTime(1)).resourceVersion("1"); assertThat(KubernetesUtils.isFirstNewer(meta1, meta2), is(true)); assertThat(KubernetesUtils.isFirstNewer(meta2, meta1), is(false)); }
@Test public void whenCreationTimesAndResourceVersionsMatch_neitherIsNewer() { V1ObjectMeta meta1 = new V1ObjectMeta().creationTimestamp(new DateTime(1)).resourceVersion("2"); V1ObjectMeta meta2 = new V1ObjectMeta().creationTimestamp(new DateTime(1)).resourceVersion("2"); assertThat(KubernetesUtils.isFirstNewer(meta2, meta1), is(false)); assertThat(KubernetesUtils.isFirstNewer(meta1, meta2), is(false)); }
@Test public void whenHaveLargeResourceVersionsAndSameTime_succeedIsFirstNewer() { DateTime now = DateTime.now(); String resVersion = "2733280673"; String evenBiggerResVersion = "2733280673000"; V1ObjectMeta first = new V1ObjectMeta().creationTimestamp(now).resourceVersion(resVersion); V1ObjectMeta second = new V1ObjectMeta().creationTimestamp(now).resourceVersion(evenBiggerResVersion); assertThat(KubernetesUtils.isFirstNewer(first, second), is(false)); }
@Test public void whenHaveNonParsableResourceVersionsAndSameTime_succeedIsFirstNewer() { DateTime now = DateTime.now(); String resVersion = "ThisIsNotANumber"; String differentResVersion = "SomeOtherValueAlsoNotANumber"; V1ObjectMeta first = new V1ObjectMeta().creationTimestamp(now).resourceVersion(resVersion); V1ObjectMeta second = new V1ObjectMeta().creationTimestamp(now).resourceVersion(differentResVersion); assertThat(KubernetesUtils.isFirstNewer(first, second), is(false)); }