LogUtils { public static String maskApiKey(final String key) { int visibleChars = (int) (0.1 * key.length()); int right = visibleChars / 2; int left = visibleChars - right; String beginning = key.substring(0, left); String end = key.substring(key.length() - right); return beginning + "..." + end; }  static String maskApiKey(final String key);  }
@Test public void maskApiKeyTest() { Assert.assertEquals("N708W...5015S", LogUtils.maskApiKey("N708W589120i0Tn984uwX6Z9c8582ccyN42Ah9PG18sO66bOCGf46sann382306D203304s2RowSA628G7KeWx1h2A8657H5015S")); Assert.assertEquals("PJGt...ube", LogUtils.maskApiKey("PJGttqarjMhhBYddWFKxwfZEqGERCDJCZHuveHwfUFJgokYfxupwKWyFHDGlcVRDCzgBDnRHeube")); Assert.assertEquals("ZZ...2", LogUtils.maskApiKey("ZZA0td8MG3RHW94ILyyz3ZLxzLrU3H02")); Assert.assertEquals("j...", LogUtils.maskApiKey("jCo0O0bJqDX4Qmi")); Assert.assertEquals("N...", LogUtils.maskApiKey("NAdompnPVE")); Assert.assertEquals("...", LogUtils.maskApiKey("m4Mm")); Assert.assertEquals("...", LogUtils.maskApiKey("")); }