-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fixes #583 fix bug when trying to capture null vararg #606
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,4 +315,17 @@ public void captures_correctly_when_captor_used_on_pure_vararg_method() throws E | |
verify(mock).varargs(eq(42), argumentCaptor.capture()); | ||
Assertions.assertThat(argumentCaptor.getValue()).contains("capturedValue"); | ||
} | ||
|
||
@Test | ||
public void should_capture_null_vararg() { | ||
// given | ||
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class); | ||
|
||
// when | ||
mock.varargs(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @lukasz-szewc, thanks for you PR! Please note this test doesn't test the captoring of an null-array ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add that test and let see what happens. Should work :) |
||
|
||
// then | ||
verify(mock).varargs(argumentCaptor.capture()); | ||
Assertions.assertThat(argumentCaptor.getValue()).isNull(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add another test with casting? in the end we will have a test with This allows thorough testing and documentation of each caseof. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at: should_capture_null_array_in_method_vararg. Is it sufficient ? |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of magically changing the length of the array, I would rather introduce an if-else around the for-loop, to make the intent clearer. With this implementation there is a hidden connection between
getLength
andgetArgument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true,
however code with if-else will be longer - but you know - there are no perfect solutions.