### Question:
NodeService { static String truncateLog(String log, int maxLength) { if (log == null || log.length() <= maxLength) { return log; } return "[snipped]" + log.substring(log.length() - maxLength); } @Inject private  NodeService(ClusterStoreService clusterStoreService, Configuration conf); void startAction(Node node, String taskId, String service, String action); void completeAction(Node node); void failAction(Node node, String stdout, String stderr); static String createHostname(String clusterName, String clusterId, int nodeNum, String dnsSuffix);  }### Answer:
@Test public void testTruncate() throws Exception { String shortStr = "this is a short string"; Assert.assertEquals(shortStr, NodeService.truncateLog(shortStr, shortStr.length())); Assert.assertEquals("[snipped]short string", NodeService.truncateLog(shortStr, 12)); String newLineString = "this \nis a string \nwith newlines"; Assert.assertEquals(newLineString, NodeService.truncateLog(newLineString, newLineString.length() + 10)); Assert.assertEquals("[snipped]ing \nwith newlines", NodeService.truncateLog(newLineString, 18)); Assert.assertEquals("[snipped]is a string \nwith newlines", NodeService.truncateLog(newLineString, 26)); }