sequential IterableAssert.filteredOn statements flagged incorrectly for "multiple statments can be joined together" #6

Closed
opened 2022-02-23 18:01:02 +01:00 by jbristow · 0 comments
jbristow commented 2022-02-23 18:01:02 +01:00 (Migrated from github.com)
final var dogs = Set.of("poodle", "golden retriever", "dachshund", "boston terrier", "labrador");

assertThat(dogs).extracting(it -> it.charAt(2))
                .contains('o', 'l', 'c', 's', 'b');
assertThat(dogs).filteredOn(it -> it.contains(" "))
                .contains("golden retriever", "boston terrier");
assertThat(dogs).filteredOn(it -> it.contains("o"))
                .contains("poodle", "golden retriever", "boston terrier", "labrador");

The two filteredOn statements are highlighted with "Multiple assertThat() statements can be joined together".

After applying the automatic refactor, the test now fails:

// after applying "Multiple assertThat() statements can be joined together"
assertThat(dogs).extracting(it -> it.charAt(2)).contains('o', 'l', 'c', 's', 'b');
assertThat(dogs).filteredOn(it -> it.contains(" "))
                .contains("golden retriever", "boston terrier")
                .filteredOn(it -> it.contains("o"))
                .contains("poodle", "golden retriever", "boston terrier", "labrador");

// java.lang.AssertionError: 
// Expecting ArrayList:
//   ["boston terrier", "golden retriever"]
// to contain:
//   ["poodle", "golden retriever", "boston terrier", "labrador"]
// but could not find the following element(s):
//   ["poodle", "labrador"]

This seems to be related to the (now fixed! Hooray!) erroneous suggestion to join extracting calls.

Additionally, and potentially related, after applying the above refactor, intellij suggests "Calls to same methods may be joined to variadic version" but...

// after applying "Calls to same methods may be joined to variadic version"
assertThat(dogs).extracting(it -> it.charAt(2)).contains('o', 'l', 'c', 's', 'b');
assertThat(dogs).filteredOn(it -> it.contains(" "))
                .contains("golden retriever", "boston terrier", "poodle", "golden retriever", "boston terrier", "labrador")
                .filteredOn(it -> it.contains("o")); // intellij correctly flags as "ignored"

// java.lang.AssertionError: 
// Expecting ArrayList:
//   ["boston terrier", "golden retriever"]
// to contain:
//   ["golden retriever",
//     "boston terrier",
//     "poodle",
//     "golden retriever",
//     "boston terrier",
//     "labrador"]
// but could not find the following element(s):
//   ["poodle", "labrador"]
```java final var dogs = Set.of("poodle", "golden retriever", "dachshund", "boston terrier", "labrador"); assertThat(dogs).extracting(it -> it.charAt(2)) .contains('o', 'l', 'c', 's', 'b'); assertThat(dogs).filteredOn(it -> it.contains(" ")) .contains("golden retriever", "boston terrier"); assertThat(dogs).filteredOn(it -> it.contains("o")) .contains("poodle", "golden retriever", "boston terrier", "labrador"); ``` The two filteredOn statements are highlighted with "Multiple assertThat() statements can be joined together". After applying the automatic refactor, the test now fails: ```java // after applying "Multiple assertThat() statements can be joined together" assertThat(dogs).extracting(it -> it.charAt(2)).contains('o', 'l', 'c', 's', 'b'); assertThat(dogs).filteredOn(it -> it.contains(" ")) .contains("golden retriever", "boston terrier") .filteredOn(it -> it.contains("o")) .contains("poodle", "golden retriever", "boston terrier", "labrador"); // java.lang.AssertionError: // Expecting ArrayList: // ["boston terrier", "golden retriever"] // to contain: // ["poodle", "golden retriever", "boston terrier", "labrador"] // but could not find the following element(s): // ["poodle", "labrador"] ``` This seems to be related to the (now fixed! Hooray!) erroneous suggestion to join `extracting` calls. Additionally, and potentially related, after applying the above refactor, intellij suggests "Calls to same methods may be joined to variadic version" but... ```java // after applying "Calls to same methods may be joined to variadic version" assertThat(dogs).extracting(it -> it.charAt(2)).contains('o', 'l', 'c', 's', 'b'); assertThat(dogs).filteredOn(it -> it.contains(" ")) .contains("golden retriever", "boston terrier", "poodle", "golden retriever", "boston terrier", "labrador") .filteredOn(it -> it.contains("o")); // intellij correctly flags as "ignored" // java.lang.AssertionError: // Expecting ArrayList: // ["boston terrier", "golden retriever"] // to contain: // ["golden retriever", // "boston terrier", // "poodle", // "golden retriever", // "boston terrier", // "labrador"] // but could not find the following element(s): // ["poodle", "labrador"] ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: chrisly42/cajon-plugin#6
No description provided.