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

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

Open
GoogleCodeExporter opened this issue Sep 23, 2015 · 0 comments
Open

Comments

@GoogleCodeExporter
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant