PackageUtils { public static String toString(@Nullable Package pack, @Nullable String defaultValue) { return pack != null ? pack.getName() : defaultValue; } private  PackageUtils(); static String getShortenPackage(Class<?> clazz); static String getShortenPackage(String pack); static @Nullable String getPackageName(Class<?> clazz); static String toString(@Nullable Package pack, @Nullable String defaultValue); static @Nullable String toString(@Nullable Package pkg);  }
@Test void toString1() { Assertions.assertEquals("java.lang", PackageUtils.toString(String.class.getPackage())); Assertions.assertNull(PackageUtils.toString(int.class.getPackage())); }
@Test void toString2() { Assertions.assertEquals("java.lang", PackageUtils.toString(String.class.getPackage(), null)); Assertions.assertEquals("null package", PackageUtils.toString(int.class.getPackage(), "null package")); }