Questions tagged [assertj]

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

386 questions
9
votes
4 answers

Ambiguous method call with Lambda in Java

I have defined a static assertThat method to extend AssertJ. This method accepts a lambda expression of the type: @FunctionalInterface public interface Action { void execute() throws Exception; } The signature looks like this: public static…
deamon
  • 89,107
  • 111
  • 320
  • 448
8
votes
1 answer

What to use instead of AssertJ isEqualToIgnoringGivenFields?

This method seems to be Deprecated. I would really appreciate it if you could tell me what AssertJ advises to use instead.
user15599360
8
votes
4 answers

Kotlin Contracts: assert instance on reified type parameter

I'm trying to write an assert function that checks if a given object is of a type T: @UseExperimental(ExperimentalContracts::class) inline fun assertIsInstance(value: Any?) { contract { returns() implies (value is T) } …
s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
8
votes
4 answers

How to compare LISTS recursively ignoring given fields using assertJ?

Firstly, this is not a duplicate of this question. There, it is asked specifically for an object. I want to do this for a Container, specifically a List. So, I know I can ignore a field when using usingElementComparatorIgnoringFields() But this…
orrymr
  • 2,264
  • 4
  • 21
  • 29
8
votes
2 answers

class file for java.nio.file.Path not found

I'm using org.assertj:assertj-core:3.6.2 to test my android project. According offical ducoment, I should use java 8 with assertj 3.x. Here is my test class, I'm trying to verify when the click performed the code can start expected activity. import…
gn cavalry
  • 149
  • 2
  • 11
8
votes
3 answers

Android AssertJ 1.0.0 with Android gradle 1.1.1

Here is part of my build.gradle that has conflict: ... dependencies { classpath 'com.android.tools.build:gradle:1.1.1' } ... testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) ... The issue that I see in log: WARNING: Conflict with…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
7
votes
2 answers

Inconsistent exception details in parallel stream

Most of the time, exceptions thrown in a parallel stream won't have all of its attributes. Ex: @Test public void test() { assertThatThrownBy(() -> Stream.of("1", "2", "asdf").parallel().forEach(Integer::parseInt)) …
dlhextall
  • 121
  • 2
  • 7
7
votes
4 answers

How to assert that some String contains at least one value from the List ?

I'm testing some UI functionality with Java and AssertJ. So when I receive some massive string from UI, I should verify if that String contains at least one predefined value from List. It is easy to do opposite thing - verify if list…
Vadam
  • 85
  • 1
  • 4
7
votes
1 answer

Failing a unit test if an exception is thrown in another thread

Currently, whenever I need to fail a test in response to an exception thrown in another thread, I write something like this: package com.example; import java.util.ArrayList; import java.util.List; import org.testng.annotations.Test; import static…
Bass
  • 4,977
  • 2
  • 36
  • 82
6
votes
4 answers

AssertJ JSON property check

I have JSONObject instance which contains some property, { "name":"testName", "age":"23" } i use the following assert, but it fails. Is this correct approach to test JSON in assertj. assertThat(jsonObject).hasFieldOrProperty("name");
parrotjack
  • 432
  • 1
  • 6
  • 18
6
votes
1 answer

AssertJ `containsExactly` assertion on list with wildcard

I have a getter returning a List with a wildcard: import java.util.List; public interface Foo { List getList(); } Where Bar is an other interface. When I write an assertion with AssertJ like…
Jmini
  • 9,189
  • 2
  • 55
  • 77
6
votes
4 answers

AnyString() as parameter for unit test

I have to deal with a legacy application that has no tests. So before I begin refactoring I want to make sure everything works as it is. Now imagine the following situation: public SomeObject doSomething(final OtherObject x, final String something)…
user4063815
6
votes
2 answers

How to check boolean getter with AssertJ?

It looks very cool assertThat(yoda).is(jedi); until you don't know what is yoda and jedi. But suppose yoda instanceof Person where interface Person { boolean isJedi(); } Then how actually check isJedi with AssertJ? In conventional JUnit I…
Dims
  • 47,675
  • 117
  • 331
  • 600
6
votes
2 answers

How do I negate assertions in AssertJ?

Using Hamcrest it is easily possible to negate a matcher. E.g. you can write an assertion like this: assertThat("The dog bites Tom", not(stringContainsInOrder(Arrays.asList("Tom", "dog")))); I.e. using the org.hamcrest.core.IsNot ,…
Joern
  • 1,926
  • 1
  • 13
  • 18
6
votes
1 answer

Clicking on disabled Swing components

I have a disabled JTable that provides a popup menu: import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JTable; public…
Angelo Berlin
  • 346
  • 4
  • 11
1 2
3
25 26