AssertJ是 JAVA的流畅断言库。
示例代码:
// uique etry poit to get access to all assertThat methods ad utility methods (e.g. etry) import static org.assertj.core.api.Assertios.*; // commo assertios assertThat(frodo.getName()).isEqualTo("Frodo");assertThat(frodo).isNotEqualTo(sauro) .isI(fellowshipOfTheRig); // Strig specific assertios assertThat(frodo.getName()).startsWith("Fro") .edsWith("do") .isEqualToIgorigCase("frodo"); // collectio specific assertios assertThat(fellowshipOfTheRig).hasSize(9) .cotais(frodo, sam) .doesNotCotai(sauro); // usig extractig magical feature to check fellowshipOfTheRig characters ame :) assertThat(fellowshipOfTheRig).extractig("ame").cotais("Boromir", "Gadalf", "Frodo", "Legolas") .doesNotCotai("Sauro", "Elrod"); // map specific assertios, rigBearers iitialized with the elves rigs ad the oe rig bearers. assertThat(rigBearers).hasSize(4) .cotais(etry(oeRig, frodo), etry(eya, galadriel)) .doesNotCotaiEtry(oeRig, aragor); // ad may more assertios : dates, file, umbers, exceptios ...









评论