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
1 answer

AssertJ check if JSONArray contains a map with an entry with given key and value

Hi I want to test with assertThat if a JSONArray contains an item with a key with a specific value. For example I have JSONArray: [ { "eventType": "event_1", "name": "user_1", .... }, { "eventType": "event_2", "name":…
0
votes
2 answers

Date format in the spring boot repository testing

I am using the following codes to do the integration testing for repository functions. However, it will fail because of the date formart. The output from SimpleDateFormat is 'Wed Jan 01 10:10:10 MST 2020', but the date from database is '2020-01-01…
0
votes
2 answers

Preventing usage of Hamcrest with JUnit 4.x

I am currently using JUnit 4.x with AssertJ. I would like to ensure that no usages of Hamcrest sneak it. However, Hamcrest Core is a required dependency at runtime for JUnit, see Junit issue #1429: A Exception for junit4.12 about…
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
0
votes
0 answers

Can you "ignore" ignored tests?

The latest AssertJ release notes have brought to my attention that I haven't really experimented much with assertj assumptions, so I thought I'd play around with it a bit: object AssertjAssumptions { @MethodSource("starWarsCharacters") …
User1291
  • 7,664
  • 8
  • 51
  • 108
0
votes
1 answer

AssertJ: Asserting that a an array of objects with fields (and values) contains (equals) another array of objects with fields (and values)

I am trying to figure out if I can write a terser program code than the one I came up with until now. I start with sharing the code snippet and some explanation after the code…
Ely
  • 10,860
  • 4
  • 43
  • 64
0
votes
1 answer

AssertJ: Type inference failed: Not enough information to infer parameter T in org.assertj.core.api.Assertions.fail

In a pure Kotlin project I am using JUnit Jupiter 5.5.2 and AssertJ 3.10.0. The following test executes successful: @Test fun `Validates something`() = runBlocking { try { // Assert something } catch (t: Throwable) { …
JJD
  • 50,076
  • 60
  • 203
  • 339
0
votes
1 answer

AssertionFailedError error when trying to compare two objects from the same class(after Overriding Equals() and Hashcode())

I tried in the first time to Override my class(Money) to check two objects on a specific attribute. a second time I tried to check two same objects from the same class(Money) but it didn't work. I tried Overriding Equals() and Hashcode() On the…
Samerlol
  • 19
  • 8
0
votes
1 answer

Get body detail message from throwable and assert that that exact message was returned when exception was thrown

I have a spring app that calls external APIs (I don't have control over this external project and its code). I am writing integration tests in my spring project. The test invoke those APIs. One of the API is throwing an exception for certain…
user1892775
  • 2,001
  • 6
  • 37
  • 58
0
votes
0 answers

java.lang.NoSuchMethodError: com.google.common.base.Objects.toStringHelper(Ljava/lang/Class;)Lcom/google/common/base/Objects$ToStringHelper;

I'm using Google Guava 21.x and AssertJ 3.8 to run a test, but it's complaining below: [junit] Testcase: testModule took 7.062 sec [junit] Caused an ERROR [junit]…
Fisher Coder
  • 3,278
  • 12
  • 49
  • 84
0
votes
1 answer

Last Assertion fails in assert chain - shows all previous passed asserts as failed

I have method which contains multiple Assertions, all are passing except last one and it shows all the assertion messages even if it is passed. Does anybody knows how to resolve such condition and how can i get only failure message instead of all…
0
votes
1 answer

AssertJ - how to check that an element is in a collection?

Is there a way to check that an object is an element of some collection with AssertJ? Something like assertThat(actualObject).isElementOf(collectionWithExpectedOptions); I could…
leventov
  • 14,760
  • 11
  • 69
  • 98
0
votes
0 answers

Assertj Mouse clicking is working only if the windows display resolution lowered to 1366X768

Mouse clicking is working only when the windows display resolution is lowered during automated UI test using assertj. Is there a way to click with the default resolution? I tried setting the preferred size of the top JFrame but still does not…
user10478566
  • 37
  • 12
0
votes
1 answer

Sorting array before compare in AssertJ

I compare two objects using assertJ. I have actual object which is output from our application and expected object. This object has field which is an array of other object but elements in this array are present in random order so sometimes test…
kris82pl
  • 977
  • 3
  • 12
  • 21
0
votes
2 answers

is it possible to log the name and values of fields being asserted along with conditions when using assertj?

For example, for this assertion - aString = "stack overflow"; another string = "stack"; assertThat(aString).startsWith(anotherString); is it possible to add a logger like this - assertThat(aString ["stack overflow"]).startsWith(another strong…
0
votes
1 answer

Why does getResourceAsStream() return null when File does not exist before start of Test method?

Before flagging this as a duplicate please read the question! I have a JUnit Test which tests a method that writes its result in a file. To check the result I want to read that result file and check its content. The problem is that when the result…
MauriceNino
  • 6,214
  • 1
  • 23
  • 60