Questions tagged [assertj]

AssertJ provides a set of strongly-typed assertions to use for unit testing (either with JUnit or TestNG).

386 questions
2
votes
3 answers

How do you assert that a `Collection` of `Collection`s contains elements containing certain elements?

Let's say I have Strings "foo", "bar" and baz and that I'm given a Stream candidates. I now want to assertThat all elements in candidates are tuples containing either {"foo", "bar"} (in any order) or {"bar", "baz"} (in any order). How do I…
User1291
  • 7,664
  • 8
  • 51
  • 108
2
votes
1 answer

AssertJ Swing not working on one Windows 10 machine

We are using the Robot in AssertJ Swing in a Demo version of our Java Application to perform some automated configuration changes to our application. This is much better and easier than teaching our salesman to do these things correctly. The code…
2
votes
1 answer

AssertJ: fluent ordering tests with custom comparator

Let us assume that I have a class Foo, which does not implement Comparable and a FooComparator class, which implements Comparator. Using AssertJ's fluent API, I would now assume that I could do something like this: Foo foo1 = ...; Foo foo2 =…
jarnbjo
  • 33,923
  • 7
  • 70
  • 94
2
votes
2 answers

AssertJ Verify List of Objects with a List field is not empty

Example: public class Office { List employee; } How do I assert that in my List offices there are none with no employees? Is it possible to assert this with one assertion chain?
George
  • 2,820
  • 4
  • 29
  • 56
2
votes
1 answer

Assertj + how to disable stack trace

I want to disable the stack trace, as its kind of repetitive in all the test failures. Kindly let me know, if there is any way possible. at ForAtleastOneTupleResult.getAssertionDone(ForAtleastOneTupleResult.java:57) at…
Rejish R
  • 43
  • 1
  • 4
2
votes
2 answers

How to validate in Assertj Collection of Set

I have method which returns List of records. Each record have Set as field. public class R { public final Set s; } I have list of all expected Set - like: Set set1 = new HashSet(); set1.add("s1"); Set set2 = new…
THM
  • 579
  • 6
  • 25
2
votes
1 answer

AssertJ + verify items returned in subList contains string as will be present in any of the list items

I have requirement, say in my response I get the results in list as "brisbane, australia", "sydney, australia" and "melbourne, australia". Now I need to test that, the results contains "sydney" in any of the three…
Rejish R
  • 43
  • 1
  • 4
2
votes
0 answers

Can't assert an exception with AssertJ

I have the following negative test code (needs to fail and throw an exception): @Test public void testInventoryControllerGetNonExistingRegion() { final String name = "ME_2"; RegionConfiguration refRegionConfiguration =…
dushkin
  • 1,939
  • 3
  • 37
  • 82
2
votes
1 answer

assertJ findFrame() fails with NoClassDefFoundError

I'm trying to integrate assertJ-swing to a NetBeans project with no Maven. So I downloaded assertj-swing-3.8.0.jar from http://repo1.maven.org/maven2/org/assertj/assertj-swing/3.8.0/ and added it as a Library to NetBeans. In the test main() I…
Dula
  • 1,404
  • 1
  • 14
  • 29
2
votes
1 answer

isEqualToComparingFieldByField is failing but isEqualToComparingFieldByFieldRecursively is passing

I am writing a test using rest-assured to test an API. I have the expected response stored as a String that I convert to an object using google gson and then I use assertj's isEqualToComparingFieldByField to assert that the objects are equal. Even…
user889829
  • 388
  • 2
  • 7
  • 20
2
votes
1 answer

Serenity BDD : How to loop on Steps with Soft Assertions

I need to run tests on an array of datas, and I can't find a way to do a soft assert in my step AND show the error at the correct step in the Serenity Report. Example code @Then("All my datas are correct") public void verifyMyDatas(){ int[]…
Yann Merk
  • 23
  • 2
  • 6
2
votes
1 answer

How to check for equality or both blank in AssertJ?

I want to assert that expected and actual are equal to each other. It is ok if both are null or blank ("") -- i.e. null means blank. .withComparator(...).isEqualTo(expected) does not work, because null is checked before by AspectJ: @Given("^data is…
towi
  • 21,587
  • 28
  • 106
  • 187
2
votes
3 answers

Using AssertJ, how do I perform complex assertions on the contents of a list?

In AssertJ you can do the following to assert the contents of a list: assertThat(list).extracting("name").containsExactlyInAnyOrder("Alice", "Bob"); I often find myself wanting to do more complex assertions on the elements themselves, e.g.,…
neXus
  • 2,005
  • 3
  • 29
  • 53
2
votes
1 answer

Output full difference between expected and actual list in assertj

I am using groovy, assertj, junit and gradle. I have a test that contains assertion like that assertThat(actualLongList).isEqualTo(expectedLongList) When I run gradle test and those lists are not equal, it generates a test report with an exception…
Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62
2
votes
2 answers

assertThat() is always successful

I have a test that doesn't fail when it should: import static org.assertj.core.api.Assertions.assertThat; @Test public void testTransactionResponse() { String id= "004"; long amount= 5000001L; TransactionResource transactionResource =…
IKo
  • 4,998
  • 8
  • 34
  • 54