Questions tagged [assertj]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

Swing testing with AssertJ not working in IntelliJ IDEA

I want to test a Swing app written with Intellij IDEA. I have been able to setup the initial example, but when trying to execute the example text, I get this message: Unable to find component using ...
Jose's user avatar
  • 11
0 votes
0 answers
17 views

Looking for a custom swing JComponent object inside a standard Swing app using AssertJ FrameFixture

AssertJ has options for finding JPanel, JFrame, and suite of other standard Swing components, but I am wanting to test a custom Prefuse Display window derived directly from the JComponent class. What ...
Daniel McEnnis's user avatar
0 votes
1 answer
33 views

Using Assertj how to verify two hashmap list List<Map<String, String>> with multiple keys

I have two hashmap list and want to check the value present against the given key is same. List<Map<String, String>> listMap1 = new ArrayList<>(); Map<String, String> map1 = ...
DeepakVerma's user avatar
0 votes
1 answer
71 views

Can AssertJ isEqualToComparingFieldByFieldRecursively ignore a field?

I need to compare a JPA Entity with expected value ignoring IDs. AssertJ has this method assertThat(actualEntity).isEqualToIgnoringGivenFields(expectedEntity, "id"); which compares two ...
Michal Krasny's user avatar
0 votes
0 answers
33 views

determineDifferences method of RecursiveComparisonDifferenceCalculator not able to compare the list of 100 objects

I hope you would suggest me something as I am quite new to Java world and trying to work with assertj-core recursive comparison APIs for deep comparison between the objects as follows. But it appears ...
Amit's user avatar
  • 13
0 votes
0 answers
29 views

Can AssertJ's contains method work with spring's PagedModel - getContent()?

The getContent() method in Spring's PagedModel is able to get all the content from an API response absolutely fine and it is possible to write an assertion that compares the content fetched by ...
matt's user avatar
  • 25
0 votes
1 answer
41 views

Bytebuddy get value of proteced field

Im struggling to figure out how to access a protected field using ByteBuddy and what approach to take. Background: Id like to intercept a class from a dependency I have on my class path. Im creating a ...
rogger2016's user avatar
0 votes
1 answer
139 views

List diffs in the context of usingRecursiveComparison()

This is an AssertJ specific question. Consider the tests below where two lists are compared first directly and then nested in some other object through usingRecursiveComparison(). public class ...
Bogdan Calmac's user avatar
0 votes
0 answers
11 views

roots are empty in BasicRobot.robot.hierarchy Swing-assertj

I’m trying to test swing dialog in desktop application, bit robot couldn’t get any dialog and also the roots is empty I need to get access to this dialog , it appears in access bridge explore
Mai Elgendy's user avatar
1 vote
1 answer
361 views

import static org.assertj.core.api.Assertions.assertThat not suggested by IntelliJ

Newbie, big project, copy/paste unit testing task. Using IntelliJ Ultimate, when trying to import assertThat(), I get to choose only between: import static com.mysema.commons.lang.Assert.assertThat; ...
NaPal.'s user avatar
  • 11
0 votes
0 answers
83 views

AssertJ assertThat Consumer

Im currently building a custom maven test report plugin that captures unit and integration tests results. While trying to capture as much test information as possible, I am able to capture AssertJ ...
rogger2016's user avatar
0 votes
1 answer
35 views

Testing object method return values

I have an object under test and want to verify it was configured correctly by testing the return values of methods. Is there a way to do this without creating one test per method? I'm imagining ...
gph's user avatar
  • 1,013
1 vote
2 answers
104 views

AssertJ exception handling (feat.assertThat+isInstanceOf)

I have been on this problem for hours but couldn't get close to solution. Any help will be appreciated. public static int enterTheAmount(){ int final LOTTO_PRICE = 1000; int amount = Integer....
Dan Lee's user avatar
  • 13
2 votes
1 answer
313 views

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 ...
André's user avatar
  • 308
0 votes
3 answers
381 views

How can i access an element from a list in AssertJ?

assertThat(service.load(1, setup.getEntity(), "OBJECT1").getImages().get(0).isSwitchedOn()).isEqualTo(false); I'm accesing the unique element of the list in this way,but i'm wondering if ...
IvanKarl's user avatar
2 votes
0 answers
134 views

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. ...
bensalerno's user avatar
0 votes
0 answers
159 views

Converting JUnit throw exceptions to AssertJ?

I am trying to manually convert my JUnit tests into AssertJ, but I'm running into some blockers. None of the scripts or plugins I've found online are working for me. I have a number of JUnit ...
bensalerno's user avatar
0 votes
1 answer
134 views

