assertj

How do I negate assertions in AssertJ?

社会主义新天地 提交于 2019-12-12 10:49:56
问题 Using Hamcrest it is easily possible to negate a matcher. E.g. you can write an assertion like this: assertThat("The dog bites Tom", not(stringContainsInOrder(Arrays.asList("Tom", "dog")))); I.e. using the org.hamcrest.core.IsNot , org.hamcrest.core.AnyOf matchers it is easy to combine or negate assertions. Is there any equivalent in AssertJ? I know that it is possible to combine/negate Condition s. But what about normal assertion methods? E.g. what do you do if you want to test that a String

How does AssertJ's `usingComparatorForFields` work?

爱⌒轻易说出口 提交于 2019-12-12 01:59:09
问题 Related to How to compare recursively ignoring given fields using assertJ? As a work around the problem, I tried to rig the comparator for the field which I don't want the comparator to compare and made it return 0. assertThat(service.postComment(12,234,comment)).usingComparatorForFields((a,b)->0,"startDate").isEqualToComparingFieldByFieldRecursively(commentReturned); But, still I get this exception. Path to difference: <startDate> - expected: <null> - actual : <2017-04-12 18:28:06.766> As a

Verify that assertions have been called in Assertj

柔情痞子 提交于 2019-12-10 21:12:00
问题 I'm reading through test classes that use Assertj to verify results. Occasionally, I've spotted an assertThat without assertions. assertThat(object.getField()); Is it possible to identify these classes somewhere in the development cycle? My first guess would be to use a custom Sonar rule. Although I don't see how I should define that this method should be followed by an assertion (a method returning void?). 回答1: SonarJava is having the rule S2970 "Assertions should be complete" that can

How to get started: testing Java Swing GUI with AssertJ Swing

眉间皱痕 提交于 2019-12-10 11:08:59
问题 While developing a Java desktop application with Swing, I encountered the need to test the UI directly, and not just the underlying controller/model classes via unit tests. This answer (on "What is the best testing tool for Swing-based applications?") suggested using FEST, which is unfortunately discontinued. However, there are a few projects that continued from where FEST left of. One in particular (mentioned in this answer) caught my attention, as I used it before in unit tests: AssertJ.

How to get started: testing Java Swing GUI with AssertJ Swing

…衆ロ難τιáo~ 提交于 2019-12-06 12:42:05
While developing a Java desktop application with Swing, I encountered the need to test the UI directly, and not just the underlying controller/model classes via unit tests. This answer (on "What is the best testing tool for Swing-based applications?") suggested using FEST , which is unfortunately discontinued. However, there are a few projects that continued from where FEST left of. One in particular (mentioned in this answer ) caught my attention, as I used it before in unit tests: AssertJ . Apparently there is AssertJ Swing , which is based on FEST and offers some easy to use ways of writing

How to compare recursively ignoring given fields using assertJ?

徘徊边缘 提交于 2019-12-01 22:26:44
AssertJ has isEqualToIgnoringGivenFields and isEqualToComparingFieldByFieldRecursively . But, there is no way I can compare two objects recursively by ignoring some fields. As per this discussion, it must be in development. How to still get my assert's return value to be compared recursively but ignoring some fields. Is it possible in any other library or can I do it somehow using AssertJ ? With latest 'Recursive comparison api improvements' from AssertJ release 3.12.0 it's possible now to do a recursive comparison and ignore fields: Assertions.assertThat(objActual) .usingRecursiveComparison()

How to compare recursively ignoring given fields using assertJ?

梦想与她 提交于 2019-12-01 18:04:07
问题 AssertJ has isEqualToIgnoringGivenFields and isEqualToComparingFieldByFieldRecursively . But, there is no way I can compare two objects recursively by ignoring some fields. As per this discussion, it must be in development. How to still get my assert's return value to be compared recursively but ignoring some fields. Is it possible in any other library or can I do it somehow using AssertJ ? 回答1: With latest 'Recursive comparison api improvements' from AssertJ release 3.12.0 it's possible now