AlertManager { String generateAlertMessage(String dc, String cluster, String shard, ALERT_TYPE type, String message) { StringBuilder sb = new StringBuilder(); if(dc != null && !dc.isEmpty()) { sb.append(dc).append(","); } if(cluster != null && !cluster.isEmpty()) { sb.append(cluster).append(","); } if(shard != null && !shard.isEmpty()) { sb.append(shard).append(","); } if(type != null) { sb.append(type.simpleDesc()).append(","); } if(message != null && !message.isEmpty()) { sb.append(message); } else { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }  @PostConstruct void postConstruct(); void alert(String dc, String cluster, String shard, HostPort hostPort, ALERT_TYPE type, String message); void alert(RedisInstanceInfo info, ALERT_TYPE type, String message); void alert(String cluster, String shard, HostPort hostPort, ALERT_TYPE type, String message); @VisibleForTesting boolean shouldAlert(String cluster);  }
@Test public void testGenerateAlertMessage() throws Exception { String cluster = null, shard = "", message = "test message"; ALERT_TYPE type = ALERT_TYPE.ALERT_SYSTEM_OFF; String result = alertManager.generateAlertMessage(cluster, "jq", shard, type, message); String expected = "jq," + type.simpleDesc() + "," + message; Assert.assertEquals(expected, result); }