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

How to assert a condition in Java?

Can someone tell me what I am doing wrong? I am writing a junit test case, where I need to check the size of list and check whether the list contains certain elements. If it does, then make the test case successful, if not, then make it…
0
votes
1 answer

Junit tests for Object Creation with final attributes (AssertJ)

I have a class with final attributes to report on error information. The constructor call is as shown in the snippet. @Test public void test_With_Message() throws ParseException { final Exception e = new…
Amogha Varsha
  • 89
  • 1
  • 1
  • 8
0
votes
2 answers

Java code works when referenced from a variable but throws an error when called directly

I created an assertion using AssertJ library. I stored the extraction from a node contained in an API response in a string variable. I referenced the variable in the assertion. It works, but when the code is passed directly in the assertion, it…
The man
  • 129
  • 16
0
votes
1 answer

How to write conditional "assertThat" using assertj.core.api.Assertions?

Hey guys I have the following code: # number 1, 2, 3 are all "long" type Assertions.assertThat(number1).isGreaterThan(number2), Assertions.assertThat(number3).isLessThan(number4) And I want to achieve something like: if…
noobie2023
  • 721
  • 8
  • 25
0
votes
1 answer

JUnit5 assertAll private method assertions being ignored

Using JUnit5 assertAll, I call a method to perform assertions but noticed that when the assertion should fail, the test actually passes. It seems calling a method like the below is being ignored. assertAll( () -> jsonAssertions(actual,…
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
0
votes
1 answer

In a CucumberBDD project org.junit.rules.ErrorCollector OR org.assertj.core.api.JUnitSoftAssertions are not catching error in spite of mismatch

@Rule public ErrorCollector errorCollector = new ErrorCollector(); public void verifyDeviceType(String device_Type){ System.out.println(deviceType.getText()+","+device_Type);==> camera,camera1 …
PraNuta
  • 629
  • 3
  • 12
  • 33
0
votes
0 answers

How to use identity comparison in AssertJ iterable assertions

I am using AssertJ fluent assertions in my code. Example: assertThat(vertexSet).containsExactlyInAnyOrder(v0, v2, v4); Now I need to use identity comparison instead of .equals(...). What is the simplest way to achieve this? Here's what I came up…
lexicore
  • 42,748
  • 17
  • 132
  • 221
0
votes
1 answer

how to get the result returned with conditions and assert the correct value

i have written codes to assert the value stored from database. //SQL statement String dbQuery2 = /SELECT * FROM public.test where testId = 'default'/ //Connect to PostgresSQL, global variable is stored at profile List results =…
user2201789
  • 1,083
  • 2
  • 20
  • 45
0
votes
1 answer

How to check that frame does not contain jlabel with specific text with help of Assertj?

I want to test my simple application with AssertJ. I can check that text is showing like that: frame.label(JLabelMatcher.withText(text).andShowing()); But is there any way to check that specific text not showing?
Dmitriy
  • 487
  • 5
  • 15
0
votes
1 answer

Testing whether a list contains certain mandatory and certain optional items

I was trying to create a unit test which would make sure a list (or, more generally, a container) contains certain mandatory items, while allowing it to also contain some extra optional items (but, again, from a pre-defined list of options). Let's…
Bass
  • 4,977
  • 2
  • 36
  • 82
0
votes
0 answers

Getting 'Building workspace' error when I save any file in the project

I have added a new dependency in my project which works great. but whenever I build or save any file in my project I get the following error. I use command line maven to run the project and I dont see any problem with the project itself, it works as…
MRK
  • 1
  • 2
0
votes
1 answer

org.assertj.core.api.Assertions doesNotContain array error

I wanted to use doesNotContain to make sure the response does not contains the string. but hitting error. What should be the correct parameter to use? test script: import static org.assertj.core.api.Assertions.* def testjson= new…
user2201789
  • 1,083
  • 2
  • 20
  • 45
0
votes
1 answer

Collect JSON object in a file when a Junit test fails

I have ~50 JSON arrays as an array of models being plugged into Unit tests to compare resultant configs. Each file looks like this: 0.json 1.json... and so on [{model1},{model2},{model3}] I am trying to run unit tests to compare the resultant…
0
votes
1 answer

Asserting individual Objects in List using AssertJ

I am using AssertJ library to perform assertions in my test. In this case I want to test if every Date object in list is after other date. So I can obviously do the following: Date dateOne = new Date(someTimestamp); Date dateTwo = new…
Zychoo
  • 625
  • 2
  • 8
  • 25
0
votes
1 answer

AssertJ assert on Exception covered another Exception

I'm a beginner of AssertJ. I encountered some issue when I use AssertJ to do Unit Testing. JAVA: version 8 AssertJ: 3.11.1 I have a source code as below, to capture an exception and throw another exception. try { Integer.valueOf(valueA); }…
Bing
  • 3
  • 1