protected static int castToIntSafely(long value) {
    if (value > Integer.MAX_VALUE) {
      return Integer.MAX_VALUE;
    }
    return Long.valueOf(value).intValue();
  }
@Test
  void testCastToIntSafely() {
    assertEquals(0, Resource.castToIntSafely(0));
    assertEquals(1, Resource.castToIntSafely(1));
    assertEquals(Integer.MAX_VALUE,
        Resource.castToIntSafely(Integer.MAX_VALUE));

    assertEquals(Integer.MAX_VALUE,
        Resource.castToIntSafely(Integer.MAX_VALUE + 1L),
        "Cast to Integer.MAX_VALUE if the long is greater than "
            + "Integer.MAX_VALUE");
    assertEquals(Integer.MAX_VALUE,
        Resource.castToIntSafely(Long.MAX_VALUE),
        "Cast to Integer.MAX_VALUE if the long is greater than "
            + "Integer.MAX_VALUE");
  }