SonarQube issue "Add at least one assertion to this test case" for unit test with assertions?
<p>I'm having issues with SonarQube raising issues with several of my unit tests, prompting the following issue:</p>

<blockquote>
  <p>Add at least one assertion to this test case.</p>
</blockquote>

<p>Each test case resembles this format (where a number of assertions are delegated to a method with common assertions, to avoid duplication):</p>

<pre><code>@Test
public void companyNameOneTooLong() throws Exception {
    AddressFormBean formBean = getValidBean();
    formBean.setCompanyNameOne("123456789012345678901234567890123456");

    assertViolation(validator.validate(formBean), "companyNameOne", "length must be between 0 and 35");
}

private void assertViolation(Set&lt;ConstraintViolation&lt;AddressFormBean&gt;&gt; violations, String fieldname, String message) {
    assertThat(violations, hasSize(1));
    assertEquals(fieldname, violations.iterator().next().getPropertyPath().iterator().next().getName());
    assertEquals(message, violations.iterator().next().getMessage());
}
</code></pre>

<p>Now, obviously I could just pull the three assertions out of the private method and put them in the test method - but I'm performing the same checks (on different fields) multiple times.</p>

<p>So, I thought I'd try to emulate the behaviour of the assertion methods, by (re) throwing an <code>AssertionError</code>:</p>

<pre><code>private void assertViolation(Set&lt;ConstraintViolation&lt;AddressFormBean&gt;&gt; violations, String fieldname, String message) throws AssertionError {
    try {
        assertThat(violations, hasSize(1));
        assertEquals(fieldname, violations.iterator().next().getPropertyPath().iterator().next().getName());
        assertEquals(message, violations.iterator().next().getMessage());
    } catch (AssertionError e) {
        throw e;
    }
 }
</code></pre>

<p>Unfortunately, this approach does not work either. </p>

<p>What's special about the JUnit assert methods / what is SonarQube looking for specifically to check that an assertion has been made for each test?</p>

<p>Alternatively - are there other approaches to achieve the same end result (avoiding duplicating the shared assertion code over and over)?</p>