Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce IsEmpty matcher for use by Refaster templates #744

Merged
merged 5 commits into from
Oct 23, 2023

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Aug 6, 2023

Suggested commit message:

Introduce `IsEmpty` matcher for use by Refaster templates (#744)

As discussed offline with @rickie: this matcher could be used for #733 (assuming that it's extended to support Mono<Void>; that's not part of this PR.)

@Stephan202 Stephan202 requested a review from rickie August 6, 2023 14:54
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 added this to the 0.13.0 milestone Aug 6, 2023
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some context.

Comment on lines -417 to +540
StepVerifier.create(Mono.just("foo")).expectNextMatches(s -> s.equals("bar")),
StepVerifier.create(Mono.just("baz")).expectNextMatches("qux"::equals));
Mono.just("foo").as(StepVerifier::create).expectNextMatches(s -> s.equals("bar")),
Mono.just("baz").as(StepVerifier::create).expectNextMatches("qux"::equals));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These .as(StepVerifier::create) changes were not previously flagged by the tests, because the actual rule under test suggested a smaller replacement. The reason I noticed this now, is that for the StepVerifierStepIdentity test cases I added a negative entry, in order to validate the @Matches usage.

"import reactor.util.context.Context;",
"",
"class A {",
" int[] negative1() {",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping these counters in sync negatively impacts maintenance. Maybe in a separate PR we should consider a more compact test format for these matchers. (But for this PR I followed the established approach.)

Comment on lines +127 to +164
" // BUG: Diagnostic contains:",
" return new ArrayList<>(",
" // BUG: Diagnostic contains:",
" ImmutableList.of());",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: expressions split across multiple lines, to prove that the outer expression is (also) recognized as an empty collection.

@github-actions
Copy link

github-actions bot commented Aug 6, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie modified the milestones: 0.13.0, 0.14.0 Aug 25, 2023
@Stephan202 Stephan202 force-pushed the sschroevers/introduce-is-empty-matcher branch from 8c6a0ac to 3f6e017 Compare August 29, 2023 06:57
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

98.8% 98.8% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie modified the milestones: 0.14.0, 0.15.0 Oct 4, 2023
@Stephan202 Stephan202 force-pushed the sschroevers/introduce-is-empty-matcher branch from 3f6e017 to cdd2e3d Compare October 8, 2023 11:34
@github-actions
Copy link

github-actions bot commented Oct 8, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-is-empty-matcher branch from cdd2e3d to afb5064 Compare October 8, 2023 11:39
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added another commit: now even more empty collections are recognized, and AssertJMapRules and AssertJRules have been simplified accordingly.

ImmutableMultiset.of(),
ImmutableSortedMultiset.of())),
mapAssert.containsExactlyEntriesOf(wellTypedMap),
mapAssert.containsExactlyInAnyOrderEntriesOf(wellTypedMap),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case was previously not covered.

Comment on lines 104 to +106
@BeforeTemplate
AbstractMapAssert<?, ?, K, V> before(AbstractMapAssert<?, ?, K, V> mapAssert, Map<K, V> map) {
AbstractMapAssert<?, ?, K, V> before(
AbstractMapAssert<?, ?, K, V> mapAssert, Map<? extends K, ? extends V> map) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: I generalized the matching a bit, just because I noticed. This likely applies to many other rules; eventually we'll write an Error Prone check for this.

Comment on lines +46 to +47
assertThat(ImmutableMap.of(4, 0))
.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(1, 2, 3, 4));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't just use ImmutableMap.of(1, 2), because then another simplification kicks in.

