praveen1503 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Mock object which inherit Spring Configurable (Roo Project) #396

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a project with Spring 3.1.0
2. Create the following classes

import org.springframework.beans.factory.annotation.Configurable;

@Configurable
public class Parent {
}

public class Child extends Parent {

    public static int staticMethod() {
        throw new RuntimeException("Should not be called, Ever !!!");
    }
}

3. Create the following test :

import static junit.framework.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareOnlyThisForTest({ Child.class })
public class UnitTest {

    @Before
    public void setup() {
        PowerMockito.spy(Child.class);

        Child child = new Child();
        // Commenting this line fails the test
        // Child child2 = new Child();
        PowerMockito.doReturn(999).when(Child.class);
        Child.staticMethod();
    }

    @Test
    public void testStaticMethod() {
        assertEquals(999, Child.staticMethod());
    }
}

What is the expected output? What do you see instead?

This test fails and should succeed. Uncommenting the child2 makes the test 
succeed.

What version of the product are you using? On what operating system?
PowerMock 1.4.2
Spring 3.1.0

Please provide any additional information below.

Original issue reported on code.google.com by benoit.pavot on 28 Jun 2012 at 2:12