mardi 13 septembre 2016

StackOverflow Error during jUnit tests with PowerMockito

I am mocking a class with a final method in it, specifically the RevTag class from jGit.

I need to stub the calling of two methods and I do it like this (forgive the goofy names):

import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

...

@RunWith(PowerMockRunner.class)
@PrepareForTest(RevTag.class)
public class TagProcessingTest {

...

PersonIdent ident = mock(PersonIdent.class);
RevTag obj = mock(RevTag.class);

when(obj.getTaggerIdent()).thenReturn(ident);
when(ident.getName()).thenReturn("Thrall");
when(ident.getEmailAddress()).thenReturn("thrall@netscape.org");

However when my unit test gets to the first stubbing method, I get a StackOverFlow error exception. I feel like the error may be in my maven dependencies, because I'm also using vanilla mockito in other different tests (different class all together), but I am not sure.

Here's my relevant pom stuff:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <exclusions>
            <exclusion>
                <artifactId>hamcrest-core</artifactId>
                <groupId>org.hamcrest</groupId>
            </exclusion>
        </exclusions>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.5.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>1.5.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>

Aucun commentaire:

Enregistrer un commentaire