assertThat(ImmutableMap.of(5, 0)).hasSameSizeAs(ImmutableMap.of());
assertThat(ImmutableMap.of(6, 0)).hasSameSizeAs(ImmutableMap.of(1, 2));
assertThat(ImmutableMap.of(7, 0)).isEqualTo(ImmutableMap.of());
assertThat(ImmutableMap.of(8, 0)).isEqualTo(ImmutableMap.of("foo", "bar"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise :)

@github-actions
Copy link

github-actions bot commented Oct 8, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-is-empty-matcher branch from afb5064 to 2d64df8 Compare October 8, 2023 14:29
@Stephan202
Copy link
Member Author

Rebased and resolved conflicts.

@github-actions
Copy link

github-actions bot commented Oct 8, 2023

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor

@Venorcis Venorcis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to review in detail, but overall LGTM 👍🏻

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pfff this is an insane PR! Really nice work @Stephan202 , the Matcher is amazing ✨ 🤯 !

Got some minor comments, let's merge this soon!

"",
" int[][] positive2() {",
" // BUG: Diagnostic contains:",
" return new int[0][1];",
Copy link
Member

@rickie rickie Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the [1][0] would maybe be interesting as that will fall through the first check of .get(0) == 0 Lol, maybe not worth changing 50+ method names for something that is actually already covered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a closer look at your suggestion, but to the general point of method naming: that was quite painful for this PR indeed. I tried to remain consistent with other tests, but it did make me wonder: perhaps we should drop all those number suffixes in favour of something more descriptive.

(W.r.t. this PR: at some point I renumbered using a Vim macro ;).)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W.r.t. the suggestion itself: return new int[1][0] is used above, in method negative2 :)

void before(
AbstractMapAssert<?, ?, K, V> mapAssert,
@Matches(IsEmpty.class) Map<? extends K, ? extends V> wellTypedMap,
@Matches(IsEmpty.class) Map<?, ?> arbitraryMap,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arbitraryTypedMap maybe? To be inline with the previous one :)? arbitraryMap sounds a bit odd IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this template looks so clean now ✨ !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammatically it'd then be arbitrarilyTypedMap. And that would be fine, I suppose, though this parameter stands in for "really any arbitrary map", and the current name covers that. (Not sure about raw Map types; let's ignore those.)

But in the interest of getting this merged: will rename :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We should then do a similar rename in AssertThatObjectEnumerableIsEmpty.)

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-is-empty-matcher branch from 2d64df8 to 140895c Compare October 23, 2023 05:41
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit. @rickie feel free to merge.

Updated suggested commit message:

Introduce `IsEmpty` matcher for use by Refaster templates (#744)

While there, generalize a number of Refaster rules using this new matcher.

"",
" int[][] positive2() {",
" // BUG: Diagnostic contains:",
" return new int[0][1];",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a closer look at your suggestion, but to the general point of method naming: that was quite painful for this PR indeed. I tried to remain consistent with other tests, but it did make me wonder: perhaps we should drop all those number suffixes in favour of something more descriptive.

(W.r.t. this PR: at some point I renumbered using a Vim macro ;).)

void before(
AbstractMapAssert<?, ?, K, V> mapAssert,
@Matches(IsEmpty.class) Map<? extends K, ? extends V> wellTypedMap,
@Matches(IsEmpty.class) Map<?, ?> arbitraryMap,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammatically it'd then be arbitrarilyTypedMap. And that would be fine, I suppose, though this parameter stands in for "really any arbitrary map", and the current name covers that. (Not sure about raw Map types; let's ignore those.)

But in the interest of getting this merged: will rename :)

"",
" int[][] positive2() {",
" // BUG: Diagnostic contains:",
" return new int[0][1];",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W.r.t. the suggestion itself: return new int[1][0] is used above, in method negative2 :)

void before(
AbstractMapAssert<?, ?, K, V> mapAssert,
@Matches(IsEmpty.class) Map<? extends K, ? extends V> wellTypedMap,
@Matches(IsEmpty.class) Map<?, ?> arbitraryMap,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We should then do a similar rename in AssertThatObjectEnumerableIsEmpty.)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

98.8% 98.8% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 26
class surviving killed
🧟tech.picnic.errorprone.refaster.matchers.IsEmpty 2 26

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit fa026de into master Oct 23, 2023
17 checks passed
@rickie rickie deleted the sschroevers/introduce-is-empty-matcher branch October 23, 2023 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants