Inspectopedia 2025.2 Help

JUnit assertion can be 'assertThat()' call

Reports calls to Assert.assertEquals(), Assert.assertTrue(), etc. methods which can be migrated to Hamcrest declarative style Assert.assertThat() calls.

For example:

public class SubstantialTest { @Test public void testContents(Collection<String> c, String s) { Assert.assertTrue(c.contains(s)); Assert.assertEquals(c, s); Assert.assertNotNull(c); Assert.assertNull(c); Assert.assertFalse(c.contains(s)); } }

A quick-fix is provided to perform the migration:

public class SubstantialTest { @Test public void testContents(Collection<String> c, String s) { assertThat(c, hasItem(o)); assertThat(o, is(c)); assertThat(c, notNullValue()); assertThat(c, nullValue()); assertThat(c, not(hasItem(o))); } }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

MigrateAssertToMatcherAssert
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | JUnit

This inspection requires that the Hamcrest library is available on the classpath.

Use the Statically import matcher's methods option to specify if you want the quick-fix to statically import the Hamcrest matcher methods.

Inspection options

Here you can find the description of settings available for the JUnit assertion can be 'assertThat()' call inspection, and the reference of their default values.

Statically import matcher's methods

Default value:

Selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection MigrateAssertToMatcherAssert

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025