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

[PiranhaJava] Delete statements using EasyMock and JUnit API #156

Merged
merged 8 commits into from
Jan 3, 2022

Conversation

ketkarameya
Copy link
Contributor

Added new matchers for the EasyMock and Junit API

Ameya Ketkar added 2 commits December 1, 2021 18:25
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
@ketkarameya ketkarameya closed this Dec 2, 2021
@ketkarameya ketkarameya reopened this Dec 2, 2021
@@ -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();
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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

Copy link
Contributor

@mkr-plse mkr-plse left a 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?

{
"methodName": "when",
"argumentIndex": 0,
"recieverType":"org.mockito.Mockito",
Copy link
Contributor

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 ->
Copy link
Contributor

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("")) {
Copy link
Contributor

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",
Copy link
Contributor

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, ...)?

Copy link
Contributor

@mkr-plse mkr-plse left a 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,
Copy link
Contributor

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());",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this wrapping common?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@mkr-plse mkr-plse changed the title Delete statements using EasyMock and JUnit API [PiranhaJava] Delete statements using EasyMock and JUnit API Jan 3, 2022
@mkr-plse mkr-plse merged commit 4279cc5 into uber:master Jan 3, 2022
@ketkarameya ketkarameya deleted the feature/specific-use-cases-104 branch January 11, 2022 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants