1

I use the "fest-assert" library in unit tests, which produce "fluent assertions" that are easy to read from left to right.

If a developer hasn't written a test using TDD, they sometimes end up with a line of code like this:

assertThat(something);

This is wrong, because it has to do something more like this:

assertThat(something).is...

Where "is..." is one of many possible predicates, like "isEqualTo()" or "isTrue()" or "hasSize()", et cetera.

I'd like to see if it's possible to write a custom PMD rule that can detect that the return value from "assertThat()" is dropped on the table, as it's not followed by a chained method.

First, does anyone know if this is possible, and could provide an example of what this would look like?

Note that I'm using Sonar 3.7, which is using PMD 4.3. We're planning a Sona upgrade to either 4.1.2 or 4.2 very soon, but I don't know what version of PMD those versions use.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • The latest PMD plugin is using PMD 4.3. But this plugin is not included by default since SonarQube 4.2. For details see the [PMD plugin page](http://docs.codehaus.org/display/SONAR/PMD+Plugin). – L. Langó Apr 14 '14 at 07:35

1 Answers1

0

Please, do not double post. Thread closed. Continuing at http://sonarqube.15.x6.nabble.com/Write-a-custom-XPath-task-that-looks-for-a-method-that-is-NOT-followed-by-a-chained-method-call-td5024017.html

  • 1
    Excuse me? Are you referring to the fact that I posted a similar question on the sonar-users list? Also, your "continuing" link refers back to this same post. – David M. Karr Apr 14 '14 at 15:35
  • I am torn between downvoting this answer because of its very unfriendly tone, and upvoting it because it contains a link to the solution. @DavidM.Karr Maybe you can still accept it? – barfuin Apr 14 '14 at 20:00
  • 2
    I double-post when I have to get answers to questions, and I get inconsistent results from different sources. – David M. Karr Apr 15 '14 at 00:17