### Question:
BasicHARule implements HARule { @Override public String toString() { int count = 0; StringBuilder buff = new StringBuilder().append("listen ").append(name).append(" *:").append(String.valueOf(externalPort)).append( "\n").append(" mode tcp\n"); if ((httpchk != null) && (httpchk.trim().length() > 0)) { buff.append(" option httpchk " + httpchk + "\n"); } buff.append(" balance roundrobin\n"); for (String server : servers) { buff.append(" server server"). append(String.valueOf(++count)).append(" "). append(server).append(" check\n"); } buff.append("\n"); return buff.toString(); } BasicHARule(String name, int externalPort, String httpchk); boolean equals(Object another); @Override String toString(); @Override int compareTo(HARule o);  }### Answer:
@Test public void testToStringWithHealthCheck() { String httpchk = "/whatsnew/healthcheck.cgi"; BasicHARule rule = new BasicHARule("http", 80, httpchk); rule.servers.add("127.0.0.1:80"); rule.servers.add("127.0.0.2:80"); String expected = "listen http *:80\n" + " mode tcp\n" + " option httpchk " + httpchk + "\n" + " balance roundrobin\n" + " server server1 127.0.0.1:80 check\n" + " server server2 127.0.0.2:80 check\n\n"; Assert.assertEquals(rule.toString(), expected); }
@Test public void testToStringWithOutHealthCheck() { BasicHARule rule = new BasicHARule("http", 80, null); rule.servers.add("127.0.0.1:80"); rule.servers.add("127.0.0.2:80"); String expected = "listen http *:80\n" + " mode tcp\n" + " balance roundrobin\n" + " server server1 127.0.0.1:80 check\n" + " server server2 127.0.0.2:80 check\n\n"; Assert.assertEquals(rule.toString(), expected); }