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

Chained mocking not working in BeforeMethod #444

Closed
Milbor opened this Issue Aug 15, 2017 · 0 comments

Comments

2 participants
@Milbor

Milbor commented Aug 15, 2017

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 {
    }
}

@rliesenfeld rliesenfeld self-assigned this Aug 15, 2017

@rliesenfeld rliesenfeld added the bug label Aug 15, 2017

@jmockit jmockit locked and limited conversation to collaborators Sep 17, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.