Collections.sort(employees, new Comparator<Employee>() {
public int compare(Employee s, Employee s1) {
int comp = s.getName().compareTo(s1.getName());
if (comp != 0) { // names are different
return comp;
}
return s.getSalary() - s1.getSalary();
}
});
System.out.println(employees);
}
Run Code Online (Sandbox Code Playgroud) 尝试运行 JUnit 测试错误时,测试将无法正确运行
package picocli;
import picocli.CommandLine.Option;
public class ComparatorRunnerConfig {
@Option(names = {"-rc", "--report-class"}, required = false,
description = "define report")
private String report;
public String getReport() {
return report;
}
}
Run Code Online (Sandbox Code Playgroud)
我的 JUnit 测试:
package picocli;
import static org.junit.Assert.*;
import org.junit.Test;
public class ConfigurationTest {
@Test
public void testBasicConfigOptions() {
String args = "-rc BlahBlah";
ComparatorRunnerConfig mfc = new ComparatorRunnerConfig();
new CommandLine(mfc).parse(args);
String myTestValue = mfc.getReport();
assertEquals(myTestValue, "BlahBlah");
}
}
Run Code Online (Sandbox Code Playgroud)
测试失败。