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
3 answers

JUnit: Is there a way to assert all array values at once?

I have a map in which its values are a simple pojo. For example (in a very loosely code): Class Data{ int a; Boolean b; } Map myMap = new HashMap<>(); Now the map is being populated with values. And at then end I would like to…
dushkin
  • 1,939
  • 3
  • 37
  • 82
0
votes
1 answer

Is it possible to test if exception was thrown even if it was caught?

Is it possible to @Test if an appropriate exception was thrown in the main code function eaven if it was catch in a try / catch block? ex: public int maxSum(int a, int b) { try { if (a + b > 100) throw new…
Pewu
  • 55
  • 6
0
votes
1 answer

Assertj not working with Jackson JsonNode

I'm using assertj and Jackson's JsonNode combined. So far I've been using Assertions.assertThat(objectNode0).isEqualTo(objectNode1); and everything works fine. Now, I need to ignore some fields in the comparison, and the way I tried is by using…
0
votes
1 answer

Is there a simple way to filter & narrow collections on instance type in assertj?

Can this be written as a single line? assertThat(actualDeltas) .filteredOn(delta -> delta instanceof Replacement) .asInstanceOf(InstanceOfAssertFactories.list(Replacement.class)) I expected asInstanceOf to do the filtering.…
ymajoros
  • 2,454
  • 3
  • 34
  • 60
0
votes
2 answers

assertj eclipse assertions generator plugin

In the past I used an assertj assertions generator plugin that I downloaded from https://joel-costigliola.github.com/assertj-eclipse-plugin/repository/. Now I get a 404 error on that library. I also saw a citation for it at…
0
votes
1 answer

Possible to generate truth.dev Subjects for my domain model automaticly?

I'm a bit fan of Google's Truth.dev library. I have a large domain model in Java, and want to add several little custom assertions for them in my own Subject files. It's a bit of pain though to create the boiler plate for the Subjects every time…
Antony Stubbs
  • 13,161
  • 5
  • 35
  • 39
0
votes
3 answers

Check a list inside a Map entry in a unit test using AssertJ

I want to check a list that is inside a Map value in a unit test using the AssertJ library: public class Group { List players = new ArrayList<>(); public Group(List players) { this.players.addAll(players); …
0
votes
1 answer

Use assertThat function of AssertJ in ifPresent() of Java Optional

How can I remove try-catch block for the assertThat in the ifPresent()? The compiler gives me only one option for using assertThat in ifPresent(), which is to surround it with try-catch block. Throw the exception again is not allowed…
0
votes
1 answer

Setup for AssertJ Swing - testing GUI

I am trying to test the GUI of a banking system application, but in the TestLogin class I have an error 'Cannot resolve constructor 'FrameFixture(GUI.Login)'. I tried to extend the SampleFrame class in the Login class, but IntelliJ can't find…
Programmer2B
  • 552
  • 3
  • 14
0
votes
2 answers

How can I compare two collections using == with AssertJ?

I just implemented my own Insertion sort and trying to verify functionalities including stability. For a given list of unsorted elements, I'm trying to verify my code against Collections#sort(List) method. List unsorted = ...; //
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
2 answers

Compare two lists of different objects by certain two fields

I have two lists of different objects class objectA { String aId; String aTitle; String aUrl; ... } class objectB { String bId; String bTitle; String bUrl; ... } List aObjectList; List bObjectList; I need to verify that these two…
Ip Man
  • 77
  • 10
0
votes
1 answer

AssertJ how to compare two list by their element value?

Suppose I have a list of User userList. class User { String firstName; String lastName; } Is there a way I can compare using AssertJ like assertThat(userList).lastName.equalsTo(List.of("A","B","C")); ?
LunaticJape
  • 1,446
  • 4
  • 21
  • 39
0
votes
1 answer

How to check if at least one string is contained in another with AssertJ?

I would like to check if at least one string is contained in another using AssertJ. For example, having: String actual = "I am a string"; String oneString = "am"; String anotherString = "some string"; Currently I can…
fzt
  • 3
  • 3
0
votes
0 answers

Trying to round up double for two decimal places using Java 1.8?

Am trying to round up 2 decimal places using a method I wrote in my class. pom.xml:
PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144
0
votes
1 answer

How to explicitly fail a test step in Extent Report?

Background I am using Extent Report Cucumber Adapter for my Cucumber based test automation framework built using Java which is running on Junit. I am using AssertJ assertions for the test conditions. Scenario One of the test scenarios require to…
Arun Gupta
  • 25
  • 3