Questions tagged [assertj]

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

386 questions
0
votes
2 answers

How to test ConstraintViolationException with assertJ?

If I have a bean like @Data @Validated @EqualsAndHashCode(callSuper = true) @Document(collection = "Xxx") public class XxxDocument extends Zzz { @Min(0) @Max(255) private Integer aProperty; } How can I write a test using assertJ that…
du-it
  • 2,561
  • 8
  • 42
  • 80
0
votes
1 answer

How to check whether a string is one of the given values using assertj?

How to check in a simpler way whether a string matches one of the given options? List OPTIONS = Arrays.asList("alpha", "beta", "gamma"); String text = "beta"; assertThat(OPTIONS.stream().anyMatch(o -> o.equals(text))).isTrue();
Jónás Balázs
  • 781
  • 10
  • 24
0
votes
1 answer

How to assert values nested json using asserj?

I am trying to print and assert addressLine1 and postcode value from the JSON map object using assertJ but facing issues while asserting. { "Region": { "Test": { "address": { "addressLine1": "addressLine1", …
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
0
votes
0 answers

Intellij warning about a null check after a SoftAssertion

I have some tests in which I've created multiple validator functions that run several assertions on each test case. I've set up these validators to have an instance of SoftAssertions that is passed to each one, and assertAll() is called once all of…
Thomas
  • 1,123
  • 3
  • 13
  • 36
0
votes
0 answers

Assertj softassertions throwing exception

Assertj soft assertion is throwing exception, its only doing the first assertion and its failing after. any help will be appreciated. org.assertj.core.api.SoftAssertionError: The following assertion failed: 1) Expected size:<8> but…
0
votes
0 answers

Writing SonarQube Java-based rule to check for assertj mistake, can't figure out when chained methods are not called

I work in a large enterprise using SonarQube 7.9.2. I see a lot of test code using the AssertJ framework incorrectly. I see that SonarSource does have a small set of rules concerning AssertJ, but none of them cover the particular issue I'm looking…
David M. Karr
  • 14,317
  • 20
  • 94
  • 199
0
votes
1 answer

Java - Deep comparison of objects without implementing the equals method in JUnit Tests

How to "deep"-compare two objects that do not implement the equals method based on their field values in a test? In my example i have two objects from two different versions of an XML Schema that differ only in the version, in my test i want to show…
fl0w
  • 3,593
  • 30
  • 34
0
votes
2 answers

Does a hibernate transaction commit changes asynchronously, independent of the program flow?

I have a test method which sometimes fails during deploy and sometimes does not. I have never seen it fail on my local. You can see my code below. I have the following retry mechanism which is asynchronously called from another…
byksl
  • 106
  • 7
0
votes
0 answers

How would I do a deep compare two maps in a unit-test

I'm currently struggling with how to make sure 2 maps have the same key/values in a unit-test, while ignoring some of the keys. This should be applied recursively, as a value within the map might be a map again - so that I want to check the whole…
digital-h
  • 301
  • 3
  • 11
0
votes
1 answer

How do I test the API behavior when mock returns unordered collection Map?

I have an API, API calls a service which returns Map>, API converts it to List and returns it. public List getEmployees(int id) { Map> employees = employeeRepository.getEmployees(id); …
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
0
votes
1 answer

using AssertJ for comparing 2 csv's in Java

I have this method in Java where I am trying to compare 2 csv's file using assertJ and the method is as follows. I am using the ignorefields with Regex function as seen below. The Regex is for ignoring the values for coulmns which has timestamp in…
YRKKH
  • 11
  • 3
0
votes
0 answers

Is there an option to compare folders (with subfolders/subfiles) with Assertj given Path?

I am interested in adding to my Assertions verification of folder(path). Because I want to keep my classes homogeneous I am looking for a neat solution with Assertj. I am considering to just extract each path to list of files/folders and comparing…
0
votes
1 answer

Can AssertJ verify that a value is of a specific data type?

I have trawled through the net but struggling to find a way to get AssertJ to verify data type, For example, I want to verify that the value from a JSON response is a long data type or not a double: Something like this: JsonPath jp =…
The man
  • 129
  • 16
0
votes
1 answer

What's the benefit of Assert Fluent Assertions over Sequential ones?

In my team the is a thread to write fluent assertions with AssertJ in the following way: void checkPerson(Person person, String expectedName, Integer expectedAge) { assertThat(person) .isNotNull() .extracting(Person::getName,…
a3dsfcv
  • 1,146
  • 2
  • 20
  • 35