Stats { public boolean checkHighUsage(double usage, double threshold, String name) { if (usage >= threshold) { NumberFormat format = NumberFormat.getPercentInstance(); errorCode = "HIGH_" + ASCII.toUpperCase(name) + "_USAGE"; errorMessage = name + " usage is too high, usage=" + format.format(usage); return true; } return false; }  String result(); void put(String key, double value); boolean checkHighUsage(double usage, double threshold, String name); void info(String key, String value); final Map<String, Double> stats; public String errorCode; public String errorMessage; public Map<String, String> info; }
@Test void checkHighUsage() { stats.checkHighUsage(0.7, 0.8, "disk"); assertThat(stats.errorCode).isNull(); stats.checkHighUsage(0.8, 0.8, "disk"); assertThat(stats.errorCode).isEqualTo("HIGH_DISK_USAGE"); assertThat(stats.errorMessage).isEqualTo("disk usage is too high, usage=80%"); }