-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Labels
bugSomething isn't workingSomething isn't workingmockitorecipeRecipe requestRecipe requesttest provided
Description
What version of OpenRewrite are you using?
I am using
- Maven/Gradle plugin 6.15.0
- rewrite-test-framework 3.21.2
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.23.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.testing.jmockit.JMockitToMockito</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>3.21.2</version>
</dependency>
</dependencies>
</plugin>What is the smallest, simplest way to reproduce the problem?
import mockit.Expectations;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Test;
class Config {
private String value;
private String name;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class SameNameTest {
@Mocked
Config config;
@Test
public void testFoo() {
new Expectations() {{
String res = "mockedValue";
config.getValue();
result = res;
String name = "mockedName";
config.getName();
result = name;
}};
String res = config.getValue();
Assert.assertEquals("mockedValue", res);
String name = config.getName();
Assert.assertEquals("mockedName", name);
}
}What did you expect to see?
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
class Config {
private String value;
private String name;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class SameNameTest {
@Mock
Config config;
@Test
public void testFoo() {
{
String res = "mockedValue";
when(config.getValue()).thenReturn(res);
String name = "mockedName";
when(config.getName()).thenReturn(name);
}
String res = config.getValue();
Assert.assertEquals("mockedValue", res);
String name = config.getName();
Assert.assertEquals("mockedName", name);
}
}What did you see instead?
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
class Config {
private String value;
private String name;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class SameNameTest {
@Mock
Config config;
@Test
public void testFoo() {
{
String res = "mockedValue";
String name = "mockedName";
}
when(config.getValue()).thenReturn(res); // it will complain Can't resolve symbol 'res'
when(config.getName()).thenReturn(name); // it will complain Can't resolve symbol 'name'
String res = config.getValue();
Assert.assertEquals("mockedValue", res);
String name = config.getName();
Assert.assertEquals("mockedName", name);
}
}The compiler will complain that Variable 'res' and 'name' can't be resolved
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmockitorecipeRecipe requestRecipe requesttest provided
Type
Projects
Status
Backlog