-
Notifications
You must be signed in to change notification settings - Fork 201
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
[PiranhaJava] Delete statements using EasyMock and JUnit API #156
[PiranhaJava] Delete statements using EasyMock and JUnit API #156
Conversation
Fixed the Swift CI issue Addressed the issues mentioned in the PR and offline Added support for then* pattern Added delete statement logic for specific patterns menntioned in issue uber#104
@@ -369,9 +363,9 @@ private API getXPAPI( | |||
for (PiranhaMethodRecord methodRecord : methodRecordsForName) { | |||
// when argumentIndex is specified, if mit's argument at argIndex doesn't match xpFlagName, | |||
// skip to next method property map | |||
Optional<Integer> optionalArgumentIdx = methodRecord.getArgumentIdx(); | |||
OptionalInt optionalArgumentIdx = methodRecord.getArgumentIdx(); |
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.
My type change tool suggested this :)
import javax.annotation.Nullable; | ||
|
||
/** A class representing a method configuration record from properties.json */ | ||
public class MethodRecord { |
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.
I extracted the super class MethodRecord from PiranhaMethodRecord
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.
Can we also update the README to reflect the new property?
java/piranha/config/properties.json
Outdated
{ | ||
"methodName": "when", | ||
"argumentIndex": 0, | ||
"recieverType":"org.mockito.Mockito", |
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.
typo: receiverType
.getUnnecessaryTestMethodRecords() | ||
.stream() | ||
.map( | ||
mthd -> |
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.
expand mthd
to method
?
@Nullable | ||
static Boolean getValueBooleanFromMap(Map<String, Object> map, String key) { | ||
Object value = map.get(key); | ||
if (value instanceof String && !value.equals("")) { |
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.
!value.isEmpty()
@@ -541,6 +545,27 @@ public void testRemoveSpecificAPIpatterns() throws IOException { | |||
" when(experimentation.isToggleEnabled(\"OTHER_FLAG\")).then(ans);", | |||
" when(foobar()).thenReturn(false);", | |||
" when(foobar()).thenAnswer(ans);", | |||
"// Easymock Test scenarios", |
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.
Can we split these into multiple tests (easymock, ...)?
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.
LGTM
java/README.md
Outdated
Another top-level optional field is `unnecessaryTestMethodProperties`. Within that, there is an array of JSON objects, | ||
having the fields `methodName`, `argumentIndex`, `receiverType`, `returnType` and `isStatic`. | ||
|
||
In practice, often the refactored code produced by `piranha` results in unnecessary method invocations. For instance, |
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.
let us get rid of the term often
:). How about "The refactored code may contain unnecessary method invocations".
"", | ||
"", | ||
"", | ||
" boolean b1 = someWrapper(when(true).thenCallRealMethod());", |
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.
Is this wrapping common?
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.
I don't know, TBH. I just added it as a corner case to the test suite, assuming that if such a scenario appears it should not be refactored because the method someWrapper
could be producing some required side effect.
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.
no worries. this is fine. we can iterate on this subsequently.
Added new matchers for the EasyMock and Junit API