Alternatives to deprecated java method from org.assertj.core.api

I'm looking for an alternative of the deprecated method containsOnlyElementsOf. It has to check whether the given iterable (a list of Integers in my case) contains only Integers in-between given ...
IDK's user avatar
  • 339
0 votes
1 answer
129 views

Which assertion library for Java has the best integration with Allure Reports?

I'm using Allure Reports to provide test results on my automated tests. However, I'm noticing that assertions are not showing up as step in the reports. I would like to know which assertions library ...
Dax Ortiz's user avatar
1 vote
2 answers
259 views

Test that at least one element of a list contains a specific element using assertj

Suppose i have players which form a team which participates at a tournament. I want to test, that the tournament has at least one team with name T1 with a player named Paul. package org.example; ...
peer's user avatar
  • 257
-1 votes
2 answers
65 views

How to test if an exception was thrown?

My code: public String getTemplate(TestType fileType) { Util util = new Util(); try { return util.addPrefix(util.getTemplate(fileType)); } catch (IOException e) { logger....
Amikuto's user avatar
0 votes
1 answer
73 views

Is it possible to assert there are only duplicates with an AbstractIterableAssert?

I have something like this: assertThat(someList).extracting("someField") and I want to continue the assert with asserting that only duplicates exist in the extraction. Is there a good way ...
Hans Wurst's user avatar
1 vote
2 answers
46 views

Idiomatic way of comparing results of two completableFutures with assertj

There are 2 completable futures cf1 and cf2 defined as follows: CompletableFuture<Boolean> cf1 = CompletableFuture.completedFuture(true); CompletableFuture<Boolean> cf2 = ...
Bhushan's user avatar
  • 580
0 votes
0 answers
43 views

Assertj-Generator maven plugin custom variable

I was wondering if there is a way to add a custom variable when using the assertj-assertions-generator-maven-plugin. I would like to introduce a variable in the maven pom that would be the entry point ...
John B's user avatar
  • 32.4k
1 vote
0 answers
58 views

How to ignore node with sub nodes in JsonAssertions?

I am using net.javacrumbs.jsonunit.assertj, JsonAssertions, assertThatJson to compare two jsons. I need to ignore node with array and sub-nodes. So in this example I would like to ignore all in node &...
Simon's user avatar
  • 11
0 votes
1 answer
176 views

Test that either one property contains value in AssertJ

Having following code: @Data @AllArgsConstructor public class TolkienCharacter{ String nick; String name; String surname; } @Test void go(){ TolkienCharacter frodo = new ...
Artur's user avatar
  • 601
0 votes
0 answers
53 views

Builder pattern in unit testing vs mocking all collaborators

Lets say a university offers courses and courses are attended by students: class University{ List<Course> courses; } class Course{ Category category; List<Student> students; } ...
peer's user avatar
  • 257
0 votes
2 answers
407 views

Ignoring a field in Map<String, Object> that is a member of a class while testing

I have an Object called ReconciliationResult public class ReconciliationResult { Map<String, Object> recordValue; List<Object> keyValues; Origin origin; ReconciliationResultStatus ...
Beez's user avatar
  • 468
-1 votes
2 answers
209 views

The import org.assertj.core.api.Assertions.catchException cannot be resolved in VSCode

When I am trying to launch my Spring application using VSCode's Extension Pack for Java which has import static org.assertj.core.api.Assertions.catchException; in one of the tests, I get build failed ...
Wiktor's user avatar
  • 59
1 vote
2 answers
251 views

assertThat returns() BigDecimal usingComparatorForType

I like to use asserThat().returns() combination to test the content of my objects. Unfortunately it does not work out of the box with BigDecimal because the equals method requires identical scale, ...
Maxime Dutaut's user avatar
0 votes
1 answer
1k views

How to verify the data type of Json response field in rest assured

How can we verify the Json data type of mentioned fields such as "price", "ck", "name", "enabled" and "tags" in rest assured test. { "...
swapnil shirke's user avatar
0 votes
0 answers
309 views

Compare nested fields in AssertJ using a BiPredocate and withEqualsForFields()

Using AssertJ when recursively comparing objects with nested objects in collections, I can ignore certain fields using either .ignoringFields(String fields...) or .ignoringFieldsMatchingRegexes(String ...
Wrench's user avatar
  • 3,890
0 votes
1 answer
61 views

ArchUnit: Prevent assertJ statements without assertion

Is it possible to create an ArchUnit rule which prevents AssertJ statements without an assertion? For exampel: This AssertJ statement is perfectly ok, because it has both a assertThat part and an ...
Olaf's user avatar
  • 3,658
1 vote
2 answers
619 views

AssertJ: How to return the actual exception when using method assertThatThrownBy

I am migrating from JUnit 5 and Hamcrest Assertions to AssertJ and I can't figure out the right method for extracting the actual exception from the executable. Here is a JUnit/Hamcrest example: var ...
Arthur Eirich's user avatar
0 votes
1 answer
692 views

Asserting Java enum values and fields with AssertJ

Given a simple enum like this: @AllArgsConstructor @Getter public enum PaymentMethod { CREDITCARD(1), PAYPAL(2), APPLE_PAY(3), GOOGLE_PAY(4); private final long id; } How can I ...
Robert Strauch's user avatar
2 votes
3 answers
383 views

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

I have a JsonNode which is built out of a Map<String, Object>: Map<String, Object> actual = Map.of("test", 3L); JsonNode actualNode = mapper.valueToTree(actual); I would like to ...
Matteo NNZ's user avatar
  • 11.9k
1 vote
1 answer
77 views

Unit test after upgrading the Spring Boot version hasOnlyOneElementSatisfying() method is not working

Unit test was working fine in its previous version while after updating the version it shows error public class PersonSearchUtil { private final HashSet<SearchResponse> result = new HashSet&...
Jimmy's user avatar
  • 929
1 vote
2 answers
277 views

In Testcase statment gives error after upgrading the springboot version from 2.1.7 to 2.6.4

After updating the Spring Boot version to 2.6.4 I am getting error in the test case while in its old version 2.1.7 working fine @Test fun `Should include id in all outbound requests`() { (...
Jimmy's user avatar
  • 929
1 vote
1 answer
83 views

How to verify that nulls are in the end of the list

I need to verify that data is sorted according to rule that all null values are in the end of the list. Is any appropriate method exist for it in assertj? I don't want to write something like - I am ...
Ip Man's user avatar
  • 77
0 votes
0 answers
80 views

AssertJ's SoftAssertions.assertSoftly is hanging my test at 892 assertions

Im doing a database comparison test using serenity-bdd. I am currently testing 892 records. All 892 failed as expected. AssertJ's SoftAssertions.assertSoftly appears to have ran through all 892 ...
Tim Boland's user avatar
  • 1,863
1 vote
0 answers
364 views

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 ...
suamo's user avatar
  • 11
1 vote
0 answers
184 views

How to get screenshot for each soft assert failure with AssertJ SoftAssertions

I want to achieve below: - CustomSoftAssertJ softly = new CustomSoftAssertJ(); softly.assertThat(actual).isEqualTo(expected); // get screen shot on failure softly.assertThat(actual).isEqualTo(expected)...
Deepak Arora's user avatar
1 vote
0 answers
238 views

Await until assertJ asserts true on database update

I am running a test that sends some data to a database and checks it's all been inserted properly. Depending on the machine, this can take varying amounts of time. I am using awaitly/assertj. Is there ...
Sheen's user avatar
  • 576
1 vote
1 answer
577 views

How to use logger to print messages with assert

I am trying to implement a logger in my repo and I am having some issues with implementing logger with Junit. Sample assertion: logger.info("Asserting the response."); assertThat(response....
Bilal's user avatar
  • 560
1 vote
1 answer
219 views

How to start writing Unit Tests for SpringBoot(The proper way)?

I'm new to the world of unit testing in Spring and with some research I think I'll be using Junit5 with mockito and AssertJ library for the same. I am just starting out and it does look really ...
Narupo's user avatar
  • 39
3 votes
2 answers
193 views

Simple JUnit test fails

I want to learn how to write JUnit tests and I fail completely. This is my test: @Test public void testGetAllCustomers() { // given List<Customer> customerList = new ...
FrozenTree's user avatar
2 votes
1 answer
364 views

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 ...
mmar's user avatar
  • 1,818
1 vote
1 answer
248 views

Creating assertions

So I want to create an assertion class like how AssertJ works. I'm having trouble getting started. public class Assertion { static object assertThis(Object o){} static ...
rd1346's user avatar
  • 23
1 vote
1 answer
1k views

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(); ...
BruceB's user avatar
  • 27
1 vote
2 answers
608 views

How can I test whether a list is sorted with AssertJ [duplicate]

Given List<Integer> list = ... I would like to test with AssertJ whether it is sorted. Something like: assertThat(list).isSorted() Is it possible?
user3429660's user avatar
  • 2,283

1
2 3 4 5
8