-
Notifications
You must be signed in to change notification settings - Fork 583
Description
Hi,
if we have a simple test class like below
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.annotation.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class TwoObjectsAnnotatedTest {
@Mock
private String obj1;
@Mock
private String obj2;
@Test
public void test() {
assertNotNull(obj1);
assertNotNull(obj2);
}
}
then both assertions fail. We noticed that whenever two fields of the same type are annotated with
org.powermock.api.easymock.annotation.Mock
If we remove first one or change to
private String obj1 = createMock(String.class);
then it works as expected. We encountered that when migrating from
jdk7 + easymock 3.3 + powermock 1.6.1
to
jdk8 + easymock 3.4 + powermock 1.6.6
OS is: Linux *** 4.4.0-62-generic 83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Does any workaround exist besides replacing annotation with
org.powermock.api.easymock.PowerMock.createMock()
?
UPDATE: it seems to be similar to #668 but I checked and it works for a third field as long as it has different type (I checked for 3 fields - 2 x String and 1 x Integer - and strings do not work but integer does).