Questions tagged [assertj]

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

386 questions
3
votes
1 answer

Get JSlider value in tests using AssertJ

I use JUnit and AssertJ tests for my Swing app written in Java 8. I'd like to test whether slider value is changed when a button is clicked, but I didn't find any way to get a current value from a slider. I've initialized the app at the beginning of…
3
votes
1 answer

AssertJ testing on a collection: what is better: 'extracting' or Java8 forEach

I'm new to AssertJ and using it to unit-test my written code and was thinking how to assert a list. Lets assume we have a list of Consumers Entities. each Entity has it own Phone, own ServiceProvider which has it own Name and EntityName. Now we want…
a.k
  • 1,035
  • 10
  • 27
3
votes
1 answer

AssertThat usage in a date comparison

I want to write a test against a search with date. I am thinking of a test code something like assertThat(repository.findByBookingDateAfter(LocalDate.of(2016, 1, 1))).extracting("bookingDate").are(...)); where the class structure is something like…
vic
  • 2,548
  • 9
  • 44
  • 74
3
votes
1 answer

Assert identity with AssertJ or JUnit

Edit II Basically, the question is if there's an AssertJ (preferred) or JUnit assertion for: objA == objB Edit I My class under test (CUT) extends JAXB's XmlAdapter. When unmarshalling a XML file, it should guarantee that equal objects exist…
beatngu13
  • 7,201
  • 6
  • 37
  • 66
3
votes
3 answers

AssertJ: how to assert BigDecimals using compareTo together with extracting()

I am using AssertJ extracting() method with Java8 lambdas and mapping some fields to BigDecimal, then asserting the resulting array. But I need to compare BigDecimal using compareTo() and not with equals() (because of this). How can I do…
jhyot
  • 3,733
  • 1
  • 27
  • 44
3
votes
1 answer

how to verify in assertj that elements are one of

I can't find how to do check with assertj the following (which is very common): Suppose I have: result1 = {"AAA", "BBB"} result2 = {"DDD"} I want to check the values in result is one of these: String[] valid = String[]{"AAA", "BBB",…
ejaenv
  • 2,117
  • 1
  • 23
  • 28
3
votes
5 answers

Analog of everyItem() from Hamcrest in AssertJ

Is there analog of everyItem() from Hamcrest in AssertJ? I have a list of emails and need to do Assertion to check that each email contains substring "alex". Currently the only way I can do it with AssertJ is as follows: List actual =…
Alex F
  • 273
  • 4
  • 13
2
votes
2 answers

3 digits difference between Java Instant and Postgres TIMESTAMPTZ

Given the following field in Java: private Instant createdDate = Instant.now(); corresponding to the following field in Postgres: created_date TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP; and saved to database using Spring Data JDBC…
Marco Lackovic
  • 6,077
  • 7
  • 55
  • 56
2
votes
1 answer

How to assert property of objects at a list?

I am trying to have proper assertion (with implicit null checks) for a property of a list element. The first assertion is working as expected, except that it will generate no proper error message if actual is null. The second is supposed to provide…
André
  • 308
  • 2
  • 17
2
votes
0 answers

Testing suspension functions in AssertJ?

I'm in the process of converting my JUnit tests to AssertJ, but I'm running into some issues with AssertJ. I'm not quite sure how to test a suspend function using AssertJ. In JUnit, I can do this. runTest { assertThrows { …
bensalerno
  • 467
  • 1
  • 6
  • 22
2
votes
3 answers

AssertJ: how can I make JsonNode comparison handle IntNode and LongNode as same?

I have a JsonNode which is built out of a Map: Map actual = Map.of("test", 3L); JsonNode actualNode = mapper.valueToTree(actual); I would like to compare such node against an expected file, that I load as…
Matteo NNZ
  • 11,930
  • 12
  • 52
  • 89
2
votes
0 answers

AssertJ.assertThat: Filtering out Map entries in POJO by Key

I'm trying to do an AssertJ assertion filtering out the specific Map entries by their key. The only available method for ignoring - "ignoringFields" doesn't work since the map key is not a field (obviously). Do you know if there are any way to do…
suamo
  • 21
  • 2
2
votes
1 answer

How can we compare two hashmaps with case insensitive on both keys and values

I have two maps with both same values, but differing in case, either in key or in value. While asserting, I need to make it as pass. I know the Treemap with case insensitive option can be used, but it validates the keys alone and not the values. Is…
mmar
  • 1,840
  • 6
  • 28
  • 41
2
votes
1 answer

AssertJ Core, is it possible to get error message with actual field/property difference when checking iterables/arrays content?

In Assertj Core you can compare ojects field by field recursively. In this test address.countryCode differ in the two objects: @Test public void shouldBeEqual() { Person person1 = createPerson(); Person person2 = createPerson2(); …
BruceB
  • 37
  • 1
  • 8
2
votes
2 answers

AssertJ-Swing and Junit 5 support

I'm currently working at a Java application that I'm testing using JUnit Jupiter. I am starting to work at the GUI and I was wondering if it was possible to use AssertJ-Swing with JUnit 5. As a matter of fact I have found an open issue on…
ClaudiaR
  • 3,108
  • 2
  • 13
  • 27