Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Excavator: Prefer AssertJ #5184

Merged
merged 8 commits into from
Jan 13, 2021
Merged

Excavator: Prefer AssertJ #5184

merged 8 commits into from
Jan 13, 2021

Conversation

svc-excavator-bot
Copy link
Collaborator

excavator is a bot for automating changes across repositories.

Changes produced by the roomba/assertj check.

To enable or disable this check, please contact the maintainers of Excavator.

@svc-excavator-bot svc-excavator-bot force-pushed the roomba/assertj branch 18 times, most recently from de33328 to 27229ef Compare January 12, 2021 11:16
@@ -79,7 +79,7 @@ public void refreshSingleCallsRefreshWithMatchingArgument() throws InterruptedEx
@Test
public void refreshSingleReturnsTokenIfCanBeRefreshed() throws InterruptedException {
when(mockClient.refresh(any())).then(REPLY_WITH_FIRST_TOKEN);
assertThat(LOCK_TOKEN).isEqualTo(client.refreshSingle(LOCK_TOKEN));
Copy link
Contributor

Choose a reason for hiding this comment

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

wow! this is really cool

fail();
} catch (TransactionSerializableConflictException e) {
// this is expected to throw because it is a write skew
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is correct, though I'd add an as() clause for the explanation

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it uses the message (if present) from fail(String). Losing the comment is unfortunate, we had tried to preserve them in some refactors, but clearly not all cases :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

It does, yep! I think you can read most of these as comments I'm writing to myself to fix.

I don't know if you want things of the form try { <things>; fail(); } catch (Exception e) { // INCLUDEME } since I'm sure there are going to be quite a few that just say expected or things like that

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya that's true, at the end of the day we always want humans to review this sort of change. If you see a pattern that occurs frequently and isn't difficult to detect, use your judgement on filing a ticket to track :-)

} catch (Exception e) {
// success
}
assertThatThrownBy(() -> Namespace.create(string, pattern)).describedAs("Namespace '" + string + "' was not supposed to match pattern '" + pattern + "'").isInstanceOf(Exception.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

clever! though I imagine checkstyle would fail

assert index3.getRange(RangeRequest.builder().build()).count() == 1;
assertThat(index1.getRange(RangeRequest.builder().build()).count() == 1).isTrue();
assertThat(index2.getRange(RangeRequest.builder().build()).count() == 1).isTrue();
assertThat(index3.getRange(RangeRequest.builder().build()).count() == 1).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I guess let's have this thing iterate a bit more

assertEquals(1, end.length);
assertEquals(-1, end[0]);
assertThat(end.length).isEqualTo(1);
assertThat(end[0]).isEqualTo(-1);
Copy link
Contributor

@jeremyk-91 jeremyk-91 Jan 12, 2021

Choose a reason for hiding this comment

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

@carterkozak Probably don't need to fix this, but amazingly this isn't semantically equivalent! (The original works because Assert#assertEquals looks like it does widening conversions to longs, but this fails because the byte -1 and int -1 aren't considered equal in AssertJ, probably because they are different types after boxing).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, we definitely handled some of these, but I must have neglected to implement byte/int conversion. I think I used the rules for java implicit conversion, which doesn't quite match assertj behavior. Mind filing a ticket on https://github.com/palantir/assertj-automation ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, here goes: palantir/assertj-automation#261 and a quick scan of the code suggests that yeah, it goes to the catchall Object rules for these

@carterkozak
Copy link
Contributor

carterkozak commented Jan 12, 2021

I wonder why excavator didn't format the results?

Copy link
Contributor

@gmaretic gmaretic left a comment

Choose a reason for hiding this comment

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

Have a suggestion, but otherwise looks good

@@ -29,15 +29,15 @@ public void testPrefix() {
assertThat(end.length).isEqualTo(0);
end = RangeRequest.builder().prefixRange(new byte[] {-2}).build().getEndExclusive();
assertThat(end.length).isEqualTo(1);
assertThat(end[0]).isEqualTo(-1);
assertThat(end[0]).isEqualTo((byte) -1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty sad, but there is no nice way around it. This test is also super bad anyway so fine with leaving as is

@jeremyk-91
Copy link
Contributor

👍

@jeremyk-91 jeremyk-91 merged commit 742eba2 into develop Jan 13, 2021
@delete-merged-branch delete-merged-branch bot deleted the roomba/assertj branch January 13, 2021 14:24
@svc-autorelease
Copy link
Collaborator

Released 0.285.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants