Skip to content

Chained mocking not working in BeforeMethod #444

@Milbor-zz

Description

@Milbor-zz

1.33 fail
1.32 green

import java.util.List;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableList;

import mockit.Expectations;
import mockit.Mocked;

import static org.testng.Assert.assertNotNull;

public class JmockitTest {
    @Mocked
    private ContextData contextData;

    @BeforeMethod
    public void setUp() throws Exception {
        new Expectations() {{
            contextData.getUser().getAccounts();
            result = ImmutableList.of(new Account());
        }};
    }

    @Test
    public void test() throws Exception {
        assertNotNull(contextData.getUser().getAccounts());
    }

    interface ContextData {
        User getUser();
    }

    static class User {
        private List<Account> accounts;

        public List<Account> getAccounts() {
            return accounts;
        }

        public void setAccounts(final List<Account> accounts) {
            this.accounts = accounts;
        }
    }

    static class Account {
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions