@Test
public void testListObjectNamesCached() throws IOException {

  List<String> expected =
      Lists.newArrayList(
          ITEM_A_A.getObjectName(),
          ITEM_A_AA.getObjectName(),
          ITEM_A_ABA.getObjectName(),
          ITEM_A_B.getObjectName());
  List<GoogleCloudStorageItemInfo> expectedCached =
      Lists.newArrayList(ITEM_A_A, ITEM_A_AA, ITEM_A_ABA, ITEM_A_B);
  // First call to get the values in cache.
  gcs.listObjectNames(
      BUCKET_A, /* objectNamePrefix= */ null, ListObjectOptions.DEFAULT_FLAT_LIST);
  // Second call to ensure the values are being served from cache.
  List<String> result =
      gcs.listObjectNames(
          BUCKET_A, /* objectNamePrefix= */ null, ListObjectOptions.DEFAULT_FLAT_LIST);
  // Verify the delegate call once.
  verify(gcsDelegate, times(2))
      .listObjectNames(
          eq(BUCKET_A),
          ArgumentMatchers.eq(null),
          ArgumentMatchers.eq(ListObjectOptions.DEFAULT_FLAT_LIST));
  // Verify the result.
  assertThat(result).containsExactlyElementsIn(expected);
  // Verify the state of the cache.
  assertThat(cache.getAllItemsRaw()).containsExactlyElementsIn(expectedCached);
}